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

I\'m having trouble with this C++ program that will need to design and implement

ID: 3661630 • Letter: I

Question

I'm having trouble with this C++ program that will need to 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. g. Add the appropriate constructors.

Explanation / Answer

#include<iostream>

#include<string>

using namespace std;

class dayType

{

public:

dayType();

string day[8];

int dayNumber;

int tempDay;

dayType::dayType()

{

day[0]="Mond";

day[1]="Tues";

day[2]="Wednes";

day[3]="Thurs";

day[4]="Frid";

day[5]="Satur";

day[6]="Sun";

}

void setDay(int day); /* to set a day */

void printDay();

void returnDay(int &day);

void returnNextDay();

void returnPreviousDay();

void calculateDay(int changeDay);

};

/* function definations */

#include <iostream>

#include <string>

#include "dayType.h"

using namespace std;

void dayType::printDay() /* prints the given day from the array */

{

cout << "Today is: " << day[dayNumber] << "day" << endl}

void dayType::setDay(int day)

{

dayNumber=day;};

void dayType::returnDay(int &day)/* returns a given day */

{

dayNumber=day;

printDay();

}

void dayType::returnNextDay()/* function to calculate next day */

{

dayNumber++;

cout<<”the next day is “<<;

}

void dayType::returnPreviousDay()/* function to calculate the previous day*/

{

dayNumber--;

cout<<”the previous day is “<<;

}

void dayType::calculateDay(int adddays) /* function to calculate or add days to original day number and display the day *.

{

tempDay=(dayNumber+ adddays);

dayNumber=(tempDay%7);

}

/* the main part of the code */

#include <iostream>

#include "dayType.h"

using namespace std;

int main()

{

dayType Day1;

int dayy;

int adddays1;

cout << "Type in a number corresponding to set the day" << endl

<< "0: Monday" << endl

<< "1: Tuesday" << endl

<< "2: Wednesday" << endl

<< "3: Thursday" << endl

<< "4: Friday" << endl

<< "5: Saturday" << endl

<< "6: Sunday" << endl;

cout<<” enter the day number “<<;

cin>>dayy;            

Day1.setDay(dayy);

Day1.printDay();

Day1.returnDay(dayy);

cout << "-----------------------------------------------------------------" << endl;

cout << "to print the next day: " << endl;

Day1.returnNextDay();

Day1.printDay();

Day1.dayNumber--; /* gets the position of daynumber back to original after finding the next day */

cout << "to print the previous day:”<< endl;

Day1.returnPreviousDay();

Day1.printDay();

Day1.dayNumber++;/* gets back the daynumber back to original after finding the previous day (/

cout << "-----------------------------------------------------------------" << endl;

cout << "Add a number of days to day number of today and check what day it will be: " << endl;

cin >> adddays1;

Day1.calculateDay(adddays1);

Day1.printDay();

return 0;

};

OUTPUT:

Type in a number to set the day:2

Today is : Wednes

Today is: Wednes

The next day is:

Today is :Thurs

The previous day is:

Today is : tues”

Add a number of days to day number of today and check what day it will be: 4

Today is :Sun

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