Добавил:
vvrstcnho
Рад, если кому-то помог
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторные работы С++ (для ИВТ) / Готовые лабы С++ / Лаба4 / Laba 4 (13)
.cpp#include <iostream>
#include <locale>
#include <string>
using namespace std;
class Date {
int day, month, year;
string getMonthName() const {
const string months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
return months[month - 1];
}
public:
Date(int d = 1, int m = 1, int y = 2000) : day(d), month(m), year(y) {}
// Оператор вывода
friend ostream& operator<<(ostream& os, const Date& d);
// Оператор ввода
friend istream& operator>>(istream& is, Date& d);
};
ostream& operator<<(ostream& os, const Date& d) {
os << (d.day < 10 ? "0" : "") << d.day << " "
<< d.getMonthName() << " " << d.year;
return os;
}
istream& operator>>(istream& is, Date& d) {
is >> d.day >> d.month >> d.year;
return is;
}
int main() {
setlocale(LC_ALL, "ru_RU.UTF-8");
Date d1(1, 1, 2023);
cout << "Дата 1: " << d1 << endl;
cout << "Введите дату (день месяц год): ";
Date d2;
cin >> d2;
cout << "Вы ввели: " << d2 << endl;
return 0;
}
Соседние файлы в папке Лаба4
