How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask LogicPro Your Own Question

LogicPro
LogicPro, Engineer
Category: Homework
Satisfied Customers: 12553
Experience:  Expert in Java C++ C C# VB Javascript Design SQL HTML
29751445
Type Your Homework Question Here...
LogicPro is online now
A new question is answered every 9 seconds

Define a class called Month that is an abstract data type for

This answer was rated:

Define a class called Month that is an abstract data type for a month. Your
class will have one member variable of type int to represent a month (1 for January, 2 for February, and so forth). Include all the following
member functions: 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 (1 for January, 2 for February, and
so forth), a default constructor, an input function that reads the month as
an integer, an input function that reads the month as the first three letters
in the name of the month, an output function that outputs the month as
an integer, an output function that outputs the month as the first three
letters in the name of the month, and a member function that returns the
next month as a value of type Month. The input and output functions will
each have one formal parameter for the stream. Embed your class definition
in a test program.
Hi,
Welcome to JustAnswer.
My name is XXXXX XXXXX I will help you.
Do you have code to start with?
What is the deadline?
Customer: replied 3 years ago.

Deadline is tomorrow evening.


 


#include <iostream>
using namespace std;

class Month
{
public:
Month (char firstLetter, char secondLetter, char thirdLetter);
Month (int month);
Month ();
void Input (istream& ins);
void Output(ostream& outs);
Month next();

private:
int Month_Number;
};

int main ()
{
//Month m1(6);
Month m2('F','e','b');
Month m3;

//m1.Output (cout);
//m2.Output(cout);
cout << "\nSolution to CSC-160 Homework Four Project 6\n ";
cout << "\nTesting the Month class\n";
cout << "\nCreating three Month objects using three seperate constructors.\n";
cout << "\nInitial Month values as month numbers:\n";
cout << "\nInitial Month values as month names:\n";
cout << "\nTesting next month functionon second initial value:\n";
cout << "Enter a Month value as a month number (1-12): ";
m3.Input(cin);
m2.Output(cout);

return 0;
}

Month::Month() : Month_Number(0){}

void Month::Input(istream& ins)
{
char c, firstLetter, secondLetter, thirdLetter ;
int i;

c = ins.peek();



if ( (c >= '1') && (c <= '9') )
ins >> i;
else
ins >> firstLetter >> secondLetter >> thirdLetter;
}


Month::Month(char firstLetter, char secondLetter, char thirdLetter)
{
firstLetter = tolower(firstLetter);
secondLetter = tolower(secondLetter);
thirdLetter = tolower(thirdLetter);

if ((firstLetter == 'j')&&(secondLetter == 'a')&&(thirdLetter == 'n'))
Month_Number = 1;
else if ((firstLetter == 'f')&&(secondLetter == 'e')&&(thirdLetter == 'b'))
Month_Number = 2;
else if ((firstLetter == 'm')&&(secondLetter == 'a')&&(thirdLetter == 'r'))
Month_Number = 3;
else if ((firstLetter = 'a')&&(secondLetter == 'p')&&(thirdLetter == 'r'))
Month_Number = 4;
else if ((firstLetter == 'm')&&(secondLetter == 'a')&&(thirdLetter == 'y'))
Month_Number = 5;
else if ((firstLetter == 'j')&&(secondLetter == 'u')&&(thirdLetter == 'n'))
Month_Number = 6;
else if ((firstLetter == 'j')&&(secondLetter == 'u')&&(thirdLetter == 'l'))
Month_Number = 7;
else if ((firstLetter == 'a')&&(secondLetter == 'u')&&(thirdLetter == 'g'))
Month_Number = 8;
else if ((firstLetter == 's')&&(secondLetter == 'e')&&(thirdLetter == 'p'))
Month_Number = 9;
else if ((firstLetter == 'o')&&(secondLetter == 'c')&&(thirdLetter == 't'))
Month_Number = 10;
else if ((firstLetter == 'n')&&(secondLetter == 'o')&&(thirdLetter == 'v'))
Month_Number = 11;
else if ((firstLetter == 'd')&&(secondLetter == 'e')&&(thirdLetter == 'c'))
Month_Number = 12;
else
cout << "Error : invalid month number: " << endl;
exit(1);
}

Month::Month (int month)
{
if ((month < 1) || (month > 12))
{
cout << "Error : invalid month number: " << endl;
exit(1);
}
else
Month_Number = month;

}
void Month::Output(ostream& outs)
{

switch (Month_Number)
{
case 1:
outs << "January";
break;
case 2:
outs << "February";
break;
case 3:
outs << "March";
break;
case 4:
outs << "April";
break;
case 5:
outs << "May";
break;
case 6:
outs << "June";
break;
case 7:
outs << "July";
break;
case 8:
outs << "August";
break;
case 9:
outs << "September";
break;
case 10:
outs << "October";
break;
case 11:
outs << "November";
break;
case 12:
outs << "December";
break;
default:
outs << "Error : invalid month number: " << endl;
}

cout << "\n";
}

Month Month::next()
{
int Num;

if (Month_Number == 12)
Num = 1;
else
Num = Month_Number + 1;

return(Month (Num));


}
public:
Month (char firstLetter, char secondLetter, char thirdLetter);
//Set the name of the month to the first 3 chars of its name

Month (int month);
//Set the months to their respective numbers

Month ();
//Initialize the Month name to "", and the month # XXXXX 0

void Input (istream& ins);
//reads either the month name or the month number

void Output(ostream& outs);
//Prints the full name of the month

Month next();
//returns the next month as a value of type Month.


private:
int Month_Number;
};

int main ()
{
//Month m1(6);
//Month m2('F','e','b');
Month m3;

//m1.Output (cout);
//m2.Output(cout);
cout << "Please enter month number or name: ";
m3.Input(cin);
m3.Output(cout);

return 0;
}

Month::Month() : Month_Number(0){}

void Month::Input(istream& ins)
{
char c, firstLetter, secondLetter, thirdLetter ;
int i;

c = ins.peek();

//Deternime whether c is an integer of a character

if ( (c >= '1') && (c <= '9') )
ins >> i;
else
ins >> firstLetter >> secondLetter >> thirdLetter;
}


Month::Month(char firstLetter, char secondLetter, char thirdLetter)
{
//Make all char lowercase
firstLetter = tolower(firstLetter);
secondLetter = tolower(secondLetter);
thirdLetter = tolower(thirdLetter);

if ((firstLetter == 'j')&&(secondLetter == 'a')&&(thirdLetter == 'n'))
Month_Number = 1;
else if ((firstLetter == 'f')&&(secondLetter == 'e')&&(thirdLetter == 'b'))
Month_Number = 2;
else if ((firstLetter == 'm')&&(secondLetter == 'a')&&(thirdLetter == 'r'))
Month_Number = 3;
else if ((firstLetter = 'a')&&(secondLetter == 'p')&&(thirdLetter == 'r'))
Month_Number = 4;
else if ((firstLetter == 'm')&&(secondLetter == 'a')&&(thirdLetter == 'y'))
Month_Number = 5;
else if ((firstLetter == 'j')&&(secondLetter == 'u')&&(thirdLetter == 'n'))
Month_Number = 6;
else if ((firstLetter == 'j')&&(secondLetter == 'u')&&(thirdLetter == 'l'))
Month_Number = 7;
else if ((firstLetter == 'a')&&(secondLetter == 'u')&&(thirdLetter == 'g'))
Month_Number = 8;
else if ((firstLetter == 's')&&(secondLetter == 'e')&&(thirdLetter == 'p'))
Month_Number = 9;
else if ((firstLetter == 'o')&&(secondLetter == 'c')&&(thirdLetter == 't'))
Month_Number = 10;
else if ((firstLetter == 'n')&&(secondLetter == 'o')&&(thirdLetter == 'v'))
Month_Number = 11;
else if ((firstLetter == 'd')&&(secondLetter == 'e')&&(thirdLetter == 'c'))
Month_Number = 12;
else
cout << "Error - This month is not a valid!" << endl;
exit(1);
}

Month::Month (int month)
{
if ((month < 1) || (month > 12))
{
cout << "Error - This month is not a valid!" << endl;
exit(1);
}
else
Month_Number = month;

}
void Month::Output(ostream& outs)
{

switch (Month_Number)
{
case 1:
outs << "January";
break;
case 2:
outs << "February";
break;
case 3:
outs << "March";
break;
case 4:
outs << "April";
break;
case 5:
outs << "May";
break;
case 6:
outs << "June";
break;
case 7:
outs << "July";
break;
case 8:
outs << "August";
break;
case 9:
outs << "September";
break;
case 10:
outs << "Octuber";
break;
case 11:
outs << "November";
break;
case 12:
outs << "December";
break;
default:
outs << "Error - This month is not a valid!" << endl;
}

cout << "\n";
}

Month Month::next()
{
int Num;

if (Month_Number == 12)
Num = 1;
else
Num = Month_Number + 1;

return(Month (Num));


}

Please wait while I review it
Which C++ IDE you are using?
Customer: replied 3 years ago.

Visual Studio Ultimate 2012

Please check back in 1 hour
Customer: replied 3 years ago.

Ok. Thank You

Welcome John
Download answer from here: MonthClass_CPP.cpp

You can ask me again using "For LogicPro only" at the start of your questions like other customers to get instant answers.
It will ensure that question is for me.
Please bookmark my profile page:
http://www.justanswer.com/homework/expert-logicpro/
so you can come back and ask me a question anytime.

Remember, if for any reason you are unsatisfied with my answer, we can continue the conversation until you’re satisfied and rate my answer as excellent. I can address follow up questions on original requirements at no extra charge and I’m always here to help.
Thank you for using JustAnswer!
Customer: replied 3 years ago.

Excellent work.


 


It should show these three months numbers ( 1 2 5)


and these three month names ( JAN FEB MAY)

It should show these three months numbers ( 1 2 5)

-> Do you mean, we should call defaul constructor 3 times for these numbers?

 

Also change the statement:

else if ((firstLetter = 'a')&&(secondLetter == 'p')&&(thirdLetter == 'r'))

to

else if ((firstLetter == 'a')&&(secondLetter == 'p')&&(thirdLetter == 'r'))

 

There was one '=' missing for firstLetter

 

 

Output will depand on input.

Hope it clears

Customer: replied 3 years ago.

Yes call constructor 3 times

THIS ANSWER IS LOCKED!

You need to spend $3 to view this post. Add Funds to your account and buy credits.
LogicPro and 3 other Homework Specialists are ready to help you

Related Homework Questions