Ok so I am in a programming course and I am working on one of my labs. We are supposed to add on to our code from the previous week, this is what I have so far:
Now some of this code is from the previous week and I may need to delete some of it, but I am just trying to get started on the task at hand. Basically I need toCode:// DayOfTheWeek.cpp : main project file. #include "stdafx.h" #include <iostream> #include <string> using namespace std; class DayOfTheWeek { public: void setDay(string ); // setDay(string) takes a string parameter // and stores the value in the day attribute. void printDay() const; // printDay() prints the value of the day attribute // on console output (cout). string getDay() const; // returns the value of the day attribute. void plusOneDay(); void minusOneDay(); void addDays(); private: string day; // This is where the value of the day attribute is stored. }; string DayOfTheWeek::getDay() const { return day; } void DayOfTheWeek::setDay(string newDay) { day = newDay; } void DayOfTheWeek::printDay() const { cout << day; } void DayOfTheWeek::plusOneDay() { } int main() { DayOfTheWeek monday; DayOfTheWeek tuesday; DayOfTheWeek wednesday; DayOfTheWeek thursday; DayOfTheWeek friday; DayOfTheWeek saturday; DayOfTheWeek sunday; // Set the values of the objects monday.setDay("Monday"); tuesday.setDay("Tuesday"); wednesday.setDay("Wednesday"); thursday.setDay("Thursday"); friday.setDay("Friday"); saturday.setDay("Saturday"); sunday.setDay("Sunday"); // Get the value of the monday object and print it out string currentDay = monday.getDay(); cout << "The value of the monday object is " << currentDay << "." << endl; // Print out the value of the tuesday object cout << "The value of the tuesday object is "; tuesday.printDay(); cout << "." << endl;; // We're finished return 0; }
Write a program that contains a class that implements the days of the week. The program should be able to perform the following on an object of the class.
Set the day
Print the day
Return the day
Return the next day
Return the previous day
Calculate and return the day by adding a certain amount of days to the current day. For example if you add 5 days to Saturday, the day to be returned is Thursday. Likewise, if we add 12 days to Wednesday, the the day returned will be Monday.
Here is an example of the output:
The value of the monday object is Monday.
The day after monday is Tuesday.
The day before monday is Sunday.
Monday + 3 = Thursday.
The value of the monday object is still Monday.
Monday - 3 = Friday.
I'm not really sure how to add and subtract days, any information would be very helpful! Thanks!