Вопрос задан 14.01.2020 в 21:09. Предмет Информатика. Спрашивает Платонова Виктория.

Teacher’s day is celebrated each year on the first Sunday of the October. Given natural number n,

that represents the number of the year. Output the date of the Teacher’s day of that year. Example:Input:2010Output3с++​
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Ананьев Иван.

Ответ:

#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

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

To determine the date of Teacher's Day for a given year, we need to find the first Sunday of October for that year. Here's how you can calculate it in C++:

```cpp #include #include #include

int main() { int year; std::cout << "Enter the year: "; std::cin >> year;

// Create a date object for October 1st of the given year std::chrono::year_month_day date{std::chrono::year{year}, std::chrono::month{10}, std::chrono::day{1}};

// Find the weekday of October 1st std::chrono::weekday weekday{date};

// Calculate the number of days to the first Sunday int days_to_sunday = (std::chrono::Sunday - weekday).count();

// Add the number of days to October 1st to get the date of the first Sunday of October std::chrono::year_month_day teacher_day_date = date + std::chrono::days{days_to_sunday};

// Output the date of Teacher's Day std::cout << "Teacher's Day in " << year << " is on " << teacher_day_date << std::endl;

return 0; } ```

This program uses the `` library in C++ to perform date calculations. It takes a natural number as input, representing the year, and outputs the date of Teacher's Day for that year.

Please note that the program assumes the first Sunday of October as the date for Teacher's Day. This may vary depending on the country or region.

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос