PHP:
#include<iostream>
using namespace std;
class DateType {
private:
int day;
int month;
int year;
public:
DateType::DateType(int day=1, int M=1, int year = 1900);
void printDate( );
bool operator<(const DateType&);
friend bool operator==(const DateType&,const DateType);
int main()
{
bool DateType::operator<(const DateType&x);
{
if(year<x.year)
return true;
if(year==x.year&&month<x.month)
return true;
if(year==x.year&&month==x.month&&day<x.day)
return true;
return false;
}
bool operator==(const DateType&x,const DateType&y)
{
return (x.day==y.day&&m.month==y.month&&x.year==y.year);
}
cout<<"D1="<<d1.printDate();
if(D1<D2)
cout<<"is before D2";
else
if(D1==D2)
cout<<"is equal D2";
else
cout<<"is after D2";
}
}
يطلع لي ايرور واحد ماادري في شنو
ساعدوني ابغي ضروري اليوم
ده السؤال
Consider the class definition below:
class DateType {
private:
int day; // value must be between 1 - 31
int month; //value must be between 1 - 12
int year; //value must be between 1900 - 2020
public:
DateType(int day=1, int M=1, int year = 1900);
void printDate( ); //prints the date in day/month/year format
….. // The function defined in part (a)
….. // The function defined in part (b)
};
For each function in part (a) and (b), write the function prototype (in the space above in the class definition) and the function implementation.
a. Overload the operator < (less than) as a member function of the class, so that the function will return true if the date of the first object comes before the date of the second object.
b. Overload the == (equal) operator as a non-member function of the class.
c. Write a main function to do the following:
- Write a statement to declare an object name D1 of type DateType with the values (12,12,1998).
- Write a statement to declare an object name D2 of type DateType with the values (30,12,2000).
- Write statements to compare between D1 and D2 to print one of the following messages as appropriate:
o D1 = day/month/year is before D2= day/month/year
o D1 = day/month/year is the same as D2= day/month/year
o D1 = day/month/year is after D2= day/month/year