Need help

hello guys ,
ive been trying for quite long so please if anyone can help i really need it

here's the question :
Create a class called Date that includes three pieces of information as data members: a month (type int),
a day (type int) and a year (type int). Your class should provide the following services:
1. Constructor with three parameters to initialize the three data members. For the purpose of this
exercise, assume that the values provided for the year and day are correct, but ensure that the
month value is in the range 1-12; if it isn't, set the month to 1.
2. Set and get for each data member.
3. Member method displayDate that displays the month, day and year separated by forward
slashes (/).
For example: 01/28/2016
4. Main method that demonstrates your class capabilities.



and here is what i did


#include <iostream>
using namespace std;
class date{
int day;
int month;
int year;

public:
date(int d, int m, int y);
void set_day();
void set_month();
void set_year();
int get_day();
int get_month();
int get_year();
void display();

};

date::date(int d, int m, int y)
{
if (m < 1 || m >12)
month = 1;
else
month = m;
day = d;
year = y;
}
void date::set_day()
{
cout << "please enter day:" << endl;
cin >> day;
}
void date::set_month()
{
cout << "please enter month:" << endl;
cin >> month;
}
void date::set_year()
{
cout << "please enter year:" << endl;
cin >> year;
}
int date::get_day()
{
return day;
}
int date::get_month()
{
return month;
}
int date::get_year()
{
return year;
}
void date::display()
{
cout << day << "/" << month << "/" << year << endl;
}
int main()
{




system("pause");
return 0;
}


please just help me tell me what i write in the main function cause i really have no idea i tried a lot of things but nothing worked
I would do it like this:
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
using namespace std;

class Date
{
  int day;
  int month;
  int year;

public:
  Date (int d, int m, int y);
  void set_day (int day);
  void set_month (int month);
  void set_year (int year);
  int get_day ();
  int get_month ();
  int get_year ();
  void display ();

};

Date::Date (int d, int m, int y)
{
  if (m < 1 || m >12)
    month = 1;
  else
    month = m;
  day = d;
  year = y;
}
void Date::set_day (int day)
{
  this->day = day;
}
void Date::set_month (int month)
{
  this->month = month;
}
void Date::set_year (int year)
{
  this->year = year;
}
int Date::get_day ()
{
  return day;
}
int Date::get_month ()
{
  return month;
}
int Date::get_year ()
{
  return year;
}
void Date::display ()
{
  cout << day << "/" << month << "/" << year << endl;
}

int main ()
{
  int day, month, year;

  cout << "please enter day: ";
  cin >> day;

  cout << "please enter month: ";
  cin >> month;

  cout << "please enter year: ";
  cin >> year;

  Date date (day, month, year);

  date.display ();

  system ("pause");
  return 0;
}
Topic archived. No new replies allowed.