leap year calculator using class

Leap year calculator while practicing class. I get an error at display portion

1. Create a class named Date
2. Class has 3 private data items (name the data items month, day, year)
a. int month
b. int day
c. int year
3. Member functions
a. ‘getters’ a getter for each data item
i. Use ‘get’ and the data items name
ii. Return the data item
iii. int getMonth() {return month;}
b. ‘setters’ a setter for each data item
i. Use ‘set’ and the data items name
ii. Change the data items value
iii. Void setMonth(int x) {month = x;}
c. bool calcLeapYear()
i. uses the month, day, and year and determines if the year is a leap year
ii. calc
1. year evenly divisible by 400 is a leap year
2. year evenly divisible by 100 is not a leap year
3. year divisible by 4 is a leap year
4. else is not a leap year
d. display()
i. blank line
ii. month is mm
iii. day is dd
iv. year is yyyy
v. yyyy is (not) a leap year
4. in main, test your class and the member functions


here's what I got
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

#include <iostream>
using namespace std;

/****************************************
*     class definitions
****************************************/
class Date
{
    private:
       int  month;
       int  day;
       int  year;
  
    public:
       // setters
        void setMonth(int m) {month = m;}
        void setDay(int d) {day = d;}
        void setYear(int y) {year = y;}
        
        // getter
        int getMonth() {return month;}
        int getDay() {return day;}
        int getYear() {return year;}
        
       // 'member' functions 
        bool calcLeapYear(); 
        void display();
                 
};
/****************************************
*     member functions for above class
****************************************/
bool Date::calcLeapYear()
{

    if(year % 400 == 0)
    {
        return true;       
    }
    if(year % 100 == 0) 
    {
        return false;
    }
    if(year % 4 == 0) 
    {
        return true;
    }
    return false;
}

Date::void display() //getting error here why?
{
    cout << endl;
    cout << "The month is " << setMonth() << endl;
    cout << "The day is " << setDay() << endl;
    cout << "The year is " << setYear() << endl;
    
    bool calcLeapYear(getYear());
    if (calcLeapYear == true) 
    {
        cout << getYear() << "is a leap year" << endl;
    }
    else 
    {
        cout << getYear() << "is not a leap year" << endl;
    }
}

/*************************************
*     function prototype
*************************************/

void dateTesting01();
void dateTesting02();
/************************************
*      global variables
*************************************/

int main()
{
    void dateTesting01(); //function call
    void dateTesting02();

}

/************************************
*      non-member functions
*************************************/


 void dateTesting01()
{
    cout << "*** test 01 ***\n"; 

        Date isLeapYear;
    int testMonth, testDay, testYear;
    cout << "Enter the month: " << endl;
    cin >> testMonth;
    cout << "Enter the day: " << endl;
    cin >> testDay;
    cout << "Enter the year: " << endl;
    cin >> testYear;
    
    isLeapYear.setMonth(testMonth);
    isLeapYear.setDay(testDay);
    isLeapYear.setYear(testYear);
    isLeapYear.display();
    cout << endl;
    
}    

 void dateTesting02()
{
     cout << "*** test 02 ***\n";
     
     Date d1;
    d1.setMonth(12);
    d1.setDay(1);
    d1.setYear(1994);
    d1.display();
	
//test
    d1.setYear(1900); // false
    d1.display(); 
    d1.setYear(2000); //true
    d1.display();
    d1.setYear(1995); //false
    d1.display();
    d1.setYear(1996); //true
    d1.display();
        

}
Last edited on
That error line, I thnk it should be void Date::display()
right! duh, thanks.
Last edited on
I also changed the print to this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
    cout << endl;
    cout << "The month is " << month << endl;
    cout << "The day is " << day << endl;
    cout << "The year is " << year << endl;
    
    bool calcLeapYear(year);
    if (calcLeapYear == true) 
    {
        cout << year << "is a leap year" << endl;
    }
    else 
    {
        cout << year << "is not a leap year" << endl;
    }

Now it complies, but when I run it closes right away.
Topic archived. No new replies allowed.