[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

Convert Month Name to Month Number

Asked by Impulse0022 in C++ Programming Language

Tags: month, convert, number, name

How would I go about converting a Month Name to a Month Number.  For example, convert Jan to 1 and Feb to 2, etc.  The Month Name is input from the keyboard and a variable called month is of type int in a void function.  So I would need to convert the Month Name to a Month Number within the function so it can make month = 1 if the input from the keyboard is Jan.  Thanks for any help that you can give me.

//**************
void MonthType::InputMonthName( istream& ins )
//**************
{
    // Reads month as char from the keyboard

    cout << "Enter the first three letters of the month name: ";
    ins >> month;

    switch ( month )
    {
        case 'J':
            month = 1;
            break;
        case 'F':
            month = 2;
            break;
        case 'M':
            month = 3;
            break;
        case 'A':
            month = 4;
            break;
        case 'S':
            month = 9;
            break;
        case 'O':
            month = 10;
            break;
        case 'N':
            month = 11;
            break;
        case 'D':
            month = 12;
            break;
        case 'y':
            month = 5;
            break;
        case 'n':
            month = 6;
            break;
        case 'l':
            month = 7;
            break;
        case 'g':
            month = 8;
            break;
    }

} // End function InputMonthName( istream& ins )


This is a class function variable and here in the other part that this function uses.


//**************
MonthType::MonthType( char firstLetter, char secondLetter, char thirdLetter )
//**************
{
    // Parameterized constructor function for three characters of month
   
    month = firstLetter, secondLetter, thirdLetter;

    switch ( firstLetter )
    {
        case 'J':
            month = 1;
            break;
        case 'F':
            month = 2;
            break;
        case 'M':
            month = 3;
            break;
        case 'A':
            month = 4;
            break;
        case 'S':
            month = 9;
            break;
        case 'O':
            month = 10;
            break;
        case 'N':
            month = 11;
            break;
        case 'D':
            month = 12;
            break;
    }
    switch ( thirdLetter )
    {
        case 'y':
            month = 5;
            break;
        case 'n':
            month = 6;
            break;
        case 'l':
            month = 7;
            break;
        case 'g':
            month = 8;
            break;
    }
} // End function MonthType( char, char, char )

This is the output that I get.

Result of passing May to monthName's char constructor:

The month number is: 5
The month name is: May

Result of loading monthName's month field via characters from the keyboard:

Enter the first three letters of the month name: Jan
The month number is: 5
The month name is: May
[+][-]01/26/03 10:20 PM, ID: 7819073Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: C++ Programming Language
Tags: month, convert, number, name
Sign Up Now!
Solution Provided By: KnightM
Participating Experts: 4
Solution Grade: B
 
[+][-]01/27/03 02:21 AM, ID: 7820074Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/27/03 02:46 AM, ID: 7820179Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/27/03 06:41 AM, ID: 7821481Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/27/03 07:21 AM, ID: 7821781Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93