Avatar of IbanezRG
IbanezRG

asked on 

Help with changes to Program that contains a class implementing days of the week

Here is my problem, the program is suppose to 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 Monday object is still Monday
Monday - 3 = Sunday
Press any key to continue.....

This is last weeks code completed:
#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;
}

Open in new window

This is the code with some changes

// 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;
}

Open in new window

Programming Languages-OtherVisual C++.NETC++

Avatar of undefined
Last Comment
IbanezRG
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of IbanezRG
IbanezRG

ASKER

1>Week1lab_AlexanderBelville.cpp
1>c:\users\alex\documents\visual studio 2008\projects\week1lab_alexanderbelville\week1lab_alexanderbelville.cpp(41) : error C2511: 'std::string DayOfTheWeek::getDay(void)' : overloaded member function not found in 'DayOfTheWeek'
1>        c:\users\alex\documents\visual studio 2008\projects\week1lab_alexanderbelville\week1lab_alexanderbelville.cpp(18) : see declaration of 'DayOfTheWeek'
1>c:\users\alex\documents\visual studio 2008\projects\week1lab_alexanderbelville\week1lab_alexanderbelville.cpp(46) : error C2440: 'initializing' : cannot convert from 'std::string' to 'int'
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\alex\documents\visual studio 2008\projects\week1lab_alexanderbelville\week1lab_alexanderbelville.cpp(60) : error C2653: 'DayOfWeek' : is not a class or namespace name
1>c:\users\alex\documents\visual studio 2008\projects\week1lab_alexanderbelville\week1lab_alexanderbelville.cpp(85) : error C2059: syntax error : '}'
1>c:\users\alex\documents\visual studio 2008\projects\week1lab_alexanderbelville\week1lab_alexanderbelville.cpp(85) : error C2143: syntax error : missing ';' before '}'
1>c:\users\alex\documents\visual studio 2008\projects\week1lab_alexanderbelville\week1lab_alexanderbelville.cpp(85) : error C2059: syntax error : '}'
1>c:\users\alex\documents\visual studio 2008\projects\week1lab_alexanderbelville\week1lab_alexanderbelville.cpp(87) : error C2143: syntax error : missing ';' before '{'
1>c:\users\alex\documents\visual studio 2008\projects\week1lab_alexanderbelville\week1lab_alexanderbelville.cpp(87) : error C2447: '{' : missing function header (old-style formal list?)
1>Build log was saved at "file://c:\Users\Alex\Documents\Visual Studio 2008\Projects\Week1lab_AlexanderBelville\Debug\BuildLog.htm"
1>Week1lab_AlexanderBelville - 8 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of IbanezRG
IbanezRG

ASKER

A--
C++
C++

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

58K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo