#include #include #include #include #include // Для работы с графикой int main() { // Инициализация графического режима int gd = DETECT, gm; initgraph(&gd, &gm, ""); // Данные задачи float initial_volume = 6.0; // Начальный объем float factor = 1.6; // Коэффициент увеличения объема // Новый объем и объем детали float new_volume = initial_volume * factor; float detail_volume = new_volume - initial_volume; // Параметры для отрисовки сосуда int x_center = getmaxx() / 2; int y_bottom = getmaxy() / 2 + 100; // Отрисовка сосуда rectangle(x_center - 50, y_bottom - 200, x_center + 50, y_bottom); setfillstyle(SOLID_FILL, LIGHTBLUE); // Расчет высоты начального уровня воды int initial_water_height = 200 * (initial_volume / new_volume); bar(x_center - 50, y_bottom - initial_water_height, x_center + 50, y_bottom); // Заполнение водой setfillstyle(SOLID_FILL, BLUE); bar(x_center - 50, y_bottom - 200, x_center + 50, y_bottom); // Подписи к уровням воды outtextxy(x_center - 30, y_bottom + 10, "Сосуд"); outtextxy(x_center - 30, y_bottom - initial_water_height - 20, "Уровень 6 куб. см"); outtextxy(x_center - 30, y_bottom - 220, "Уровень 9.6 куб. см"); // Вывод текста на экран (объем детали) в левом верхнем углу setcolor(WHITE); outtextxy(10, 10, "Объем детали = 3.6 куб. см"); // Формирование полного текста решения и ответа char solutionText[500]; sprintf(solutionText, "Решение задачи:\n" "Начальный объем воды: %.2f куб. см\n" "Новый объем воды: %.2f куб. см\n" "Объем детали: %.2f куб. см", initial_volume, new_volume, detail_volume); // Вывод решения в правом верхнем углу int screen_width = getmaxx(); int line_height = 15; int y_offset = 10; char *line = strtok(solutionText, "\n"); while (line != NULL) { outtextxy(screen_width - 300, y_offset, line); y_offset += line_height; line = strtok(NULL, "\n"); } // Запись решения в файл "Ответ.txt" FILE *file = fopen("Ответ.txt", "w"); if (file == NULL) { printf("Ошибка при открытии файла!\n"); return 1; } fprintf(file, "Решение задачи:\n"); fprintf(file, "Начальный объем воды = %.2f куб. см\n", initial_volume); fprintf(file, "Новый объем воды после погружения детали = %.2f куб. см\n", new_volume); fprintf(file, "Объем детали = %.2f куб. см\n", detail_volume); fclose(file); printf("Ответ записан в файл 'Ответ.txt'.\n"); // Ожидание ввода для закрытия графического окна getch(); closegraph(); return 0; }