#include <iostream>
using namespace std;
class Month
{
public:
Month (char char1, char char2, char char3);
// Precondition: The parameters contain the first three characters
// in the name of the month - all lowercase.
// Postcondition: The member variable month has been set to
// the integer value corresponding to the letters (1 for jan,
// (2 for feb, and so on). month is set to 0 and a message is
// printed if the letters do not correspond to a valid month.
Month (int monthNum);
// Precondition: The parameter monthNum contains a valid
// month number (1 - 12)
// Postcondition: The member variable month has been set to
// the value of the parameter monthNum.
Month();
// Sets the member variable month to 1 (defaults to January).
void Input (istream& in);
// Postcondition: The member variable month has been output
// to the screen if it is valid; otherwise a "not valid"
// message is printed.
void Output(ostream& outs);
// Postcondition: The first three letters of the name of the
// month has been output to the screen if the month is
// valid (1 - 12); otherwise a message indicating the month
// is not valid is output
Month Next();
private:
int month;
};
void main ()
{
Month m1;
Month m2;
cout<<" enter month"<< endl;
m1.Input(cin);
m2.Output(cout);
}
Month::Month(): month(month)
{
}
void Month::Input(istream& in)
{
char first,second,third;
int number_month;
char c;
c=in.peek();
if( (c > '0') && (c <= '9'))
{
in >> number_month;
Month(nuber_month);
}
else
{
in >>first>>second>>third;
Month(first,second,third);
}
}
Month::Month(char char1, char char2, char char3)
{
if( (char1=='j'|| char1 =='J') && (char2=='a'|| char2=='A')&&(char3=='n'|| char3=='N'))
{ month=1;
cout<< month;
Month(month);}
if(( char1=='f' || char1=='F') && (char2 == 'e' || char2 == 'E') && ( char3 == 'b'|| char3=='B'))
{month=2;}
if(( char1=='m' || char1=='M') && (char2 == 'a' || char2 == 'A') && ( char3 == 'r'|| char3=='R'))
{month=3;
cout<< month;}
if(( char1=='a' || char1=='A') && (char2 == 'p' || char2 == 'P') && ( char3 == 'r'|| char3=='R'))
{month=4;
cout<< month;}
if(( char1=='m' || char1=='M') && (char2 == 'a' || char2 == 'A') && ( char3 == 'y'|| char3=='Y'))
{month=5;
cout<< month;}
if(( char1=='j' || char1=='J') && (char2 == 'u' || char2 == 'U') && ( char3 == 'n'|| char3=='N'))
{month=6;
cout<< month;}
if(( char1=='j' || char1=='J') && (char2 == 'u' || char2 == 'U') && ( char3 == 'l'|| char3=='L'))
{month=7;
}
if(( char1=='a' || char1=='A') && (char2 == 'u' || char2 == 'U') && ( char3 == 'g'|| char3=='G'))
{month=8;
}
if(( char1=='s' || char1=='S') && (char2 == 'e' || char2 == 'E') && ( char3 == 'p'|| char3=='P'))
{month=9;
cout<< month;}
if(( char1=='o' || char1=='O') && (char2 == 'c' || char2 == 'C') && ( char3 == 't'|| char3=='T'))
{month= 10;}
if((char1=='n' || char1=='N') && (char2 == 'o' || char2 == 'O') && ( char3 == 'v'|| char3=='V'))
{month=11;}
if(( char1=='d' || char1=='D') && (char2 == 'e' || char2 == 'E') && ( char3 == 'c'|| char3=='C'))
{month=12;}
cout<<endl<<char1<<char2<<char3;
Month(month);
}
Month::Month(int monthNum)
{
if (monthNum>0 && monthNum<=12)
month=monthNum;
else
{
}
}
/* here is the problem it is taking the default value to do the switch and
not the value that month just
got in the previous function. why is it doing that or is that i am using the wrong concepts???*/
void Month:: Output(ostream& outs)
{
switch (month)
{
case 1:
outs<< "January" <<endl;
break;
case 2:
outs << "February" <<endl;
break;
case 3:
outs << "March" <<endl;
break;
case 4:
outs << "April" <<endl;
break;
case 5:
outs << "May" <<endl;
break;
case 6:
outs << "June" <<endl;
break;
case 7:
outs << "July" <<endl;
break;
case 8:
outs << "August" <<endl;
break;
case 9:
outs << "September" <<endl;
break;
case 10:
outs << "October" <<endl;
break;
case 11:
outs << "November" <<endl;
break;
case 12:
outs << "December" <<endl;
break;
default:
outs << "Sorry incorect Month " <<endl;
}
}
Month Month :: Next()
{
int next;
if (month==12)
next=1;
else
{
next=month++;
}
cout<< next;
return( Month(next));
}
Bigboy06 0 Newbie Poster
VernonDozier 2,218 Posting Expert Featured Poster
vmanes 1,165 Posting Virtuoso
ArkM 1,090 Postaholic
vmanes 1,165 Posting Virtuoso
Bigboy06 0 Newbie Poster
Salem 5,199 Posting Sage
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.