C++ Programming

Leap Year Using Class Object

C plus plus example for leap year using class object

11/11/2019
0 views
leap-year-using-class-object.cppCPP
/* 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! */
cppc plus plusclass objectleap year

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com