C++ Class

So i'm trying to make program using class. I need to make this to work by using set/get....I'm stuck here and still it does not work....





#include<iostream>
#include<iomanip>


using namespace std;

int main()

class Date();

int date_1;
int date_2;
int date_3;

cout<<"\n Enter the date in the pattern i.e dd/mm/yy "<<endl;

cout<<"\n First Date :"<<endl;
date_1.get_date();

cout<<"\n Second Date :"<<endl;
date_2.get_date();

cout<<"\n********** First Date **********"<<endl;
date_1.show_date();

cout<<"\n********** Second Date **********"<<endl;
date_2.show_date();

cout<<"\n********** Result **********\n"<<endl;
if(date_1>date_2)
date_3.show_days(date_2,date_1);

else
date_3.show_days(date_1,date_2);

getch();
return 0;
}
Last edited on
date_1, date_2, and date_3 are ints, not Date objects as you seem to suggest.

Also, your line "class Date();" is not valid.

You need to actually make a class called Date and give it the appropriate data members and functions.

e.g.
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
class Date {
  private:
    int year;
    int month;
    int day;

  public:
    void get_date()
    {
        // fill in year, month, day from user input, presumably
    }

    void show_date()
    {
        // print year, month, day
    }

    void show_days(const Date& date1, const Date& date2)
    {
        // idk what the point of this is, but here you go
    }

    bool operator<(const Date& date)
    {
        // compare this to another Date
        return true; // TODO
    }
};


1
2
3
4
5
6
7
8
int main()
{
    Date date_1;
    Date date_2;
    Date date_3;

    // ...
}
Last edited on
Topic archived. No new replies allowed.