Need Help C++ Data structure

Hey Everyone. I've given an assignment on C++ Data structure. I'm using visual code.

I've finish all the required part but sadly I've encountered errors on the (Sunday and Saturday part) during the run. * I was so close to the final result, can anybody guide/help me on my errors. Thank you and God Bless you.

The errors are with my output.

1a). 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.

1b). Then, write the definitions of the functions to implement the operations for the class dayType as defined in Programming above. Also, write a program to test various operations on this class.

The following are my Header file, Implementation file and Main file.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  //Header file

#include<iostream>
#include<string>
using namespace std;

class dayType
{
public:
dayType();

string day[8];
int dayNumber;
int tempDay;

void setDay(int day);
void printDay();
void returnDay(int &day);
void returnNextDay();
void returnPreviousDay();
void calculateDay(int changeDay);

};


//Implementation file

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

using namespace std;

void dayType::printDay()
{
cout << "Today is: " << day[dayNumber] << "day" << endl;};

void dayType::setDay(int day)
{
dayNumber=day;};

void dayType::returnDay(int &day)
{
day=dayNumber;};

void dayType::returnNextDay()
{
dayNumber++;};

void dayType::returnPreviousDay()
{
dayNumber--;};

void dayType::calculateDay(int changeDay)
{
tempDay=(dayNumber+changeDay);
dayNumber=(tempDay%7);};


//Main file

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

using namespace std;

int main()
{
dayType today;

int day;
int changeDay;

cout << "------------------------------------------------------------------" << endl;
cout << "Default day is Sunday " << endl;
cout << "Type in a number corresponding to set the day" << endl
<< "1: Monday" << endl
<< "2: Tuesday" << endl
<< "3: Wednesday" << endl
<< "4: Thursday" << endl
<< "5: Friday" << endl
<< "6: Saturday" << endl
<< "7: Sunday" << endl;

while (day<0 || day>7)
cin >> day;

today.setDay(day);
today.printDay();

today.returnDay(day);
today.printDay();

cout << "-----------------------------------------------------------------" << endl;
cout << "If it were tomorrow, then the following statement would be true: " << endl;
today.returnNextDay();
today.printDay();
today.dayNumber--;

cout << "-----------------------------------------------------------------" << endl;
cout << "If it were yesterday, then the following statement would be true:" << endl;
today.returnPreviousDay();
today.printDay();
today.dayNumber++;

cout << "-----------------------------------------------------------------" << endl;
cout << "Add a number of days to today and see what day it will be: " << endl;
cin >> changeDay;

today.calculateDay(changeDay);
today.printDay();

return 0;
};

dayType::dayType()
{
dayNumber=1;
day[1]="Mon";
day[2]="Tues";
day[3]="Wednes";
day[4]="Thurs";
day[5]="Fri";
day[6]="Satur";
day[7]="Sun";
};

Topic archived. No new replies allowed.