You need to create an object of type date before you can call any of it's functions. Use cin to get a value first, then call the function with that value.
1 2 3 4 5
|
date MyDate; //this creates a date object
int d;
cout <<"What day is it?\n";
cin >> d;
MyDate.setDay(d);
| |
Where are the definitions of your functions?
Also, it is good practice to name the member variables with a leading m_ as in m_day. This is a reminder to you that it is a member variable, and makes naming function arguments easier.
And don't use
using namespace std;
it brings in heaps of stuff polluting the global namespace and causing naming conflicts for variables and function names.
Either put
std::
before each std thing or put these after the include directives:
1 2 3 4
|
using std::cout;
using std::cin;
using std::endl; //similar for other std things
| |
I tend to do a mixture- do the using statements for frequently used things, and std:: for less frequent things like
std::find
or
std::sort
for example.
Instead of having a set / get function for each member variable, think about how it might happen in real life, and organise your functions that way. You could have a function setDate which asks for and sets all 3 variables. And a PrintDate function that prints out the date in the right format. This has the added advantage that the code is encapsulated in the class, leaving minimal code in main(). Remember that class functions have access to the classes' private & protected members. So main might look like this:
1 2 3 4 5 6 7 8 9
|
int main() {
date MyDate;
MyDate.setDate();
MyDate.PrintDate;
return 0;
}
| |
Be aware hat you can build up cout statements over several lines - there is no need to have it all on one line - though line 27 is not too bad. I am just pointing out something for the future. It could be done equivalently:
1 2
|
cout <<"\n\n\t\t\t\tThat makes it "<<date.getMonth();
cout <<"/"<<date.getDay()<<"/"<<date.getYear()<<"!";
| |
There is a bit of a rule that code should not exceed 80 chars per line for readability, and functions not longer than 80 lines.
Hope all this helps :)