for school, dont know what to do

so im a new comp sci major in college i did good last semester and now im in a new semester with a different teacher, well apparently in the first semester we should have learned how to make classes pretty well but we didn't... and now my first assignment in my new class is to create a class in c++ that keeps track of the day this is what i have so far

(i honestly have no idea where to go from here... here are the program instructions.

Write the definition of the class dayType the implements the day of the week in a program. The class dayType should store the day, such as sunday for Sunday. The program should be able to perform the following operations on an object of type dayType:
1. set the day
2. print the day
3. return the day
4. return the next day
5. return the previous day
6. calculate the day when adding n amount of days.)


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

enum day{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday};

class dayType
{
public:
void daySet()//set the day
{
};

void dayPrint() //print out the current day
{
};


int tomorrow()//return what the next day will be
{
return (day+1)%7;
};

int yesterday()// return what the day before was
{
return (day-1)%7;
};

int add_to_day(int n)//return what the day would be plus n
{
return (day+n)%7;
};




private:
day date;


im not asking for anyone to do the program for me, just a tip or two or some guidance on where i need to go next...
What about a constructor? What if I want to say dayType fav("Sunday"); or dayType myfunday(0);
Make it so that your program has a constructor with default arguments. Accept either the day as a number or a std::string.

Your enum is fine, but you'll Still need to std::cout the strings.
1
2
3
if (date == Sunday)
  std::cout << "Sunday" << std::endl;
// more statements to print here. 


What about if statements to catch if I set the date outside of your week? Or will you just %7 me back in the right date?

myday.setDate(3495); // You're gonna need to handle this.

EDIT: Why do you have semicolons after each {} in your functions. remove the {}.
Last edited on
As for determining the day given a set amount of days to go forward... use static casting to increase the value of the enum variable.

For example...

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
#include <iostream>
using std::cout;
#include <limits>
#include <string>
using std::string;

enum days_e {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};
string returnDay(days_e days);

int main(int argc, char* argv[])
{
    days_e days;
    days = Monday;
    cout << "Today is: " << returnDay(days) << std::endl;
    days = (days_e)(days + 1);
    cout << "Today is: " << returnDay(days) << std::endl;
    
    cout << "Press <ENTER> to continue...";
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    
    return 0;
}

string returnDay(days_e days)
{
    switch(days)
    {
        case Monday:
             return "Monday";
        case Tuesday:
             return "Tuesday";
        case Wednesday:
             return "Wednesday";
        case Thursday:
             return "Thursday";
        case Friday:
             return "Friday";
        case Saturday:
             return "Saturday";
        case Sunday:
             return "Sunday";          
    }       
}


The only problem is that if you increment the days var beyond the number of members in the enum, your program will crash. Someone want to give a solution beyond that?
ik i need constructors and what not, i just dont know where to start to make them nor do i know what i need to put in the private area. and the day date; i put in as some kind of way of pulling the number out of the enum but i have no idea if i did it right. and as far as your question about modding from my understanding %7 should break any number down small enough so that the remainder will keep you with in a 7 day week
I guess I didn't completely read wolfgang's post... just noticed the %7 solution.
so this is what i have so far and what i have changed given the info you all have given me and thank you by the way. am i using it in the right context how ever? and as far as constructors go i have no idea where to start i know u named some but they dont really deal with the instruction for my project that i stated in my original post. any way here is what i have so far

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
#include <iomanip>
#include <iostream>
using namespace std;

enum day{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday};

class dayType
{
        public:
                void daySet()//set the day

                string returnDay(day date)
                {
                        switch(date)
                        {
                        case Monday:
                                return "Monday";
                        break;
                        case Tuesday:
                                return "Tuesday";
                        break;
                        case Wednesday:
                                return "Wednesday";
                        break;
                        case Thursday:
                                return "Thursday";
                        break;
                        case Friday:
                                return "Friday";
                        break;
                        case Saturday:
                                return "Saturday";
                        break;
                        case Sunday:
                                return "Sunday";
                        break;
                        }
                }


                string dayPrint(day date);   //print out the current day


                int tomorrow()//return what the next day will be
                {
                        return (date+1)%7;
                }

                int yesterday()// return what the day before was
                {
                        return (date-1)%7;
                }

                int add_to_day(int n)//return what the day would be plus n
                {
                        return (date+n)%7;
                }




        private:
        day date;






}


int main()
{
}
-- INSERT --                                                  
i will probably end up changing the switch statement into if statements for my own clarity later how ever
1
2
3
4
5
// constructors for my class
                dayType::dayType(int n)// in theory by changing the variable n now the user can controll what the day is
                {day=n;
                }
 

thats my attempt at creating a constructor again i have no idea what im really doing just tying to read in my txt book and figure it out
so i have been working on it a little and this is where im stuck now.
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
#include <iomanip>
#include <iostream>
using namespace std;

enum day_orig{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday};
string returnDay(day_orig day);

class dayType
{
        public:
                void daySet();//set the day

                string returnDay(day_orig day)
                {
                        switch(day)
                        {
                        case Monday:
                                return "Monday";
                        break;
                        case Tuesday:
                                return "Tuesday";
                        break;
                        case Wednesday:
                                return "Wednesday";
                        break;
                        case Thursday:
                                return "Thursday";
                        break;
                        case Friday:
                                return "Friday";
                        break;
                        case Saturday:
                                return "Saturday";
                        break;
                        case Sunday:
                                return "Sunday";
                        break;
                        }
                }


                string dayPrint(day_orig day);   //print out the current day


                int tomorrow()//return what the next day will be
                {
                        return (day+1)%7;
                }

                int yesterday()// return what the day before was
                {
                        return (day-1)%7;
                }

                int add_to_day(int n)//return what the day would be plus n
                {
                        return (day+n)%7;
                }




        private:
        day_orig day;







};
// constructors for my class



                int main()
{



                day_orig day;
                day=Monday;//d is the day you want to start on
                cout<<"Today is "<<returnDay(day)<<endl;
                day = (day_orig)((day+1)%7);
                cout<<"Today is "<<returnDay(day)<<endl;

                return 0;
}




i have reworked my code and now this is where i am at
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

 #include <iostream>
        #include<string>

        using namespace std;
        string my_Day[7] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };

        class day //initialize the class
        {
                public:
                        day();

                        void setDay(string);
                        void printDay();
                        string getDay();
                        void addDay();


                private:
                // set an integer to represent the day
                int my_Day2;




        };

        day::day() //set the day to a defult
        {
        my_Day2 = 0;
        }

        void day::addDay()
        {
        my_Day2++;
                if (my_Day2 > 7)
                my_Day2 = 1;
                }

                string day::getDay() //return the day
                {
                return my_Day[my_Day2];
                }


        void day::setDay(string newDay) // reset the day to a new one
{
        // set the day integer variable to the co-insiding day
        for (int i = 0; i < 7; i++)
        {
                if (newDay.compare(my_Day[i]) == 0)
        {
                my_Day2 == i;
                return;
        }
        }
        // If this code is reached then newDay was not viable,
        // so set the day to 0.
        my_Day2 = 0;
        }

        void day::printDay() //this code prints out the day
        {
        cout << "The day is " <<getDay()<< endl;
        }
        int main()
        {

        return 0;
        }
                                                                  






well i finished the program and finally did it haha thank you all for your help
Topic archived. No new replies allowed.