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: 9450
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

Resolved Question:

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.
Submitted: 11 months ago.
Category: Homework
Expert:  LogicPro replied 11 months ago.
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 11 months 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));


}

Expert:  LogicPro replied 11 months ago.
Please wait while I review it
Expert:  LogicPro replied 11 months ago.
Which C++ IDE you are using?
Customer: replied 11 months ago.

Visual Studio Ultimate 2012

Expert:  LogicPro replied 11 months ago.
Please check back in 1 hour
Customer: replied 11 months ago.

Ok. Thank You

Expert:  LogicPro replied 11 months ago.
Welcome John
Expert:  LogicPro replied 11 months ago.
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 11 months ago.

Excellent work.


 


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


and these three month names ( JAN FEB MAY)

Expert:  LogicPro replied 11 months ago.

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 11 months ago.

Yes call constructor 3 times

Expert:  LogicPro replied 11 months ago.
THIS ANSWER IS LOCKED!
You can view this answer by clicking here to Register or Login and paying $3.
If you've already paid for this answer, simply Login.
LogicPro, Engineer
Category: Homework
Satisfied Customers: 9450
Experience: Expert in Java C++ C C# VB Javascript Design SQL HTML
LogicPro and 3 other Homework Specialists are ready to help you

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
< Last | Next >
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
  • He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here. Diane Dallas, TX
 
 
 

Meet The Experts:

 
 
 
  • Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4520
    More than 5000 online tutoring sessions.
< Last | Next >
  • http://ww2.justanswer.com/uploads/BU/BusinessTutor/2012-2-2_115741_Kouki2.64x64.jpg Manal Elkhoshkhany's Avatar

    Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4520
    More than 5000 online tutoring sessions.
  • http://ww2.justanswer.com/uploads/LI/lindaus/2012-6-10_04811_IMG20120609164157.64x64.jpg Linda_us's Avatar

    Linda_us

    Finance, Accounts & Homework Tutor

    Satisfied Customers:

    3121
    Post Graduate Diploma in Management (MBA)
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Engineer

    Satisfied Customers:

    3035
    Expert in Java C++ C C# VB Javascript Design SQL HTML
  • http://ww2.justanswer.com/uploads/lanis/2009-4-1_233717_phput9xef_c1pm.jpg Lani S.'s Avatar

    Lani S.

    Tutor

    Satisfied Customers:

    2457
    Registered Nurse, Internet Researcher, Private Tutor
  • http://ww2.justanswer.com/uploads/chooser77/2009-08-18_162025_Chris.jpg Chris M.'s Avatar

    Chris M.

    M.S.W. Social Work

    Satisfied Customers:

    2341
    Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)
  • http://ww2.justanswer.com/uploads/JawaadAhmed/2009-6-27_12137_SIs_SHadi.jpg F. Naz's Avatar

    F. Naz

    Chartered Accountant

    Satisfied Customers:

    1975
    Experience with chartered accountancy
  • http://ww2.justanswer.com/uploads/JK/jkcpa/2011-1-16_182614_jkcpa.64x64.jpg Bizhelp's Avatar

    Bizhelp

    CPA

    Satisfied Customers:

    1873
    Bachelors Degree and CPA with Accounting work experience