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

What needs to happen: An input from the user (number) corresponds to a day of th

ID: 673726 • Letter: W

Question

What needs to happen:

An input from the user (number) corresponds to a day of the week. The next number will add to that day to give a future day of the week. The output needs to show present day, yesterday, tomorrow and the future day. As of now, I can get the present day of the week and the previous and after that I got stuck. I did change the code around a little so it might not look the best right now.

I would like to keep the code I have intact as much as possible.

#include <iostream>
#include <cmath>

using namespace std;

class dayType
{
public: int presday;
int prevday;
int nextday;
dayType()
{
presday = 0;
nextday = 0;
prevday = 0;
}
void set(int day);
void print(int day);
int Next_day(int pres);
int day();
int Prev_day(int pres);
};

void dayType :: set(int day)
{
presday = day;
}

int dayType :: Prev_day(int day)
{
prevday = (presday - 1);
if(prevday <= 0)
prevday = 7 - abs(prevday);
return prevday;
}

int dayType :: Next_day(int day)
{
nextday = (presday + 1);
if(nextday <= 0)
{
if(nextday % 7 == 0)
nextday = presday;
else
nextday = nextday % 7;
}

return nextday;
}

void dayType :: print(int d)
{
if(d == 1)
cout << "Mon" << endl;
if(d == 2)
cout << "Tue" << endl;
if(d == 3)
cout << "Wed" << endl;
if(d == 4)
cout << "Thur" << endl;
if(d == 5)
cout << "Fri" << endl;
if(d == 6)
cout << "Sat" << endl;
if(d == 7)
cout << "Sun" << endl;
}

int main()
{
int d, p, n;
dayType obj;

cout << "Enter day: ";
cin >> d;
obj.set(d);

cout << "Today is: ";
obj.print(d);

p = obj.Prev_day(d);

cout << "Yesterday was: ";
obj.print(p);

n = obj.Next_day(d);

cout << "Tomorrow is: ";
obj.Next_day(n);

}

Explanation / Answer

#include <iostream>

#include <cmath>

using namespace std;

class dayType

{

public:

int presday;

int prevday;

int nextday;

dayType()

{

presday = 0;

nextday = 0;

prevday = 0;

}

void set(int day);

void print(int day);

int Next_day(int pres);

int day();

int Prev_day(int pres);

};

void dayType :: set(int day)

{

presday = (day%7)+1;

}

int dayType :: Prev_day(int day)

{

prevday = ((presday - 1)%7)+1;

return prevday;

}

int dayType :: Next_day(int day)

{

nextday = ((presday + 1)%7)+1;

return nextday;

}

void dayType :: print(int d)

{

if(d == 1)

cout << "Mon" << endl;

if(d == 2)

cout << "Tue" << endl;

if(d == 3)

cout << "Wed" << endl;

if(d == 4)

cout << "Thur" << endl;

if(d == 5)

cout << "Fri" << endl;

if(d == 6)

cout << "Sat" << endl;

if(d == 7)

cout << "Sun" << endl;

}

int main()

{

int d, p, n;

dayType obj;

cout << "Enter day: ";

cin >> d;

obj.set(d);

cout << "Today is: ";

obj.print(obj.presday);

cout << "Yesterday was: ";

  

obj.print(obj.Prev_day(d));

cout << "Tomorrow is: ";

  

obj.print(obj.Next_day(n));

  

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote