C++ Saved Program: fragrant-palace

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include<iostream>
using namespace std;

class Date
{
	int d;
	int m;
	int y;
	public:
		void getdata(int a,int b,int c)
		{
			d=a;
			m=b;
			y=c;
		}
		int valid();
};

int Date:: valid()
{
	if (m==1||m==3||m==5||m==7||m==8||m==10||m==12)
	{
		if(d<=31)
		{
			cout<<"it is a valid date\n";
		}
		else
		{
			cout<<"it is not a valid date\n";
		}
		
	}
	if(m==4||m==6||m==9||m==11)
	{
		if(d<=30)
		{
			cout<<"it is valid date\n";
		}
		else
		{
			cout<<"it is not a valid date\n"; 
		}
	}
	if (m==2)
	{
		if(y%400==0)
		{
			if(y%4==0)
			{
				if(d<=29)
				{
					cout<<"it is a valid date\n";
				}
				else
				{
					cout<<"it is not a valid date\n";
				}
			}
			else
			{
				if(d<=28)
				{
					cout<<"it is a valid date\n";
				}
				else
				{
					cout<<"it is not a valid date\n";
				}
			}
		}
	}
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs