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.
1.Set the day
2.Print the day
3.Return the day
4.Return the next day
5.Return the previous day
6.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.
So far I have 1-3 completed and have created my array holding 7 string values one being each day of the week. From there I am kind lost on how I am supposed to call display the array and use a counter to make the calculations. Any help is appreciated, bellow is my code so far:
/****************************************************************
Written By: Jeremy Duenas Date: 5/1/2010
Program: Sets variable day to a day of the week(Sunday by default)
Prompts user to enter a day of the week
Prints the users data on the screen for the user to read
****************************************************************/
#include <iostream>
#include <string>
using namespace std;
class DayOfTheWeek
{
private:
string day;
public:
void setDay(string);
void getDay(string&);
void plusOneDay();
void minusOneDay();
void addDays();
void printDay();
};
int main()
{
DayOfTheWeek myDay; //default constructor, object myDay of class
DayOfTheWeek
string today; //declares vaiable theday
string gottenDay = " "; //declares empty varriable gottenday
DayOfTheWeek normalWeek[7];
normalWeek[0].setDay("Monday");
normalWeek[1].setDay("Tuesday");
normalWeek[2].setDay("Wednesday");
normalWeek[3].setDay("Thursday");
normalWeek[4].setDay("Friday");
normalWeek[5].setDay("Saturday");
normalWeek[6].setDay("Sunday");
cout << "Enter what day it is: ";
getline(cin, today);
myDay.setDay(today); //sets the day to the value entered by the user
myDay.printDay(); //prints to the screen the value
entered by the user
myDay.getDay(gottenDay);
myDay.printDay();
system("pause");
}
void DayOfTheWeek::setDay(string anyDay){day = anyDay;}
//function setDay sets the variable day in the private class to
variable theDay
void DayOfTheWeek::getDay(string& x){x = day;} //function
getDay gets the variable day from the private section of the class and
assignes it to the variable theDay
void DayOfTheWeek::printDay()
//function printDay prints the data to the screen for the user
to read
{
cout << "The day today is, "<< day << endl;
}

New Topic/Question
Reply




MultiQuote







|