// DayOfTheWeek.cpp : main project file.
#include <iostream>
#include <string>
usingnamespace 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.
string plusOneDay(int, int &, int &, string);
string minusOneDay(int, int &, int &, string);
int addDays();
private:
string day; // This is where the value of the day attribute is stored.
int convertToInt(string);
string ConvertToString(int);
};
string DayOfTheWeek::getDay() const {
return day;
}
void DayOfTheWeek::setDay(string newDay) {
day = newDay;
}
void DayOfTheWeek::printDay() const {
cout << day;
}
//the convertToInt function converts a string argument into an int
int DayOfTheWeek::convertToInt(string sValue){
int iNum=0;
if(sValue=="Sunday"){iNum=0;}
elseif(sValue=="Monday"){iNum=1;}
elseif(sValue=="Tuesday"){iNum=2;}
elseif(sValue=="Wednesday"){iNum=3;}
elseif(sValue=="Thursday"){iNum=4;}
elseif(sValue=="Friday"){iNum=5;}
elseif(sValue=="Saturday"){iNum=6;}
else{cout<<"The string entered is not a day of the week! Setting day to Monday."<<endl; iNum=1;}
return iNum;
}
//the convertToString function converts an int value into a string
string DayOfTheWeek::ConvertToString(int intValue){
string dayVariable="";
switch (intValue){
case'0': dayVariable="Sunday"; break;
case'1': dayVariable="Monday"; break;
case'2': dayVariable="Tuesday"; break;
case'3': dayVariable="Wednesday"; break;
case'4': dayVariable="Thursday"; break;
case'5': dayVariable="Friday"; break;
case'6': dayVariable="Saturday"; break;
}
return dayVariable;
}
string DayOfTheWeek::plusOneDay(int addDay, int &iNum, int &dayVariable, string addDayString){
addDay = iNum + 1;
ConvertToString(addDay);
addDayString = dayVariable;
return addDayString;
}
string DayOfTheWeek::minusOneDay(int minusDay, int &iNum, int &dayVariable, string minusDayString){
minusDay = iNum - 1;
ConvertToString(minusDay);
minusDayString = dayVariable;
return minusDayString;
}
int main()
{
DayOfTheWeek monday;
DayOfTheWeek tuesday;
// Set the values of the objects
monday.setDay("Mon");
tuesday.setDay("Tues");
// 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 next day
string nextDay = monday.plusOneDay();
cout << "The day after Monday is " << nextDay << "." << endl;
// Print out the value of the previous day
string previousDay = monday.minusOneDay();
cout << "The day before Monday is " << previousDay << "." << endl;
// We're finished
return 0;
}
1 2 3 4 5 6 7 8 9 10 11
1
1>Build started 7/17/2011 1:42:05 PM.
1>_PrepareForClean:
1> Deleting file "Debug\Week2Lab_NicholasMarlatt.lastbuildstate".
1>InitializeBuildStatus:
1> Touching "Debug\Week2Lab_NicholasMarlatt.unsuccessfulbuild".
1>ClCompile:
1> DaysOfWeek.cpp
1>c:\users\nick\documents\visual studio 2010\projects\week2lab_nicholasmarlatt\week2lab_nicholasmarlatt\daysofweek.cpp(99): error C2660: 'DayOfTheWeek::plusOneDay' : function does not take 0 arguments
1>c:\users\nick\documents\visual studio 2010\projects\week2lab_nicholasmarlatt\week2lab_nicholasmarlatt\daysofweek.cpp(103): error C2660: 'DayOfTheWeek::minusOneDay' : function does not take 0 arguments
1>
1>Build FAILED.
You're using iNum to give addDay a value, but iNum has never been set to anything and you don't attempt to pass it in when you actually (incorrectly) called the function. What do you expect iNum to be at this point?