#include<iostream>
using namespace std;
class Date
{
public:
Date(int y = 0, int m = 0, int d = 0)
{
year = y;
month = m;
day = d;
};
void operator=(Date &date);
void output() { cout << year << "," << month << "," << day << endl; }
friend bool operator>(Date d1, Date d2);
private:
int year, month, day;
};
void Date:: operator=(Date &date)
{
year = date.year;
month = date.month;
day = date.day;
}
bool operator>(Date d1, Date d2)
{
bool flag = false;
if (d1.year > d2.year)flag = true;
else if (d1.year == d2.year)
if (d1.month > d2.month)flag = true;
else if (d1.month == d2.month)
if (d1.day > d2.day)flag = true;
return flag;
}
void main()
{
Date date1(2017, 4, 27);
Date date2(2018, 4, 27), date3;
date3 = date1;
cout << "date3:";
date3.output();
cout << "date2>date3 is";
cout << boolalpha << (date2 > date3);
}
#include<iostream>
using namespace std;
class Point
{
public:
Point(double m, double n) { x = m; y = n; }
virtual void Area() { cout << "The area is 0" << endl; }
private:
double x, y;
};
class Circle :public Point
{
public:
Circle(double m, double n, double i) :Point(m, n) { r = i; }
void Circle::Area()
{
double a = 3.14*r*r;
cout << "The area of the circle is:" << a << endl;
}
private:
double r;
};
void main()
{
Point *pt;
Circle c(4, 5, 6);
pt = &c;
pt->Area();
}