Ответ:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
int y;
char buffer[80];
cout << "Year = ";
cin >> y;
tm time_in;
time_in.tm_sec = 0; // second
time_in.tm_min = 0; // minute
time_in.tm_hour = 0; // hour
time_in.tm_mday = 1; // 1-based day
time_in.tm_mon = 9; // 0-based month
time_in.tm_year = y - 1900; // year since 1900
time_t time_temp = mktime (&time_in); // Convert the local time to a calendar value.
tm* time_out = localtime (&time_temp); // Converts a time_t time value to a tm structure
if (time_out->tm_wday > 0) // if it is not Sunday, go to the next Sunday
time_out->tm_mday += 7 - time_out->tm_wday;
strftime(buffer, 80, "%d.%m.%Y", time_out); // date formatting for output
cout << "\nTeachers day is " << buffer << "\n";
}
Объяснение: explanations in the comments to the program
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
Ответ:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
int y;
char buffer[80];
cout << "Year = ";
cin >> y;
tm time_in;
time_in.tm_sec = 0; // second
time_in.tm_min = 0; // minute
time_in.tm_hour = 0; // hour
time_in.tm_mday = 1; // 1-based day
time_in.tm_mon = 9; // 0-based month
time_in.tm_year = y - 1900; // year since 1900
time_t time_temp = mktime (&time_in); // Convert the local time to a calendar value.
tm* time_out = localtime (&time_temp); // Converts a time_t time value to a tm structure
if (time_out->tm_wday > 0) // if it is not Sunday, go to the next Sunday
time_out->tm_mday += 7 - time_out->tm_wday;
strftime(buffer, 80, "%d.%m.%Y", time_out); // date formatting for output
cout << "\nTeachers day is " << buffer << "\n";
}
Объяснение: explanations in the comments to the program