Long compiler, I believe I'm missing code but not sure.

Mar 7, 2011 at 5:05pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//Day of the Week Program- Richard Mooney//

#include <iostream>
#include <string>

using namespace std;

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

int main()
{

DayOfTheWeek monday;
DayOfTheWeek tuesday;

monday.setDay("Monday");
monday.getDay();
monday.printDay();
{
	cout <<"The value for the monday object is " <<monday<<"."<<endl;
}

tuesday.setDay("Tuesday");
tuesday.getDay();
tuesday.printDay();
{
	cout <<"The value for the monday object is " <<tuesday<<"."<<endl;
}
return 0;
}


I get like a page of errors. I know I'm missing code somewhere, I just can't figure out how to make this work.
Mar 7, 2011 at 5:12pm
You did not define any method declared in DayOfTheWeek. You are printing monday and tuesday as if you overloaded the ostream << operator ( which you didn't )
Mar 7, 2011 at 5:15pm
Well there are several things you might want to do...differently

First, you declared your methods setDay, printDay, and getDay, and ... never actually implemented the methods?
In this case simply
1
2
3
  void DayOfTheWeek::setDay(string instring){
Day = instring;
}

and so on with the rest of the methods.

on another note, you never stored the value of monday.getDay();

on another note again, you can just << monday I believe, if you overload the << operator. But I don't think that's what you were trying to do when you were cout'ing the day's value.

What you'd want to do is cout << monday.getDay();

argh bazzy! Barely before me!
Last edited on Mar 7, 2011 at 5:16pm
Mar 8, 2011 at 9:05pm
I'm not sure what any of this means.

Man I wish my professor would actually go over this stuff instead of talking about sports the entire class. :(
Topic archived. No new replies allowed.