Answer to Question #181255 in C++ for Deepanshi singh

Question #181255

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


1
Expert's answer
2021-04-15T06:23:41-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS