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

Please read the FULL instructions. Do not copy answers from other people and pas

ID: 3725668 • Letter: P

Question

Please read the FULL instructions. Do not copy answers from other people and paste it here, it's most likely false. Thank you. Correct answer will be given multiple thumbs up.

This is what it should ask and print. 12 was entered, so it printed This month is Dec and so on.

The second part asked for first letter, second letter, and third letter. Then it gave the number, and the NAME of the next month.

Here's the input.

Here's the output.

Define a class called Month that is an abstract data type for a month. Your class should have a private intager variable that represents the month (1 for January, 2 for February, etc.). Include all the following member functions - A default constructor that set's the month to January - A constructor to set the month using the first three letters in the name of the month as three arguments - A constructor to set the month using an integer as an argument. - A mutator function that sets the month by passing in an integer - An accessor function that returns the value of the month as an integer - An accessor function that returns the first three letters in the name of the month - A Member function that returns the next month as a value of type Month Make sure your class validates user input to verify that a valid month was entered In main(), test your program by creating 3 different Month objects. The first month object should use an integer value entered by the user as the argment to the constructor. Then, use the Month class member functions to print out the first three letters of the corresponding month and the first three letters of the next month The second month object should take 3 letters that the user enters as arguments to the constructor Then, use the Month class member functions to print out the value of that month as an integer, as well as the first three letters of the next month onstructor. Print out the first three letters The third month object should be created using the def of that month and the next month

Explanation / Answer

Hi, I have a solution for you. I have answered the same question asked by another user, so I’m presenting my own answer which works 100% like you wanted.

//code.cpp

#include<iostream>

#include<ctype.h>

using namespace std;

class Month{

                int month;

               

                public:

                /*default constructor, will set month to january*/

                Month(){

                                month=1;

                }

                /*constructor with integer argument, will set month to month number specified*/

                Month(int i){

                                setMonth(i);

                }

                /*constructor to set month using first 3 letters*/

                Month(char a, char b, char c){

                                month=1;/*setting default value first, so that if the a,b,c doesn't form a valid month,

                                this value will be used*/

                                a=toupper(a); /*converting each characters to upper case*/

                                b=toupper(b);

                                c=toupper(c);

                                /*finding the month using first 3 chars*/

                                switch(a){

                                                case 'J':

                                                                if(b=='A' && c=='N'){

                                                                                month=1; //January

                                                                }else if(b=='U' && c=='N'){

                                                                                month=6; //June

                                                                }else if(b=='U' && c=='L'){

                                                                                month=7; //July

                                                                }

                                                                break;

                                                case 'F':

                                                                if(b=='E' && c=='B'){

                                                                                month=2; //February

                                                                }

                                                                break;

                                                case 'M':

                                                                if(b=='A' && c=='R'){

                                                                                month=3; //March

                                                                }else if(b=='A' && c=='Y'){

                                                                                month=5; //May

                                                                }

                                                                break;

                                                case 'A':

                                                                if(b=='P' && c=='R'){

                                                                                month=4; //April

                                                                }else if(b=='U' && c=='G'){

                                                                                month=8; //August

                                                                }

                                                                break;

                                                case 'S':

                                                                if(b=='E' && c=='P'){

                                                                                month=9; //September

                                                                }

                                                                break;

                                                case 'O':

                                                                if(b=='C' && c=='T'){

                                                                                month=10; //october

                                                                }

                                                                break;

                                                case 'N':

                                                                if(b=='O' && c=='V'){

                                                                                month=11; //November

                                                                }

                                                                break;

                                                case 'D':

                                                                if(b=='E' && c=='C'){

                                                                                month=12; //December

                                                                }

                                                                break;

                                                               

                                }

                               

                }

                /*method to set a month using month number*/

                void setMonth(int i){

                                /**checking if number is in valid range */

                                if(i>=1 && i<=12){

                                                month=i;

                                }else{

                                                /*setting default value */

                                                month=1;

                                }

                }

                //returns the month as integer

                int getMonth(){

                                return month;

                }

                //returns the month's first 3 letters

                char* getMonthAsLetters(){

                                char* MON;

                                /*finding the first 3 letters of the month*/

                                switch(month){

                                                case 1:

                                                                MON="JAN";

                                                                break;

                                                case 2:

                                                                MON="FEB";

                                                                break;

                                                case 3:

                                                                MON="MAR";

                                                                break;

                                                case 4:

                                                                MON="APR";

                                                                break;

                                                case 5:

                                                                MON="MAY";

                                                                break;

                                                case 6:

                                                                MON="JUN";

                                                                break;

                                                case 7:

                                                                MON="JUL";

                                                                break;

                                                case 8:

                                                                MON="AUG";

                                                                break;

                                                case 9:

                                                                MON="SEP";

                                                                break;

                                                case 10:

                                                                MON="OCT";

                                                                break;

                                                case 11:

                                                                MON="NOV";

                                                                break;

                                                case 12:

                                                                MON="DEC";

                                                                break;

                                }

                                return MON;

                }

                //returns a Month object holding next month

                Month nextMonth(){

                                /* defining a Month object for next month.

                                will work even if current month is december, as it will be handled by the constructor */

                                Month m(month+1);

                                /*returning it*/

                                return m;

                }

};

int main(){

                int n;

                cout<<"Enter a month value as an integer : ";

                cin>>n;

                /*creating a month from integer n*/

                Month month1(n);

                /*displaying month and next month*/

                cout<<"This month is "<<month1.getMonthAsLetters()<<endl;

                cout<<"The next month is "<<month1.nextMonth().getMonthAsLetters()<<endl;

                char a,b,c;

                cout<<"Enter first letter of the month name : ";

                cin>>a;

                cout<<"Enter second letter of the month name : ";

                cin>>b;

                cout<<"Enter third letter of the month name : ";

                cin>>c;

                /*creating a month from first 3 characters*/

                Month month2(a,b,c);

                /*displaying this month‘s int value and next month’s first three characters*/

                cout<<"This is month number : "<<month2.getMonth()<<endl;

                cout<<"The next month is "<<month2.nextMonth().getMonthAsLetters()<<endl;         

                /*creating a month using default constructor*/

                Month month3;               

                /*displaying month and next month*/

                cout<<"Using the default constructor, the month is "<<month3.getMonthAsLetters()<<endl;

                cout<<"The next month is "<<month3.nextMonth().getMonthAsLetters()<<endl;

                return 0;

}

/*OUTPUT*/

Enter a month value as an integer : 12

This month is DEC

The next month is JAN

Enter first letter of the month name : S

Enter second letter of the month name : E

Enter third letter of the month name : P

This is month number : 9

The next month is OCT

Using the default constructor, the month is JAN

The next month is FEB

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