I need help with this program, I am new and i am loosing the battle.
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 five
days to Saturday, the day to be returned is Thursday. Likewise, if we add 12 days to Wednesday, the day returned
will be Monday.
This is my original code which I have to add what is missing.
#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("Mon.");
tuesday.setDay("Tues.");
wednesday.setDay("Wed.");
thursday.setDay("Thur.");
friday.setDay("Fri.");
saturday.setDay("Sat.");
sunday.setDay("Sun.");
// 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;
}
This is the code with some changes but some errors
// Week1lab_AlexanderBelville.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
#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();
string addDays(int numberOfAdditionalDays);
private:
int day; // This is where the value of the day attribute is stored.
int toNumber(string);
string toName(int);
};
string DayOfTheWeek::getDay()
{
return day;
}
void DayOfTheWeek::setDay(string newDay)
{
int day = newDay;
}
void DayOfTheWeek::printDay() const
{
cout << day;
}
void DayOfTheWeek::plusOneDay()
{
}
void DayOfTheWeek::minusOneDay()
{
}
int DayOfWeek::toNumber(string name)
{
if (name == "Monday") return 0;
if (name == "Tuesday") return 1;
if (name == "Wednesday") return 2;
if (name == "Thursday") return 3;
if (name == "Friday") return 4;
if (name == "Saturday") return 5;
if (name == "Sunday") return 6;
}
string DayOfTheWeek::toName(int idx)
{
idx = idx % 7;
switch (idx)
{
case 0: return "Monday"; break;
case 1: return "Tuesday"; break;
case 2: return "Wednesday"; break;
case 3: return "Thursday"; break;
case 4: return "Friday"; break;
case 5: return "Saturday"; break;
case 6: return "Sunday"; break;
}
}
}
int main()
{
DayOfTheWeek monday;
DayOfTheWeek tuesday;
DayOfTheWeek wednesday;
DayOfTheWeek thursday;
DayOfTheWeek friday;
DayOfTheWeek saturday;
DayOfTheWeek sunday;
// Set the values of the objects
monday.setDay("Mon.");
tuesday.setDay("Tues.");
wednesday.setDay("Wed.");
thursday.setDay("Thur.");
friday.setDay("Fri.");
saturday.setDay("Sat.");
sunday.setDay("Sun.");
// 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;
}