1. 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 perform 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.
Add the appropriate constructors.
2. Also, write a program to test various operations on this class .

See Answers (1)

Accepted Answer

Using the knowledge in computational language in C++ it is possible to write the code that design and implement a class dayType that implements the day of the week in a program. Writting the code:#include "stdafx.h" #include<iostream>#include<cmath>sing namespace std;class dayType{public: int presday;int prevday;int nextday;dayType()presday = 0;nextday = 0;prevday = 0;}void set(int day); //function declarationsvoid print(int day);int Next_day(int day);int day();int prev_day(int pres);};void dayType::set(int day) //member functions{presday = day;}/* modify here*/int dayType::prev_day(int day){prevday = presday - day;// =abs(presday-day);if (prevday<0)prevday += 7;return prevday;}int dayType::day(){return presday;}int dayType::Next_day(int day){nextday = presday + day;if (nextday>7){nextday = nextday % 7;}return nextday;}void dayType::print(int d){if (d == 1)cout << "Monday" << endl;if (d == 2)cout << "Tuesday" << endl;if (d == 3)cout << "Wednesday" << endl;if (d == 4)cout << "Thursday" << endl;if (d == 5)cout << "Friday" << endl;if (d == 6)cout << "Saturday" << endl;if (d == 7)cout << "Sunday" << endl;}/* here modify change void to int type */int main(){int d, p, n;dayType obj;cout << "1-Mon" << endl << "2-Tue" << endl << "3-Wed" << endl << "4-Thur" << endl << "5-Fri" << endl << "6-Sat" << endl << "7-sun" << endl;cout << "Enter Day";cin >> d;obj.set(d);cout << "Present day is";obj.print(d);cout << "Enter number of days next";cin >> d;n = obj.Next_day(d);cout << "Next day is";obj.print(n);cout << "Enter number of days previous";cin >> d;p = obj.prev_day(d);cout << "previous day is";obj.print(p);system("Pause");return 0;}See more about C++ at brainly.com/question/29225072#SPJ1

Related Question in Computers and Technology