This repository has been archived on 2026-07-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
college-work/Задания по C и C++/с (2024)/23.cpp
T

86 lines
2.8 KiB
C++

#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <winbgim.h> // Äëÿ ðàáîòû ñ ãðàôèêîé
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;
}