Добавил:
Diryabuh
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
#include <stdio.h>
#include <conio.h>
class Date
{
public:
// Constructors
Date() { Set(1,1,0); };
Date(short dd, short mm, short yy) { Set(dd, mm, yy); };
Date(Date &src) { Set(src.day, src.month, src.year); };
// Methods
short GetDay() {return day;};
short GetMonth() {return month;};
short GetYear() {return year;};
// Operations
void Set(short dd, short mm, short yy);
// Operators
inline short operator==(const Date& a) const { return (day==a.day && month==a.month && year==a.year); }
friend void Input(Date &a);
friend void Print(Date &a);
private:
short day;
short month;
short year;
};
void Date::Set(short dd, short mm, short yy)
{
day = dd;
month = mm;
year = yy;
}
void Input(Date &a)
{
short d = 0, m = 0, y = 0;
scanf("%d %d %d", &d, &m, &y);
if (d > 31)
d = 31;
if (m > 12)
m = 12;
a.Set(d, m, y);
}
void Print(Date &a)
{
printf("Date: %d %d %d\n", a.day, a.month, a.year);
}
void main(void)
{
Date f1 = Date();
Date f2(2, 10, 98);
Date f3(f2);
Print(f1);
Print(f2);
Print(f3);
printf("Enter new value for Date 3: ");
Input(f3);
Print(f3);
if (f3 == f1)
printf("Date 3 is equal to Date 1!\n");
else if (f3 == f2)
printf("Date 3 is equal to Date 2!\n");
getch();
}
