Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the DayOfYear class, written in Programming Challenge 2, to add a constructor that takes two parameters: a stringobject representing a month and an integer

Modify the DayOfYear class, written in Programming Challenge 2, to add a constructor that takes two parameters: a stringobject representing a month and an integer in the range 0 through 31 representing the day of the month. The constructor should then initialize the integer member of the class to represent the day specified by the month and day of month parameters. The constructor should terminate the program with an appropriate error message if the number entered for a day is outside the range of days for the month given.(Full month names like March, Aprill, May.....)

Add the following overloaded operators:

++ prefix and postfix increment operators. These operators should modify the DayOfYear object so it represents the next day. If the day is already the end of the year, the new value of the object will represent the first day of the year.

-- prefix and postfix decrement operators. These operators should modify the DayOfYear object so it represents the previous day. If the day is already the first day of the year, the new value of the object will represent the last day of the year.

Code:

#include

#include

#include

#include

using namespace std;

class DayOfYear

{

public:

int day;

string month;

DayOfYear(int dayentered)

{

day = dayentered;

}

void print()

{

if (day >= 1 && day <= 31)

{

cout << " Day " << day << " would be " << "January, " << day << endl;

}

if (day >= 32 && day <= 59)

{

cout << " Day " << day << " would be " << "February, " << day - 31 << endl;

}

if (day >= 60 && day <= 90)

{

cout << " Day " << day << " would be " << "March, " << day - 59 << endl;

}

if (day >= 91 && day <= 120)

{

cout << " Day " << day << " would be " << "April, " << day - 90 << endl;

}

if (day >= 121 && day <= 151)

{

cout << " Day " << day << " would be " << "May, " << day - 120 << endl;

}

if (day >= 152 && day <= 181)

{

cout << " Day " << day << " would be " << "June, " << day - 151 << endl;

}

if (day >= 182 && day <= 212)

{

cout << " Day " << day << " would be " << "July, " << day - 181 << endl;

}

if (day >= 213 && day <= 243)

{

cout << " Day " << day << " would be " << "August, " << day - 212 << endl;

}

if (day >= 244 && day <= 273)

{

cout << " Day " << day << " would be " << "September, " << day - 243 << endl;

}

if (day >= 274 && day <= 304)

{

cout << " Day " << day << " would be " << "October, " << day - 273 << endl;

}

if (day >= 305 && day <= 334)

{

cout << " Day " << day << " would be " << "November, " << day - 304 << endl;

}

if (day >= 335 && day <= 365)

{

cout << " Day " << day << " would be " << "December, " << day - 334 << endl;

}

}

};

int main()

{

int dayentered;

cout << "Enter a number from 1 to 365" << endl;

cin >> dayentered;

DayOfYear instance = DayOfYear(dayentered);

instance.print();

cin.ignore();

cin.get();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

2. What types of nonverbal behavior have scholars identifi ed?

Answered: 1 week ago