Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a class called Month that represents a month of the year. Your class will

ID: 3621532 • Letter: D

Question

Define a class called Month that represents a month of the year. Your class will have one data member of type int to represent a month(1 for January, 2 for February, 3 for March, etc.) Include the following member functions in the class:

An input function to input the month number.
An output function to output the month as an integer.
Another output function to output the month as the first three characters of the month's name.(e.g. Jan)
A constructor that takes an integer to initialize the month number(We will talk about constructors next week.)
A default constructor
An accessor function to allow access to the month number.(We will talk about accessors next week.)


Write a main function to test the all the functions in the class.

For now you could write the class with the first three functions. Add the others as we talk about accessors and constructors next week.

Explanation / Answer

please rate - thanks

#include <iostream>
using namespace std;
class MONTH
{
private: int month;

public:
MONTH(int m)
{
month=m;
}
MONTH()
{
month=1;
}
void MONTH::output()
{cout<<"month="<<month<<endl;
}
void MONTH::print()
{string mth[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug",
"Sep","Oct","Nov","Dec"};
cout<<"month= "<<mth[month-1]<<endl;
}
void MONTH::input()
{
cout<<"enter the month as a number 1-12: ";
cin>>month;
}

int MONTH::getmonth()
{
return month;
}
};
int main()
{MONTH a;
MONTH b(3);
MONTH c;
a.print();
b.output();
c.input();
cout<<"The month is "<<c.getmonth()<<endl;

system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote