how to finish the code in main function

here is the started code:

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
#include <iostream>
using namespace std;

class date
{
	public:
		date();
		date(int, int, int);
		void print() const;
	private:
		int month, day, year;
};
date::date()
{
	cout<<"date() ";
	month=1;
	day=1;
	year = 2000;
}
date::date(int x, int y, int z)
{
	month =x;
	day = y;
	year = z;
}
void date::print() const
{
	cout<<month<<'-'<<day<<'-'<<year<<endl;
}

int main()
{
	
	
	return 0;
}

i want to know how to finish the simple porgram that will output some random date, what do i need to type in the main function
Last edited on
Your date class has 2 constructors. The first takes no arguments (default constructor) and sets an object to Jan 1, 2000. The second constructor takes 3 arguments and creates a date from them. You can create a date object with either of the following lines:
1
2
date defaultDate;
date today(4, 19, 2016);


The first line creates a variable named defaultDate set to 1/1/2000. The second creates a variable named today set to 4/19/2016.

In order to print out the contents of the date object, simply call the print() function on the object. For instance:

today.print();
thank you very much, you clarified the things a lot, i am a noob at oop c++, so this helped a lot :)
Topic archived. No new replies allowed.