Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int newdays;
- struct time
- {
- long year;
- int month;
- int day;
- time()
- {
- year = 0;
- month = 0;
- day = 0;
- }
- };
- int newday()
- {
- cout << "Введите количество дней " << endl;
- cin >> newdays;
- return newdays;
- }
- void positive(time first, int result_newday)
- {
- while (result_newday--) {
- first.day++;
- switch (first.month) {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12: {
- if (first.day > 31) {
- first.month++;
- first.day -= 31;
- }
- break;
- }
- case 2: {
- if (first.year % 4 == 0) {
- if (first.year % 100 == 0) {
- if (first.year % 400 == 0) {
- if (first.day > 29) {
- first.month++;
- first.day -= 29;
- }
- }
- else if (first.day > 28) {
- first.month++;
- first.day -= 28;
- }
- }
- else if (first.day > 29) {
- first.month++;
- first.day -= 29;
- }
- }
- else if (first.day > 28) {
- first.month++;
- first.day -= 28;
- }
- break;
- }
- case 4:
- case 6:
- case 9:
- case 11: {
- if (first.day > 30) {
- first.month++;
- first.day -= 30;
- }
- break;
- }
- default:
- break;
- }
- while (first.month > 12) {
- first.month -= 12;
- first.year++;
- }
- }
- cout << "Новая дата: " << first.day << '.' << first.month << '.' << first.year << endl;
- }
- int negative(time first, int result_newday) {
- while (result_newday++) {
- first.day--;
- switch (first.month) {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12: {
- if (first.day < 31) {
- first.month--;
- first.day += 31;
- }
- break;
- }
- case 2: {
- if (first.year % 4 == 0) {
- if (first.year % 100 == 0) {
- if (first.year % 400 == 0) {
- if (first.day < 29) {
- first.month--;
- first.day += 29;
- }
- }
- else if (first.day < 28) {
- first.month--;
- first.day += 28;
- }
- }
- else if (first.day < 29) {
- first.month--;
- first.day += 29;
- }
- }
- else if (first.day < 28) {
- first.month--;
- first.day += 28;
- }
- break;
- }
- case 4:
- case 6:
- case 9:
- case 11: {
- if (first.day < 30) {
- first.month--;
- first.day += 30;
- }
- break;
- }
- default:
- break;
- }
- while (first.month < 1) {
- first.month += 12;
- first.year--;
- }
- if (first.year < 0) {
- cout << "Калькулятор работает только в пределах нашей эры!" << endl;
- return 0;
- }
- cout << "Новая дата: " << first.day << '.' << first.month << '.' << first.year << endl;
- }
- return 0;
- }
- void calculator(time first) {
- cout << "Введите изначальную дату(день, месяц, год): " << endl;
- cin >> first.day;
- cin >> first.month;
- cin >> first.year;
- cout << "Изначальная дата: " << first.day << "." << first.month << "." << first.year << endl;
- int result_newday = newday();
- if (result_newday>0)
- positive(first, result_newday);
- else
- negative(first, result_newday);
- }
- int main()
- {
- setlocale(0, "rus");
- time first;
- calculator(first);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement