• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Starting with Classes need help C++

#include <iostream>
#include <string>

using namespace std;

class DayOfTheWeek
{
public:
	void setDay(string );
	void printDay() const;
	string getDay() const;
private:
	string monday, tuesday;
	
};

void DayOfTheWeek::setDay(string mon, string Tues)
{
	monday = Mon
	tuesday = Tues
}

string DayOfTheWeek::getDay() const
{
	return monday;
	return tuesday;
}

void DayOfWeek::printDay()
{
	if (monday < 10)
		cout << "0";
	cout << monday << ":";
	if (tuesday < 10)
		cout << "0";
	cout << tuesday << ":";

int main()
{
	DayofTheWeek myDay;
	DayOfTheWeek newDay;

	myDay.setDay(monday);
	newDay.setDay(tuesday);

	cout << "Printing out monday object value" << endl;
	myDay.printDay();
	cout << endl << endl;

	cout << "Printing out tuesday object value" << endl;
	string firstDay = myDay.getDay();
	cout << firstDay << ":" << newDay.getDay() << ":" << newDay.getDay() << endl;
	
	return 0;

Open in new window

0
IbanezRG
Asked:
IbanezRG
2 Solutions
 
Infinity08Commented:
So, what's your question ?
0
 
evilrixSenior Software Engineer (Avast)Commented:
See my comments in the code. There were plenty of problems and for the most part the compiler errors were pretty simple. Try reading what the compiler is telling you and understanding the errors.
#include <iostream>
#include <string>

using namespace std;

class DayOfTheWeek
{
public:
   // <--- this should be two parameters
        //void setDay(string );
        void setDay(string, string );
        void printDay() const;
        string getDay() const;
private:
        string monday, tuesday;
        
};

// <--- incorrect case
//void DayOfTheWeek::setDay(string mon, string Tues)
void DayOfTheWeek::setDay(string Mon, string Tues)
{
   // <--- missing semi-colons
        //monday = Mon
        //tuesday = Tues
        monday = Mon;
        tuesday = Tues;
}

string DayOfTheWeek::getDay() const
{
   // <--- You can't have 2 return statements.
        //return monday;
        return tuesday;
}

//void DayOfWeek::printDay() // <--- Isn't the class called DayOfTheWeek? It should also be const.
void DayOfTheWeek::printDay() const
{
   /* <--- this just makes no sence, you can't perform numeric comparisons on strings
        if (monday < 10)
                cout << "0";
        cout << monday << ":";
        if (tuesday < 10)
                cout << "0";
        cout << tuesday << ":";
        */

} // <--- this was missing

int main()
{
   // <--- incorrect case
        //DayofTheWeek myDay;
        DayOfTheWeek myDay;
        DayOfTheWeek newDay;

        // <--- these need to be strings and there are 2 params
        //myDay.setDay(monday);
        //newDay.setDay(tuesday);
        myDay.setDay("monday", "tuesday");

        cout << "Printing out monday object value" << endl;
        myDay.printDay();
        cout << endl << endl;

        cout << "Printing out tuesday object value" << endl;
        string firstDay = myDay.getDay();
        cout << firstDay << ":" << newDay.getDay() << ":" << newDay.getDay() << endl;
        
        return 0;
} // <--- missing

Open in new window

0
 
evilrixSenior Software Engineer (Avast)Commented:
Also note, I have identified syntax errors but there are plenty of other problems that need to be fixed. I won't correct them for you though; now you have the ability to compile the code you should work through it. We can give you suggestions on what needs improving but as this is a learning experience it is up to you to do the work :)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
IbanezRGAuthor Commented:
I will star on it right now.
0
 
IbanezRGAuthor Commented:
I need to be really honest, I have all kinds of problems with this programming courses. I am getting my bachelors online and I am not grasping what I need to learn.
I need a tutor, and I need it quick. I need to get this lab done, and on Monday speak with my Academic adviser.
0
 
IbanezRGAuthor Commented:
I worked at it and I don't seem to get it.
If someone can help.
0
 
phoffricCommented:
>> I worked at it and I don't seem to get it.
Since you have many questions, instead of trying to work on the entire assignment at once, and asking very open-ended question, try writing down a list of basic items that you are having trouble with. Then ask about each item. After putting it all together, you may be able to do this project.
0
 
evilrixSenior Software Engineer (Avast)Commented:
>> and I don't seem to get it.
What don't you get?
0
 
IbanezRGAuthor Commented:
The help wasn't too clear.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now