Help: bool function in classes

I'm working on a beginner practice problem on C++ classes.
it's a calendar problem, that takes 2 user input dates and compare which one comes earlier. it has 2 bool member functions that determines if the dates are equal & which one comes earlier. My question is how to call the bool functions in main? I get syntax error when i try to do is_equal(c1,c2);
if I were to do c1.is_equal(c2), how do I compare the two dates in the bool function?

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
81
82
83
84
85
86
#include <iostream>

using namespace std;

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

public:
       
  void set_date(int m, int d, int y); //allows user to set date    
  void display_date(); //displays months in words     
  int GetDay() {return day;}
  int GetMonth(){return month;}
  int GetYear(){return year;}
  bool is_less_than(Date&x, Date&y); //takes a date, return true if original is less than the one passed in
  bool is_equal(Date&x, Date&y);//determines if 2 dates are equal
  
};

int main ()
{  
    int m;
    int d;
    int y;
    char ch;
    cout << "Please Enter a Date in the Form xx/xx/xxxx" <<endl;
    cin >> m >> ch >> d >> ch >> y;
    Date c1;
    Date c2;

    c1.set_date(m, d, y);
    cout << "First Date is: ";
    c1.display_date();
    cout << "Please Enter a second Date in the Form xx/xx/xxxx" <<endl; 
    cin >> m >> ch >> d >> ch >> y;
    c2.set_date(m,d,y);
    cout << "Second Date is: ";
    c2.display_date();

    is_equal(c1,c2);

    system("pause");
    return 0;
}


void Date::set_date(int m, int d, int y)
{
  month = m;
  day = d;
  year = y;

} 

void Date:: display_date()
{
 if (month == 12) cout << "December " << day <<", " << year;
 else if (month == 11) cout << "November " << day <<", " << year <<endl;
 else if (month == 10) cout << "October " << day <<", " << year<<endl;
 else if (month == 9) cout << "September " << day <<", " << year<<endl;
 else if (month == 8) cout << "August " << day <<", " << year<<endl;
 else if (month == 7) cout << "July " << day <<", " << year<<endl;
 else if (month == 6) cout << "June " << day <<", " << year<<endl;
 else if (month == 5) cout << "May " << day <<", " << year<<endl;
 else if (month == 4) cout << "April " << day <<", " << year<<endl;
 else if (month == 3) cout << "March " << day <<", " << year<<endl;
 else if (month == 2) cout << "Feburary " << day <<", " << year<<endl;
 else if (month == 1) cout << "January " << day <<", " << year<<endl;
}
/*
bool Date:: is_less_than(Date&x, Date&y) //if c1 is less than c2, second date is later
{
  
}
*/
bool Date:: is_equal(Date&x, Date&y)
{
 if (x.GetDay() == y.GetDay && x.GetMonth == y.GetMonth && x.GetYear = y.GetYear)
 return true;
 else
 return false; 
}
put c1. or c2. in front of is_equal in your function call and it should work. is_equal is a function that's part of your class, so you can only call it using an object of that class. A better way to do it would be to only take 1 parameter, because the variables of the class that calls the function will be available in that function already(like in your get functions), so you only have to pass in one other object.
Topic archived. No new replies allowed.