The code is implemented based on the given operations.
Explanation:
#include <iostream>
#include <string>
using namespace std;
class dayType
{ private:
string day[7];
string presentDay;
int numofDays;
public:
void setDay(string freshDay);
void printDay() const;
int showDay(int &day);
int nextDay(int day);
int prevDay(int day) const;
int calcDay(int day, int numofDays);
dayType()
{
day[0] = "Sunday";
day[1] = "Monday";
day[2] = "Tuesday";
day[3] = "Wednesday";
day[4] = "Thursday";
day[5] = "Friday";
day[6] = "Saturday";
presentDay = day[0];
numofDays = 0;
};
~dayType();
};
#endif
#include "dayType.h"
void dayType::setDay(string freshDay)
{
presentDay = freshDay;
}
void dayType::printDay()
{
cout << "Day chosen is " << presentDay << endl;
}
int dayType::showDay(int& day)
{
return day;
}
int dayType::nextDay(int day)
{
day = day++;
if (day > 6)
day = day % 7;
switch (day)
{
case 0: cout << "The successive day is Sunday";
break;
case 1: cout << "The successive day is Monday";
break;
case 2: cout << "The successive day is Tuesday";
break;
case 3: cout << "The successive day is Wednesday";
break;
case 4: cout << "The successive day is Thursday";
break;
case 5: cout << "The successive day is Friday";
break;
case 6: cout << "The successive day is Saturday";
break;
}
cout << endl;
return day;
}
int dayType::prevDay(int day)
{
day = day--;
switch (day)
{
case -1: cout << "The before day is Saturday.";
break;
case 0: cout << "The before day is Saturday.";
break;
case 1: cout << "The before day is Saturday.";
break;
case 2: cout << "The before day is Saturday.";
break;
case 3: cout << "The before day is Saturday.";
break;
case 4: cout << "The before day is Saturday.";
break;
case 5: cout << "The before day is Saturday.";
break;
default: cout << "The before day is Saturday.";
}
cout << endl;
return day;
}
int dayType::calcDay(int addDays, int numofDays)
{
addDay = addDays + numofDays;
if (addDay > 6)
addDay = addDay % 7;
switch(addDay)
{
case 0: cout << "The processed day is Sunday.";
break;
case 1: cout << "The processedday is Monday.";
break;
case 2: cout << "The processedday is Tuesday.";
break;
case 3: cout << "The processedday is Wednesday.";
break;
case 4: cout << "The processedday is Thursday.";
break;
case 5: cout << "The processedday is Friday.";
break;
case 6: cout << "The processedday is Saturday.";
break;
default: cout << "Not valid choice.";
}
cout << endl;
return addDays;
}