Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <cstdlib>
- using namespace std;
- enum Months {
- January = 1,
- February,
- March,
- April,
- May,
- June,
- July,
- August,
- September,
- October,
- November,
- December,
- };
- struct DateStruct {
- unsigned int day = 0;
- unsigned int month = 0;
- unsigned int year = 0;
- };
- class Date {
- private:
- DateStruct date;
- DateStruct tempDate;
- public:
- void setDateNow() {
- cout << "Введите текущий год: ";
- cin >> date.year;
- cout << "Введите текущий месяц: ";
- cin >> date.month;
- cout << "Введите текущий день: ";
- cin >> date.day;
- }
- void afterCountDays(int countDays) {
- tempDate = date;
- if (tempDate.month != February) {
- int temp = countDays;
- if (temp > 30) {
- while (temp > 0) {
- if (temp >= 365) {
- tempDate.year++;
- temp -= 365;
- }
- else if (temp >= 30) {
- tempDate.month++;
- temp -= 30;
- if (tempDate.month > 12) {
- tempDate.month = 1;
- tempDate.year++;
- }
- }
- else {
- tempDate.day += temp;
- temp -= temp;
- }
- }
- if (tempDate.day > 30) {
- tempDate.month++;
- tempDate.day = 1;
- }
- printDate(true, countDays, tempDate);
- }
- else {
- tempDate.day += countDays;
- printDate(true, countDays, tempDate);
- }
- }
- }
- void SubtractDays(int countDays) {
- tempDate = date;
- for (int i = countDays; i > 0; i--) {
- tempDate.day--;
- if (tempDate.day == 0) {
- tempDate.day = 30;
- tempDate.month--;
- }
- if (tempDate.month == 0) {
- tempDate.month = 12;
- tempDate.year--;
- }
- }
- printDate(true, countDays, tempDate);
- }
- void leapYear() {
- if (date.year % 4 == 0) {
- cout << "Год является високосным!" << endl;
- }
- else {
- cout << "Год НЕ является високосным!" << endl;
- }
- }
- void printDate(bool afterCountDays, int countDays, DateStruct tempDate) {
- if (afterCountDays) {
- cout << "Через " << countDays << " дней от введённой даты будет(примерно): "
- << tempDate.year << ":" << tempDate.month << ":" << tempDate.day << endl;
- }
- else {
- cout << "Сейчас " << date.year << " год" << endl;
- }
- }
- };
- int main()
- {
- setlocale(LC_ALL, "rus");
- Date nowDate;
- nowDate.setDateNow();
- nowDate.afterCountDays(34);
- nowDate.SubtractDays(765);
- nowDate.leapYear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement