Write a c++ program find the which data is greater than given data ( assume the 2 data in one Singal year only, consider leap year also as an input)
A. Define a class called day with member as date , month, year
B. Define a parametized constructor to initized the data
C. Overload>opertor using member function to check if data 1>data2.
D. Write a show _data function to show the data in dd:yyyy found
#include <iostream>
#include <string>
using namespace std;
//A. Define a class called day with member as date, month, year
class Day{
private:
int date;
int month;
int year;
//B. Define a parametized constructor to initized the data
public:
Day(int date,int month,int year){
this->date=date;
this->month=month;
this->year=year;
}
//C. Overload>opertor using member function to check if data 1>data2.
bool operator>(const Day& d) {
if (this->year > d.year){
return true;
}else if (this->year == d.year){
if (this->month > d.month)
return true;
else if (this->month==d.month)
{
if (this->date>d.date){
return true;
}
}
}
return false;
}
//D. Write a show _data function to show the data in dd:yyyy found
void show_data(){
cout<<this->date<<":"<<this->year;
}
};
int main()
{
int date;
int month;
int year;
cout<<"Enter the date for day 1: ";
cin>>date;
cout<<"Enter the month for day 1: ";
cin>>month;
cout<<"Enter the year for day 1: ";
cin>>year;
Day day1(date,month,year);
cout<<"\nEnter the date for day 2: ";
cin>>date;
cout<<"Enter the month for day 2: ";
cin>>month;
cout<<"Enter the year for day 2: ";
cin>>year;
Day day2(date,month,year);
cout<<"\nDate 1: \n";
day1.show_data();
cout<<"\nDate 2: \n";
day2.show_data();
if(day1>day2){
cout<<"\nDate 1 is greater than given Date 2\n";
}else{
cout<<"\nDate 1 is not greater than given Date 2\n";
}
system("pause");
return 0;
}
Comments
Leave a comment