Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6630067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:21:01+00:00 2026-05-25T22:21:01+00:00

I have a class Month that has void member functions and void parameter passing.

  • 0

I have a class “Month” that has void member functions and void parameter passing. I need to overload the constructor (I think) but the compiler doesn’t like my attempts.

class Month
{
public:
    Month(char firstLetter, char secondLetter, char thirdLetter);    //?
    Month::Month(int m) : month(m) {}  //Want above ^ to look like this
    Month();
    void outputMonthNumber();
    void outputMonthLetters();
    //~Month();   // destructor
private:
    int month;
};
void Month::outputMonthNumber()
{
  if (month >= 1 && month <= 12)
    cout << "Month: " << month << endl;
  else
    cout << "Not a real month!" << endl;
}
void Month::outputMonthLetters()
{
    const char * monthNames[] = {
        "Jan","Feb","Mar","Apr","May","Jun",
        "Jul","Aug","Sep","Oct","Nov","Dec"
    };

    const char * output = "The number is not a month!";
    if (month >= 1 && month <= 12)
        output = monthNames[month - 1];

    cout << output;
}

Just like how outputting the month numbers were done, I’m trying to do the same for outputMonthNumber but can’t wrap my head around it.

int main(void)
{
    int num;
    char firstLetter, secondLetter, thirdLetter;
    cout << "give me a number between 1 and 12 and I'll tell you the month name: ";
    cin >> num;
    Month myMonth(num);
    myMonth.outputMonthLetters();
    cout << endl << "Give me a 3 letter month and I'll give you the month #: ";
    cin >> firstLetter >> secondLetter >> thirdLetter;
    /*===How would I pass the parameters to the class?===*/
        //Month herMonth(firstLetter, secondLetter, thirdLetter);
        //herMonth.outputMonthNumber();
}

All member functions of class pass void parameters. I understand how to do it for passing one, but I can’t seem to get it to overload correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:21:02+00:00Added an answer on May 25, 2026 at 10:21 pm

    Do it like so:

    class Month
    {
    public:
        Month(char firstLetter, char secondLetter, char thirdLetter) :
            first(firstLetter),second(secondLetter),third(thirdLetter)
        {
           const char * monthNames[] = {
            "Jan","Feb","Mar","Apr","May","Jun",
            "Jul","Aug","Sep","Oct","Nov","Dec"
           };
           for ( int i = 0 ; i < 12 ; i++ )
              if ( monthNames[i][0] == first && monthNames[i][1] == second && monthNames[i][2] == third )
                  month = i + 1;
        }
        Month::Month(int m) : month(m) {}  //Want above ^ to look like this
        Month();
        void outputMonthNumber();
        void outputMonthLetters();
        //~Month();   // destructor
    private:
        int month;
        char first;
        char second;
        char third;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class with a member function that takes a default argument. struct Class
I have a class Date that I defined that models a date, it has
I have a table that has about 1/2 million records in it. Each month
I have class method that returns a list of employees that I can iterate
I have class Fred { public: void inspect() const {}; void modify(){}; }; int
I have a form that has this code in it, so I can echo
I have a base class which has a method for moving files to appropriate
I have a web app that has to do something every, let's say first
In rails 3, I have a database model that has a birthday field, of
I have a bunch of code that has lots integers with different meanings (I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.