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:
-Set the day
-Print the day
-Return the day
-Return the next day
-Return the previous day
-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.
-Add the appropriate constructors.
-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.
I'm a beginner of OOD field. I have find note from internet but i realy don't know how to solve. Please help, thanks!
I hope you don't expect anybody to do that for you.
That withstanding, here's what I'd suggest:
Define your class with an enumeration for the day as the member. The methods all look fairly simple with the exception of the next and previous - for those ones, you'll have to remember to loop back around to the other end of the week if you're at the edge of your enumeration. For example, with an enum from sunday to saturday, if you called previous day on sunday you'd need to make sure to return saturday.
That function for calculating the day could be done fairly simply by performing a modulus on the number of days forward or backward, and then using code similar to that in your previous/later day function to determine where it is.
I suppose your default constructor should initialize to a "regular" day (monday?) while you should have an int constructor for taking a day of the week (1-7 I guess) or a string constructor.
So what exactly is confusing you about this assignment? You threw a homework assignment at us but we have no idea what your actual issue is with it. If you are really hopelessly confused try planning it out on paper first.