Class Object
C++ Programming ⚭ Jun 6, 2016 ⚭ 2464 views
/* Leap year */
#include<iostream>
using namespace std;
class leapYear {
public:
/* Public function defined inside class */
void isLeapYear(int yr) {
if(yr % 4 == 0 || yr % 400 == 0)
cout << "It's a Leap Year!" << endl;
else
cout << "It's not a Leap Year!" << endl;
}
};
int main() {
int year;
/* Create object 'x' of class 'leapYear' */
leapYear x;
cout << "Program to find Leap Year" << endl;
cout << "Enter a year:" << endl;
cin >> year;
/* Call member function 'isLeapYear()' */
x.isLeapYear(year);
return 0;
}
/* Output */
Program to find Leap Year
Enter a year:
2000
It's a Leap Year!
/* ---------------------------- */
Program to find Leap Year
Enter a year:
2014
It's not a Leap Year!
Learn more about Classes in C++