Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help with the following question. Design and implement a class dayType th

ID: 3568438 • Letter: P

Question

Please help with the following question.

Design and implement a class dayType that implements the day of the week in a program. The class dayType should store the day, such as Sun for Sunday. The program should be able to preform the following operations on an object of type dayType:
a. set the day
b. print the day
c. return the day
d. return the next day
e. return the previous day
f. calculate and return the day by adding certain days to the current day. for example, if the current day is Monday and we add 4 days, the day to be returned is friday. similarly, if today is tuesday and we add 13 days, the day to be returned is monday.
g. add the appropriate constructors.

H. Write the definitions of the methods to implement the operations for the class Day, as

defined in a through g.
I. Write a program to test various operations on the class Day.

Explanation / Answer

Program to design and implement a class dayType that implements the day of the week in a program:

#include <iostream>
#include "dayType.h"

using namespace std;

void dayType::printDay()
{
switch(weekDay)
{
case Sun:
cout<<"Sunday";
break;
case Mon:
cout<<"Monday";
break;
case Tue:
cout<<"Tuesday";
break;
case Wed:
cout<<"Wednesday";
break;
case Thu:
cout<<"Thursday";
break;
case Fri:
cout<<"Friday";
break;
case Sat:
cout<<"Saturday";
}
}

weekDayType dayType::nextDay()
{
return weekDayType((weekDay + 1) % 7);
}

weekDayType dayType::prevDay()
{
if (weekDay == Sun)
return Sat;
else
return weekDayType(weekDay - 1);
}


void dayType::addDay(int nDays)
{
weekDay = weekDayType((weekDay + nDays) % 7);
}

void dayType::setDay(weekDayType d)
{
weekDay = d;
}

weekDayType dayType::getDay()
{
return weekDay;
}

dayType::dayType()
{
weekDay = Sun;
}

dayType::dayType(weekDayType d)
{
weekDay = d;
}

Main program :

#include <iostream>
#include "dayType.h"

using namespace std;

int main()
{
dayType myDay(Thu);
dayType tempDay;

cout<<"Today: ";
myDay.printDay();
cout<<endl;

tempDay.setDay(myDay.nextDay());

cout<<"Next Day: ";

tempDay.printDay();
cout<<endl;

tempDay.setDay(myDay.prevDay());

cout<<"Previous Day: ";

tempDay.printDay();
cout<<endl;

myDay.addDay(7);

cout<<"After 7 Days: ";
myDay.printDay();
cout<<endl;
cout<<endl;

return 0;