Question: Modify the DayOfYear class, written in an earlier Programming Challenge, to add a constructor that takes two parameters: a string representing a month and an
Modify the DayOfYear class, written in an earlier Programming Challenge, to add a constructor that takes two parameters: a string 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 specied 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. Add the following overloaded operators: ++ prex and postx increment operators. These operators should modify the DayOfYear object so that it represents the next day. If the day is already the end of the year, the new value of the object will represent the rst day of the year. -- prex and postx decrement operators. These operators should modify the DayOfYear object so that it represents the previous day. If the day is already the rst day of the year, the new value of the object will represent the last day of the year.
Output should look like this:

Language: C++
Professor asked us to modify the below program to do the above assignment
make sure to overload
++ prex and postx increment operators.
-- prex and postx decrement operators
#include
#include
#include
using namespace std;
class DayOfYear
{
//Declare required private member variables.
private:
int day_of_year;
string monthArr[12];
int endDayOfMonths[13];
//Declare required static member variables to store
//the results.
static string dayInMonthDayFormat;
static int reqDayOFYear;
//Declare the required public member functions.
public:
DayOfYear(int inputDayOfYear);
void print();
void setEndDaysOfMonths();
void setMonthArrValues();
};
string DayOfYear::dayInMonthDayFormat = "";
int DayOfYear::reqDayOFYear = 0;
//Define the constructor of the class to initialize the
//member variable of the class.
DayOfYear::DayOfYear(int inputDayOfYear)
{
day_of_year = inputDayOfYear;
}
//Define the method setEndDaysOfMonths() to set the
//end day value for each month.
void DayOfYear::setEndDaysOfMonths()
{
endDayOfMonths[0] = 0;
endDayOfMonths[1] = 31;
endDayOfMonths[2] = 59;
endDayOfMonths[3] = 90;
endDayOfMonths[4] = 120;
endDayOfMonths[5] = 151;
endDayOfMonths[6] = 181;
endDayOfMonths[7] = 212;
endDayOfMonths[8] = 243;
endDayOfMonths[9] = 273;
endDayOfMonths[10] = 304;
endDayOfMonths[11] = 334;
endDayOfMonths[12] = 365;
}
//Define the method setMonthArrValues() to set the
//month names.
void DayOfYear::setMonthArrValues()
{
monthArr[0] = "January";
monthArr[1] = "February";
monthArr[2] = "March";
monthArr[3] = "April";
monthArr[4] = "May";
monthArr[5] = "June";
monthArr[6] = "July";
monthArr[7] = "August";
monthArr[8] = "September";
monthArr[9] = "October";
monthArr[10] = "November";
monthArr[11] = "December";
}
//Define the method print() to display the day of the
//year entered by the user into the month followed by
//day form.
void DayOfYear::print()
{
//Declare and initialize a variable to store the
//month values.
int monthVal = 0;
//Start a while loop till the end day of the current
//month is less than the day of the year entered by
//the user.
while(endDayOfMonths[monthVal]
{
//Increment the month value in each iteration by 1.
monthVal++;
}
//Get the corresponding day and month name from the
//arrays provided in the class using the
//appropriate index value which is monthVal.
//cout
dayInMonthDayFormat += monthArr[monthVal - 1];
reqDayOFYear += day_of_year -
endDayOfMonths[monthVal - 1];
//Display the message to show the corresponding
//month followed by the day for the given day of
//the year.
cout
cout
cout
}
int main()
{
//Declare required variables to store the value
//entered by the user.
int day_of_year;
//Prompt the user to enter a day of the year.
cout
cin >> day_of_year;
//Check if the day entered by the user is outside the
//given range (1 to 365), then display an error
//message and prompt the user again to enter the
//valid day of the year.
while(day_of_year 365)
{
cout
cout
cin >> day_of_year;
}
//Create an object of the class DayOfYear and pass
//the value entered by the user to its constructor.
DayOfYear dy(day_of_year);
//Call the function setEndDaysOfMonths() to set the
//end days of each month.
dy.setEndDaysOfMonths();
//Call the function setMonthArrValues() to set the
//month names for each month.
dy.setMonthArrValues();
//Call the function print() to display the day
//entered by the user in the month-day format.
dy.print();
return 0;
}
please make output exactly like the picture
D A Microsoft Visual Studio Debug Console This program converts a Month and day of month into A day of the year in the range 1..365 Enter month and day (Example: January 3): January 3 3 The day before is January 2 The day after is January 4 C:\Users\ghaforp source epos\Project1\Debug\Project1.exe (process 4184) exited with code o. Press any key to close this window D A Microsoft Visual Studio Debug Console This program converts a Month and day of month into A day of the year in the range 1..365 Enter month and day (Example: January 3): January 3 3 The day before is January 2 The day after is January 4 C:\Users\ghaforp source epos\Project1\Debug\Project1.exe (process 4184) exited with code o. Press any key to close this window
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
