Mon Nov 11 2019

Leap Year Using Class Object

File Name: leap-year-using-class-object.cpp

/* 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! */
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.