Работы по программированию

This commit is contained in:
IgorVolochay
2026-07-28 09:56:54 +03:00
parent b85155ff95
commit 8602b7e845
73 changed files with 4090 additions and 0 deletions
@@ -0,0 +1,108 @@
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#include <winbgim.h>
int main() {
// Êîîðäèíàòû òî÷åê A(-6, 4), B(-2, -2), C(-1, -4), D(2, 3)
int ax = -6, ay = 4, bx = -2, by = -2;
int cx = -1, cy = -4, dx = 2, dy = 3;
// Âåêòîð a ñ êîîðäèíàòàìè (B-A) è âåêòîð b ñ êîîðäèíàòàìè (D-C)
int vecA_x = bx - ax;
int vecA_y = by - ay;
int vecB_x = dx - cx;
int vecB_y = dy - cy;
// Óìíîæàåì âåêòîð a íà 2
int vec2A_x = 2 * vecA_x;
int vec2A_y = 2 * vecA_y;
// Ñêàëÿðíîå ïðîèçâåäåíèå
int scalarProduct = vec2A_x * vecB_x + vec2A_y * vecB_y;
// Îòêðûâàåì ôàéë äëÿ çàïèñè
FILE *file = fopen("Îòâåò.txt", "w");
if (file != NULL) {
fprintf(file, "Solution to the scalar product task:\n");
fprintf(file, "Vector A: (%d, %d)\n", ax, ay);
fprintf(file, "Vector B: (%d, %d)\n", bx, by);
fprintf(file, "Vector C: (%d, %d)\n", cx, cy);
fprintf(file, "Vector D: (%d, %d)\n", dx, dy);
fprintf(file, "Scalar product of 2a and b: %d\n", scalarProduct);
fclose(file); // Çàêðûâàåì ôàéë
} else {
printf("Error opening file!\n");
}
// Èíèöèàëèçàöèÿ ãðàôèêè
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
// Ìàñøòàáèðîâàíèå
int scale = 30; // Øàã ñåòêè
// Ñìåùàåì íà÷àëî êîîðäèíàò â áëèæàéøóþ êëåòî÷êó
int origin_x = (getmaxx() / 2) / scale * scale; // Áëèæàéøàÿ êëåòêà ïî x
int origin_y = (getmaxy() / 2) / scale * scale; // Áëèæàéøàÿ êëåòêà ïî y
// Ðèñóåì êëåòî÷íóþ ñåòêó
setcolor(12); // Öâåò äëÿ ñåòêè
for (int i = 0; i < getmaxx(); i += scale) {
line(i, 0, i, getmaxy()); // Âåðòèêàëüíûå ëèíèè
}
for (int i = 0; i < getmaxy(); i += scale) {
line(0, i, getmaxx(), i); // Ãîðèçîíòàëüíûå ëèíèè
}
// Ðèñóåì îñè êîîðäèíàò, ñìåùåííûå ê áëèæàéøåé êëåòêå
setcolor(5);
line(0, origin_y, getmaxx(), origin_y); // Îñü X
line(origin_x, 0, origin_x, getmaxy()); // Îñü Y
// Ðèñóåì âåêòîð AB èç òî÷êè A
setcolor(RED); // Öâåò äëÿ âåêòîðà AB
line(origin_x + ax * scale, origin_y - ay * scale,
origin_x + bx * scale, origin_y - by * scale);
// Ðèñóåì âåêòîð CD èç òî÷êè C
setcolor(BLUE); // Öâåò äëÿ âåêòîðà CD
line(origin_x + cx * scale, origin_y - cy * scale,
origin_x + dx * scale, origin_y - dy * scale);
// Ïîäïèñè òî÷åê A, B, C, D (êàê íà ïðèìåðå)
setcolor(WHITE); // Âåðíóòü áåëûé öâåò äëÿ ïîäïèñåé
outtextxy(origin_x + ax * scale - 20, origin_y - ay * scale, "A");
outtextxy(origin_x + bx * scale + 10, origin_y - by * scale + 5, "B");
outtextxy(origin_x + cx * scale - 20, origin_y - cy * scale, "C");
outtextxy(origin_x + dx * scale + 10, origin_y - dy * scale + 5, "D");
// Ôîðìèðóåì ïîëíîå ðåøåíèå â âèäå òåêñòà
char solutionText[500];
sprintf(solutionText, "Ðåøåíèå:\n"
"A(%d, %d), B(%d, %d)\n"
"C(%d, %d), D(%d, %d)\n"
"2a = (2*(%d, %d))\n"
"b = (%d, %d)\n"
"Îòâåò = %d",
ax, ay, bx, by, cx, cy, dx, dy,
vecA_x, vecA_y, vecB_x, vecB_y, scalarProduct);
// Âûâîä ðåøåíèÿ â ïðàâîì âåðõíåì óãëó
int screen_width = getmaxx(); // Ïîëó÷àåì øèðèíó ýêðàíà
int line_height = 15; // Âûñîòà ñòðîêè
int y_offset = 10; // Íà÷àëüíàÿ ïîçèöèÿ ïî Y
char *line = strtok(solutionText, "\n");
while (line != NULL) {
outtextxy(screen_width - 300, y_offset, line); // Âûâîäèì ñòðîêó
y_offset += line_height; // Ñìåùàåìñÿ ïî Y
line = strtok(NULL, "\n");
}
// Îæèäàíèå íàæàòèÿ êëàâèøè
getch();
closegraph();
return 0;
}
@@ -0,0 +1,85 @@
#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;
}
Binary file not shown.
@@ -0,0 +1,113 @@
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <winbgim.h> // Äëÿ ðàáîòû ñ ãðàôèêîé íà Windows
int main() {
// Èíèöèàëèçàöèÿ ãðàôè÷åñêîãî ðåæèìà
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
// Äàííûå çàäà÷è
int angle_ACB = 33; // Óãîë ACB
int arc_AB = 102; // Ãðàäóñíàÿ ìåðà äóãè AB
int angle_DAE = arc_AB / 2; // Óãîë DAE = ïîëîâèíà äóãè AB
// Öåíòð îêðóæíîñòè è ðàäèóñ
int x_center = getmaxx() / 2;
int y_center = getmaxy() / 2;
int radius = 150;
// Îòðèñîâêà îêðóæíîñòè
circle(x_center, y_center, radius);
// Êîîðäèíàòû òî÷åê A, B, C, D
int x_A = x_center;
int y_A = y_center + radius;
int x_B = x_center - radius * cos(M_PI / 10);
int y_B = y_center - radius * sin(M_PI / -1);
int x_C = x_center + radius * 1.5;
int y_C = y_center - radius * 1.5;
int x_D = x_center + radius * cos(M_PI / 3);
int y_D = y_center - radius * sin(M_PI / 3);
// Òåïåðü ðàññ÷èòûâàåì êîîðäèíàòû E, êîòîðàÿ äîëæíà ëåæàòü íà ëèíèè AC
// Èñïîëüçóåì ëèíåéíóþ èíòåðïîëÿöèþ äëÿ íàõîæäåíèÿ êîîðäèíàò E
float ratio = 0.6; // Ïóñòü E áóäåò íà ñåðåäèíå îòðåçêà AC
int x_E = x_A + ratio * (x_C - x_A); // Êîîðäèíàòà X
int y_E = y_A + ratio * (y_C - y_A); // Êîîðäèíàòà Y
// Îòðèñîâêà òî÷åê A, B, C, D, E
setcolor(WHITE);
circle(x_A, y_A, 5);
outtextxy(x_A - 20, y_A + 10, "A");
circle(x_B, y_B, 5);
outtextxy(x_B - 20, y_B - 20, "B");
circle(x_C, y_C, 5);
outtextxy(x_C + 10, y_C - 20, "C");
circle(x_D, y_D, 5);
outtextxy(x_D + 10, y_D - 20, "D");
circle(x_E, y_E, 5);
outtextxy(x_E - 20, y_E + -5, "E");
// Îòðèñîâêà ëèíèé ìåæäó òî÷êàìè
line(x_B, y_B, x_C, y_C); // Ëèíèÿ BC
line(x_D, y_D, x_C, y_C); // Ëèíèÿ DC
line(x_A, y_A, x_D, y_D); // Ëèíèÿ AD
line(x_A, y_A, x_E, y_E); // Ëèíèÿ AE
line(x_D, y_D, x_B, y_B); // Ëèíèÿ DB
// Íîâàÿ ëèíèÿ: ñîåäèíåíèå E, A è C
line(x_E, y_E, x_A, y_A); // Ëèíèÿ îò E ê A
line(x_A, y_A, x_C, y_C); // Ëèíèÿ îò A ê C
// Ïåðåíîñ òåêñòà ðåøåíèÿ â ëåâûé âåðõíèé óãîë
char solutionText[500];
sprintf(solutionText, "Ðåøåíèå çàäà÷è:\n"
"Óãîë ACB = %d ãðàäóñîâ\n"
"Ãðàäóñíàÿ ìåðà äóãè AB = %d ãðàäóñîâ\n"
"Óãîë DAE = %d ãðàäóñîâ",
angle_ACB, arc_AB, angle_DAE);
// Âûâîä ðåøåíèÿ â ëåâîì âåðõíåì óãëó
int screen_width = getmaxx();
int line_height = 15;
int y_offset = 10;
char *line = strtok(solutionText, "\n");
while (line != NULL) {
outtextxy(10, 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, "Óãîë ACB = %d ãðàäóñîâ\n", angle_ACB);
fprintf(file, "Ãðàäóñíàÿ ìåðà äóãè AB = %d ãðàäóñîâ\n", arc_AB);
fprintf(file, "Óãîë DAE = %d ãðàäóñîâ\n", angle_DAE);
fclose(file);
printf("Îòâåò çàïèñàí â ôàéë 'Îòâåò.txt'.\n");
// Îæèäàíèå ââîäà äëÿ çàêðûòèÿ ãðàôè÷åñêîãî îêíà
getch();
closegraph();
return 0;
}
Binary file not shown.
@@ -0,0 +1,125 @@
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <winbgim.h> // Äëÿ ðàáîòû ñ ãðàôèêîé íà Windows
// Ôóíêöèÿ äëÿ ðàñ÷åòà çíà÷åíèÿ y = (x + 4)^2(x + 3) - 6
double func(double x) {
return pow((x + 4), 2) * (x + 3) - 6;
}
int main() {
// Èíèöèàëèçàöèÿ ãðàôè÷åñêîãî ðåæèìà
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
// Óñëîâèå çàäà÷è
setcolor(WHITE);
outtextxy(10, 10, "Íàéäèòå íàèáîëüøåå çíà÷åíèå ôóíêöèè y = (x+4)^2(x+3) - 6");
outtextxy(10, 30, "íà îòðåçêå [-5, -3.5].");
// Íàéäåì çíà÷åíèÿ ôóíêöèè â ãðàíè÷íûõ òî÷êàõ è êðèòè÷åñêèõ òî÷êàõ
double x1 = -5, x2 = -3.5;
double x_critical1 = -4, x_critical2 = -10.0 / 3.0;
double y1 = func(x1);
double y2 = func(x2);
double y_critical1 = func(x_critical1);
double y_critical2 = func(x_critical2);
// Íàéäåì íàèáîëüøåå çíà÷åíèå
double max_value = y1;
double max_x = x1;
if (y2 > max_value) {
max_value = y2;
max_x = x2;
}
if (y_critical1 > max_value) {
max_value = y_critical1;
max_x = x_critical1;
}
if (y_critical2 > max_value) {
max_value = y_critical2;
max_x = x_critical2;
}
// Âûâîä ðåøåíèÿ íà ýêðàí
char solutionText[500];
sprintf(solutionText, "Íàèáîëüøåå çíà÷åíèå ôóíêöèè = %.2f ïðè x = %.2f", max_value, max_x);
outtextxy(10, 50, solutionText);
// Ïîñòðîåíèå ãðàôèêà ôóíêöèè íà èíòåðâàëå [-5, -3.5]
setcolor(YELLOW);
// Íàéäåì ðàçìåðû ãðàôè÷åñêîãî îêíà
int width = getmaxx();
int height = getmaxy();
int graph_x_start = 50; // Ëåâûé êðàé ãðàôèêà
int graph_y_start = height / 2; // Ñðåäíÿÿ ëèíèÿ äëÿ îñè y
int graph_width = width - 100; // Øèðèíà ãðàôèêà
// Óñòàíîâèì ìàñøòàá ïî îñè X è Y
double x_scale = graph_width / (x2 - x1); // Ìàñøòàá ïî X
double y_scale = 30; // Ìàñøòàá ïî Y (çàâèñèò îò ôóíêöèè)
// Îòîáðàæàåì îñè
setcolor(WHITE);
line(graph_x_start, 0, graph_x_start, height); // Îñü Y
line(0, graph_y_start, width, graph_y_start); // Îñü X
// Ðàçìåòêà (ñåòêà)
setcolor(LIGHTGRAY);
// Ãîðèçîíòàëüíûå ëèíèè (ïî Y)
for (int i = -5; i <= 5; i++) {
int y_line_pos = graph_y_start - i * y_scale;
line(0, y_line_pos, width, y_line_pos);
char label[10];
sprintf(label, "%d", i);
outtextxy(graph_x_start - 30, y_line_pos - 5, label);
}
// Âåðòèêàëüíûå ëèíèè (ïî X)
for (double i = x1; i <= x2; i += 0.5) {
int x_line_pos = graph_x_start + (int)((i - x1) * x_scale);
line(x_line_pos, 0, x_line_pos, height);
char label[10];
sprintf(label, "%.1f", i);
outtextxy(x_line_pos - 10, graph_y_start + 10, label);
}
// Îòðèñîâêà ôóíêöèè
setcolor(YELLOW);
for (int i = graph_x_start; i < graph_x_start + graph_width; i++) {
double x = x1 + (i - graph_x_start) / x_scale;
double y = func(x);
int graph_y = graph_y_start - (int)(y * y_scale);
putpixel(i, graph_y, YELLOW);
}
// Îòìå÷àåì òî÷êó ìàêñèìóìà
int max_graph_x = graph_x_start + (int)((max_x - x1) * x_scale);
int max_graph_y = graph_y_start - (int)(max_value * y_scale);
setcolor(RED);
circle(max_graph_x, max_graph_y, 5);
outtextxy(max_graph_x + 10, max_graph_y - 10, "Max");
// Çàïèñü ðåøåíèÿ â ôàéë
FILE *file = fopen("Ðåøåíèå_çàäà÷è.txt", "w");
if (file == NULL) {
printf("Îøèáêà ïðè îòêðûòèè ôàéëà!\n");
return 1;
}
fprintf(file, "Íàèáîëüøåå çíà÷åíèå ôóíêöèè íà îòðåçêå [-5, -3.5]:\n");
fprintf(file, "Ìàêñèìóì = %.2f ïðè x = %.2f\n", max_value, max_x);
fclose(file);
printf("Îòâåò çàïèñàí â ôàéë 'Ðåøåíèå_çàäà÷è.txt'.\n");
// Îæèäàíèå ââîäà äëÿ çàêðûòèÿ ãðàôè÷åñêîãî îêíà
getch();
closegraph();
return 0;
}
Binary file not shown.
@@ -0,0 +1,95 @@
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
// Функция для вычисления левой части уравнения: 4√3 * cos^3(x)
double left_side(double x) {
return 4 * sqrt(3) * pow(cos(x), 3);
}
// Функция для вычисления правой части уравнения: cos(2x + π/2)
double right_side(double x) {
return cos(2 * x + M_PI / 2);
}
int main() {
// Инициализация графического режима
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
// Заданный отрезок [-4π; -5π/2]
double x_start = -4 * M_PI;
double x_end = -5 * M_PI / 2;
// Массив для хранения корней
double roots[10];
int root_count = 0;
// Поиск корней уравнения на заданном отрезке с шагом 0.01
for (double x = x_start; x <= x_end; x += 0.01) {
double left = left_side(x);
double right = right_side(x);
// Проверяем условие совпадения левой и правой частей уравнения с некоторой погрешностью
if (fabs(left - right) < 0.01) {
roots[root_count] = x;
root_count++;
}
}
// Координаты для рисования графиков
int x_center = getmaxx() / 2;
int y_center = getmaxy() / 2;
// Рисуем оси
line(0, y_center, getmaxx(), y_center); // Ось X
line(x_center, 0, x_center, getmaxy()); // Ось Y
// Подписи для осей
outtextxy(x_center + 5, 5, "Y");
outtextxy(getmaxx() - 10, y_center + 5, "X");
// Рисуем графики левой и правой частей уравнения
for (double x = x_start; x <= x_end; x += 0.01) {
double left = left_side(x);
double right = right_side(x);
// Левую часть уравнения рисуем белым
putpixel(x_center + (int)(x * 100), y_center - (int)(left * 100), WHITE);
// Правую часть уравнения рисуем желтым
putpixel(x_center + (int)(x * 100), y_center - (int)(right * 100), YELLOW);
}
// Вывод текста с найденными корнями
setcolor(WHITE);
char root_text[100];
sprintf(root_text, "Найдено %d корней", root_count);
outtextxy(10, 10, root_text);
// Запись корней в файл
FILE *file = fopen("answer.txt", "w");
if (file == NULL) {
printf("Ошибка при открытии файла!\n");
return 1;
}
// Запись найденных корней в файл
fprintf(file, "Ответ задачи:\n");
fprintf(file, "Найдено %d корней:\n", root_count);
for (int i = 0; i < root_count; i++) {
fprintf(file, "x = %.5f\n", roots[i]);
}
// Закрытие файла
fclose(file);
printf("Ответ записан в файл 'answer.txt'.\n");
// Ожидание завершения
getch();
closegraph();
return 0;
}
@@ -0,0 +1,40 @@
#include <stdio.h>
int main() {
FILE *initialFile = fopen("1 input.txt", "w");
if (initialFile == NULL) {
printf("Не удалось создать файл 1 input.txt\n");
return 1;
}
fprintf(initialFile, "5 6 1 10 24\n");
fclose(initialFile);
FILE *inputFile = fopen("1 input.txt", "r");
if (inputFile == NULL) {
printf("Не удалось открыть файл 1 input.txt\n");
return 1;
}
FILE *outputFile = fopen("1 output.txt", "w");
if (outputFile == NULL) {
printf("Не удалось открыть файл 1 output.txt\n");
fclose(inputFile);
return 1;
}
float a, b, c, d, e;
fscanf(inputFile, "%f %f %f %f %f", &a, &b, &c, &d, &e);
fclose(inputFile);
float result = ((a / b) + (c / d)) * e;
fprintf(outputFile, "%.2f\n", result);
fclose(outputFile);
printf("output.txt\n");
return 0;
}
@@ -0,0 +1,38 @@
#include <graphics.h>
#include <iostream>
#include <fstream>
#include <vector>
void drawBarChart(const std::vector<int>& temperatures) {
int x = 50;
for (int temp : temperatures) {
bar(x, 400 - temp * 2, x + 30, 400);
x += 40;
}
}
std::vector<int> readTemperatures(const std::string& filename) {
std::ifstream file(filename);
std::vector<int> temperatures;
int temp;
while (file >> temp) {
temperatures.push_back(temp);
}
return temperatures;
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
std::vector<int> temperatures = readTemperatures("temperatures.txt");
drawBarChart(temperatures);
getch();
closegraph();
return 0;
}
@@ -0,0 +1,23 @@
#include <graphics.h>
#include <iostream>
void plotInequality() {
for (int x = -10; x <= 10; x++) {
if (4 * x - x * x <= 0) {
putpixel(300 + x * 10, 300 - (4 * x - x * x) * 10, WHITE);
} else {
putpixel(300 + x * 10, 300 - (4 * x - x * x) * 10, WHITE);
}
}
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
plotInequality();
getch();
closegraph();
return 0;
}
@@ -0,0 +1,49 @@
#include <iostream>
#include <cmath>
#include <graphics.h>
using namespace std;
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
const int angleABD = 46;
const int angleCAD = 58;
int angleABC = 180 - angleABD - angleCAD;
setcolor(WHITE);
outtextxy(10, 10);
outtextxy(10, 30);
int x0 = 200, y0 = 200;
int radius = 100;
circle(x0, y0, radius);
int xA = x0 + radius * cos(angleCAD * M_PI / 180);
int yA = y0 - radius * sin(angleCAD * M_PI / 180);
int xB = x0 + radius * cos((angleCAD + angleABD) * M_PI / 180);
int yB = y0 - radius * sin((angleCAD + angleABD) * M_PI / 180);
int xC = x0 + radius * cos((angleCAD + angleABD + angleABC) * M_PI / 180);
int yC = y0 - radius * sin((angleCAD + angleABD + angleABC) * M_PI / 180);
int xD = x0 + radius * cos((angleCAD + angleABD + angleABC + angleCAD) * M_PI / 180);
int yD = y0 - radius * sin((angleCAD + angleABD + angleABC + angleCAD) * M_PI / 180);
putpixel(xA, yA, WHITE);
putpixel(xB, yB, WHITE);
putpixel(xC, yC, WHITE);
putpixel(xD, yD, WHITE);
line(xA, yA, xB, yB);
line(xB, yB, xC, yC);
line(xC, yC, xD, yD);
line(xD, yD, xA, yA);
char text[50];
sprintf(text, "Angle ABC = %d°", angleABC);
outtextxy(10, 50, text);
getch();
closegraph();
return 0;
}
@@ -0,0 +1,39 @@
#include <iostream>
#include <graphics.h>
#include <cmath>
using namespace std;
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
const double distance = 208;
const double riverSpeed = 5;
const double timeDifference = 5;
double boatSpeed = (distance * (riverSpeed + distance / (timeDifference + distance / riverSpeed))) / (2 * distance);
int riverWidth = 50;
line(50, 200, 50 + riverWidth, 200);
line(50, 250, 50 + riverWidth, 250);
line(50, 200, 50, 250);
line(50 + riverWidth, 200, 50 + riverWidth, 250);
int boatSize = 20;
int boatX = 50 + riverWidth / 2 - boatSize / 2;
int boatY = 220;
rectangle(boatX, boatY, boatX + boatSize, boatY + boatSize / 2);
line(boatX + boatSize / 2, boatY + boatSize / 4, boatX + boatSize / 2 - 10, boatY + boatSize / 4 - 10);
line(boatX + boatSize / 2, boatY + boatSize / 4, boatX + boatSize / 2 - 10, boatY + boatSize / 4 + 10);
line(boatX + boatSize / 2, boatY + boatSize / 4, boatX + boatSize / 2 + 10, boatY + boatSize / 4 - 10);
line(boatX + boatSize / 2, boatY + boatSize / 4, boatX + boatSize / 2 + 10, boatY + boatSize / 4 + 10);
char text[50];
sprintf(text, "Boat speed: %.2f km/h", boatSpeed);
outtextxy(10, 70, text);
getch();
closegraph();
return 0;
}
@@ -0,0 +1,36 @@
#include <iostream>
#include <graphics.h>
#include <cmath>
using namespace std;
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
line(100, 400, 400, 400);
line(100, 400, 100, 100);
const double k1 = 2, b1 = 1;
const double k2 = -1, b2 = 3;
const double k3 = 0.5, b3 = -2;
const double k4 = -3, b4 = -4;
for (int x = 100; x <= 400; x++) {
int y1 = k1 * (x - 100) + b1 + 400;
putpixel(x, y1, GREEN);
int y2 = k2 * (x - 100) + b2 + 400;
putpixel(x, y2, BLUE);
int y3 = k3 * (x - 100) + b3 + 400;
putpixel(x, y3, RED);
int y4 = k4 * (x - 100) + b4 + 400;
putpixel(x, y4, YELLOW);
}
getch();
closegraph();
return 0;
}
@@ -0,0 +1,24 @@
#include <iostream>
#include <graphics.h>
#include <cmath>
using namespace std;
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
line(100, 400, 400, 400);
line(100, 400, 100, 100);
for (int x = 100; x <= 400; x++) {
double y = abs(x - 100) * (x - 100) / 100 + abs(x - 100) / 100 - 3 * (x - 100) / 100 + 400;
putpixel(x, y, GREEN);
}
getch();
closegraph();
return 0;
}
@@ -0,0 +1,48 @@
#include <iostream>
#include <graphics.h>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
srand(time(0));
ofstream fileX("x.txt"), fileY("y.txt");
for (int i = 0; i < 100; i++) {
int x = rand() % 31 - 5;
int y = rand() % 31 - 5;
fileX << x << endl;
fileY << y << endl;
}
fileX.close();
fileY.close();
ifstream fileXRead("x.txt"), fileYRead("y.txt");
int x, y;
while (fileXRead >> x && fileYRead >> y) {
int graphX = x * 10 + 100;
int graphY = 400 - y * 10;
if (x + y == 35) {
circle(graphX, graphY, 5);
} else {
putpixel(graphX, graphY, WHITE);
}
}
fileXRead.close();
fileYRead.close();
getch();
closegraph();
return 0;
}
@@ -0,0 +1,178 @@
#include <stdio.h>
#include <stdlib.h>
int t19_a() {
FILE *fp;
int num, count_positive = 0, count_negative = 0;
int sum_positive = 0, sum_negative = 0;
float avg_positive = 0.0, avg_negative = 0.0;
fp = fopen("netext_a.bin", "rb"); // Îòêðûòèå áèíàðíîãî ôàéëà äëÿ ÷òåíèÿ
if (fp == NULL) {
printf("Îøèáêà îòêðûòèÿ ôàéëà!\n");
return 1;
}
while (fread(&num, sizeof(char), 1, fp) == 1) { // ×òåíèå ïî 1 öåëîìó ÷èñëó
if (num > 0) {
count_positive++;
sum_positive += num;
} else if (num < 0) {
count_negative++;
sum_negative += num;
}
}
fclose(fp); // Çàêðûòèå ôàéëà
if (count_positive > 0) {
avg_positive = (float)sum_positive / count_positive;
}
if (count_negative > 0) {
avg_negative = (float)sum_negative / count_negative;
}
printf("Number of positive numbers: %d\n", count_positive);
printf("Number of negative numbers: %d\n", count_negative);
printf("Sum of positive numbers: %d\n", sum_positive);
printf("Sum of negative numbers: %d\n", sum_negative);
printf("Arithmetic mean of positive numbers: %.2f\n", avg_positive);
printf("Arithmetic mean of negative numbers: %.2f\n", avg_negative);
return 0;
}
int t19_b() {
FILE *fp;
int num, count_positive = 0, count_negative = 0;
int sum_positive = 0, sum_negative = 0;
float avg_positive = 0.0, avg_negative = 0.0;
fp = fopen("netext_b.bin", "rb"); // Îòêðûòèå áèíàðíîãî ôàéëà äëÿ ÷òåíèÿ
if (fp == NULL) {
printf("Îøèáêà îòêðûòèÿ ôàéëà!\n");
return 1;
}
while (fread(&num, sizeof(short), 1, fp) == 1) { // ×òåíèå ïî 1 öåëîìó ÷èñëó
if (num > 0) {
count_positive++;
sum_positive += num;
} else if (num < 0) {
count_negative++;
sum_negative += num;
}
}
fclose(fp); // Çàêðûòèå ôàéëà
if (count_positive > 0) {
avg_positive = (float)sum_positive / count_positive;
}
if (count_negative > 0) {
avg_negative = (float)sum_negative / count_negative;
}
printf("Number of positive numbers: %d\n", count_positive);
printf("Number of negative numbers: %d\n", count_negative);
printf("Sum of positive numbers: %d\n", sum_positive);
printf("Sum of negative numbers: %d\n", sum_negative);
printf("Arithmetic mean of positive numbers: %.2f\n", avg_positive);
printf("Arithmetic mean of negative numbers: %.2f\n", avg_negative);
return 0;
}
int t19_v() {
FILE *fp;
int num, count_positive = 0, count_negative = 0;
int sum_positive = 0, sum_negative = 0;
float avg_positive = 0.0, avg_negative = 0.0;
fp = fopen("netext_v.bin", "rb"); // Îòêðûòèå áèíàðíîãî ôàéëà äëÿ ÷òåíèÿ
if (fp == NULL) {
printf("Îøèáêà îòêðûòèÿ ôàéëà!\n");
return 1;
}
while (fread(&num, sizeof(int), 1, fp) == 1) { // ×òåíèå ïî 1 öåëîìó ÷èñëó
if (num > 0) {
count_positive++;
sum_positive += num;
} else if (num < 0) {
count_negative++;
sum_negative += num;
}
}
fclose(fp); // Çàêðûòèå ôàéëà
if (count_positive > 0) {
avg_positive = (float)sum_positive / count_positive;
}
if (count_negative > 0) {
avg_negative = (float)sum_negative / count_negative;
}
printf("Number of positive numbers: %d\n", count_positive);
printf("Number of negative numbers: %d\n", count_negative);
printf("Sum of positive numbers: %d\n", sum_positive);
printf("Sum of negative numbers: %d\n", sum_negative);
printf("Arithmetic mean of positive numbers: %.2f\n", avg_positive);
printf("Arithmetic mean of negative numbers: %.2f\n", avg_negative);
return 0;
}
int t20() {
FILE *fp;
int num, count_positive = 0, count_negative = 0;
int sum_positive = 0, sum_negative = 0;
float avg_positive = 0.0, avg_negative = 0.0;
fp = fopen("netext2.bin", "rb"); // Îòêðûòèå áèíàðíîãî ôàéëà äëÿ ÷òåíèÿ
if (fp == NULL) {
printf("Îøèáêà îòêðûòèÿ ôàéëà!\n");
return 1;
}
while (fread(&num, sizeof(char), 1, fp) == 1) { // ×òåíèå ïî 1 öåëîìó ÷èñëó
if (num > 0) {
count_positive++;
sum_positive += num;
} else if (num < 0) {
count_negative++;
sum_negative += num;
}
}
fclose(fp); // Çàêðûòèå ôàéëà
if (count_positive > 0) {
avg_positive = (float)sum_positive / count_positive;
}
if (count_negative > 0) {
avg_negative = (float)sum_negative / count_negative;
}
printf("Number of positive numbers: %d\n", count_positive);
printf("Number of negative numbers: %d\n", count_negative);
printf("Sum of positive numbers: %d\n", sum_positive);
printf("Sum of negative numbers: %d\n", sum_negative);
printf("Arithmetic mean of positive numbers: %.2f\n", avg_positive);
printf("Arithmetic mean of negative numbers: %.2f\n", avg_negative);
return 0;
}
void main() {
printf("a\n");
t19_a();
printf("b\n");
t19_b();
printf("v\n");
t19_v();
printf("20\n");
t20();
}
@@ -0,0 +1,42 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
srand(time(NULL));
FILE *fn_a = fopen("netext_a.bin", "wb");
if (fn_a == NULL) {
perror("Error opening file netext_a.bin");
return 1;
}
for (int i = 1; i <= 100; i++) {
char n = -50 + rand() % 151;
fwrite(&n, sizeof(char), 1, fn_a);
}
fclose(fn_a);
FILE *fn_b = fopen("netext_b.bin", "wb");
if (fn_b == NULL) {
perror("Error opening file netext_b.bin");
return 1;
}
for (int i = 1; i <= 100; i++) {
char n = -50 + rand() % 151;
fwrite(&n, sizeof(char), 1, fn_b);
}
fclose(fn_b);
FILE *fn_v = fopen("netext_v.bin", "wb");
if (fn_v == NULL) {
perror("Error opening file netext_v.bin");
return 1;
}
for (int i = 1; i <= 100; i++) {
char n = -50 + rand() % 151;
fwrite(&n, sizeof(char), 1, fn_v);
}
fclose(fn_v);
return 0;
}
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <math.h>
int main() {
FILE *initialFile = fopen("input.txt", "w");
if (initialFile == NULL) {
printf("Не удалось создать файл input.txt\n");
return 1;
}
fprintf(initialFile, "3 5 4 5 9\n");
fclose(initialFile);
FILE *inputFile = fopen("input.txt", "r");
if (inputFile == NULL) {
printf("Не удалось открыть файл input.txt\n");
return 1;
}
FILE *outputFile = fopen("output.txt", "w");
if (outputFile == NULL) {
printf("Не удалось открыть файл output.txt\n");
fclose(inputFile);
return 1;
}
float a, b, c, d, e;
fscanf(inputFile, "%f %f %f %f %f", &a, &b, &c, &d, &e);
fclose(inputFile);
float numerator = pow(a, 3) * pow(b, 5);
numerator = pow(numerator, c);
float denominator = pow(d, 5) * pow(e, 9);
float result = numerator / denominator;
fprintf(outputFile, "%.2f\n", result);
fclose(outputFile);
printf("Вычисления завершены, результат записан в output.txt\n");
return 0;
}
@@ -0,0 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
FILE *fn = fopen("netext2.bin", "wb");
float n;
for (int i = 1; i <= 100; i++) {
n = -49.99 + ((float)rand()/(float)RAND_MAX) * 101.98;
fwrite(&n, sizeof(float), 1, fn);
}
fclose(fn);
return 0;
}
@@ -0,0 +1,47 @@
#include <iostream>
#include <graphics.h>
using namespace std;
void drawGrid() {
for (int i = 0; i <= 600; i += 20) {
line(i, 0, i, 600);
line(0, i, 600, i);
}
}
int main() {
// Óñòàíîâêà ãðàôè÷åñêîãî ðåæèìà
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
drawGrid();
setcolor(12);
// Îñè êîîðäèíàò
line(200, 260, 400, 260); // îñü X
line(300, 360, 300, 160); // îñü Y
// line(320, 340, 400, 220);
// Ðèñîâàíèå ãðàôèêà
for (int x = 0; x <= 600; x++) {
float y = 1.25*x - 4.25; // Âû÷èñëåíèå y ïî ãðàôèêó
putpixel(580-x, (int)y, 2);
}
bar(0,0,500,100);
// Òåêñò óñëîâèÿ
setcolor(14);
outtextxy(10, 10, "a = y2 - y1 / x2 - x1 = 2 - (-3) / 5 - 1 = 2 + 3 / 5 - 1 = 5 / 4");
outtextxy(10,30, "-3 = 5 / 4 * 1 + b ---> -3 = 5 / 4 + b");
outtextxy(10,50, "b = -3 - 5 / 4 = -12 / 4 - 5 / 4 = -17 / 4");
// Òåêñò îòâåòà
outtextxy(10, 70, "Answer: f(11) = 1.25 * 11 - 4.25 = 9.5");
printf("a = y2 - y1 / x2 - x1 = 2 - (-3) / 5 - 1 = 2 + 3 / 5 - 1 = 5 / 4");
printf("-3 = 5 / 4 * 1 + b ---> -3 = 5 / 4 + b");
printf("b = -3 - 5 / 4 = -12 / 4 - 5 / 4 = -17 / 4");
printf("Answer: f(11) = 1.25 * 11 - 4.25 = 9.5");
getch();
closegraph();
return 0;
}
@@ -0,0 +1,77 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graphics.h>
#include <winbgim.h>
#define MAX_PRODUCTS 100
#define MAX_NAME_LEN 50
int main() {
FILE *initialFile = fopen("Данные.txt", "w");
if (initialFile == NULL) {
printf("Не удалось создать файл Данные.txt\n");
return 1;
}
fprintf(initialFile, "Продукт1 14.0 17.0 12.0 20.0\n");
fclose(initialFile);
FILE *file = fopen("Данные.txt", "r");
if (file == NULL) {
printf("Не удалось открыть файл Данные.txt\n");
return 1;
}
char products[MAX_PRODUCTS][MAX_NAME_LEN];
float proteins[MAX_PRODUCTS], fats[MAX_PRODUCTS], carbohydrates[MAX_PRODUCTS], other[MAX_PRODUCTS];
int count = 0;
while (fscanf(file, "%s %f %f %f %f", products[count], &proteins[count], &fats[count], &carbohydrates[count], &other[count]) == 5) {
count++;
}
fclose(file);
int gd = DETECT, gm;
initwindow(640, 480, "Круговая диаграмма");
for (int i = 0; i < count; i++) {
cleardevice();
setcolor(WHITE);
setlinestyle(SOLID_LINE, 0, 3); // ширина линий на 3 пикселя
outtextxy(200, 20, products[i]);
float total = proteins[i] + fats[i] + carbohydrates[i] + other[i];
float start_angle = 0;
// Белки
setcolor(RED);
float sweep_angle = (proteins[i] / total) * 360;
fillellipse(320, 240, 150, 150);
pieslice(320, 240, start_angle, start_angle + sweep_angle, 150);
start_angle += sweep_angle;
// Жиры
setcolor(BLUE);
sweep_angle = (fats[i] / total) * 360;
pieslice(320, 240, start_angle, start_angle + sweep_angle, 150);
start_angle += sweep_angle;
// Углеводы
setcolor(GREEN);
sweep_angle = (carbohydrates[i] / total) * 360;
pieslice(320, 240, start_angle, start_angle + sweep_angle, 150);
start_angle += sweep_angle;
// Прочее
setcolor(YELLOW);
sweep_angle = (other[i] / total) * 360;
pieslice(320, 240, start_angle, start_angle + sweep_angle, 150);
getch();
}
closegraph();
printf("Круговая диаграмма отображена на экране\n");
return 0;
}
@@ -0,0 +1,62 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <graphics.h>
#include <winbgim.h>
#define MAX_VARIANTS 4
int main() {
FILE *initialFile = fopen("function_data.txt", "w");
if (initialFile == NULL) {
printf("Не удалось создать файл function_data.txt\n");
return 1;
}
fprintf(initialFile, "13 15\n-13 15\n13 -15\n-13 -15\n");
fclose(initialFile);
FILE *file = fopen("function_data.txt", "r");
if (file == NULL) {
printf("Не удалось открыть файл function_data.txt\n");
return 1;
}
float a[MAX_VARIANTS], c[MAX_VARIANTS];
int count = 0;
// Чтение данных из файла
while (fscanf(file, "%f %f", &a[count], &c[count]) == 2) {
count++;
}
fclose(file);
// Инициализация графического режима с использованием winbgim
int gd = DETECT, gm;
initwindow(640, 480, "Графики функции");
// Построение графиков для каждого варианта
for (int i = 0; i < count; i++) {
cleardevice();
setcolor(WHITE);
line(320, 0, 320, 480); // Ось Y
line(0, 240, 640, 240); // Ось X
setcolor(RED);
for (int x = -320; x <= 320; x++) {
int graphX = x + 320;
float y = a[i] * (x / 20.0) * (x / 20.0) + 20 * (x / 20.0) + c[i];
int graphY = 240 - (int)(y * 20);
if (graphY >= 0 && graphY <= 480) {
putpixel(graphX, graphY, RED);
}
}
delay(2000); // Задержка для отображения графика
}
closegraph();
printf("Графики отображены на экране\n");
return 0;
}
@@ -0,0 +1,38 @@
#include <graphics.h>
#include <iostream>
#include <fstream>
void drawTriangle(float A[], float B[], float C[]) {
line(A[0], A[1], B[0], B[1]);
line(B[0], B[1], C[0], C[1]);
line(C[0], C[1], A[0], A[1]);
}
float calculateArea(float base, float height) {
return 0.5 * base * height;
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
// Условия задачи
float A[] = {100, 100}, B[] = {200, 300}, C[] = {300, 100};
drawTriangle(A, B, C);
// Параметры
float AC = 16, MN = 10, areaABC = 32;
// Площадь треугольника MBN
float areaMBN = (MN / AC) * areaABC;
outtextxy(10, 10, "Area of triangle MBN:");
char buffer[50];
sprintf(buffer, "%.2f", areaMBN);
outtextxy(10, 30, buffer);
getch();
closegraph();
return 0;
}
@@ -0,0 +1,34 @@
#include <graphics.h>
#include <iostream>
void drawGrid() {
for (int i = 0; i <= 600; i += 20) {
line(i, 0, i, 600);
line(0, i, 600, i);
}
}
void drawParallelogram() {
int x[] = {100, 200, 100, 100, 250, 100, 200, 200, 100, 200}; // êîîðäèíàòû âåðøèí
// int y[] = {100, 100, 200, 200};
setcolor(RED);
drawpoly(4, x); // Ïåðåäàåì ìàññèâ òî÷åê
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
drawGrid();
drawParallelogram();
// Ïëîùàäü ïàðàëëåëîãðàììà
int base = 150; // äëèíà îñíîâàíèÿ (ðàññ÷èòàííàÿ ïî êîîðäèíàòàì)
int height = 100; // âûñîòà (ðàññ÷èòàííàÿ ïî êîîðäèíàòàì)
float area = base * height;
std::cout << "Area of the parallelogram: " << area << std::endl;
getch(); // Îæèäàíèå ââîäà
closegraph();
return 0;
}
@@ -0,0 +1,34 @@
#include <graphics.h>
#include <math.h>
void drawGraph() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
int x, y;
int max_x = getmaxx();
int max_y = getmaxy();
int origin_x = max_x / 2;
int origin_y = max_y / 2;
// Draw axes
line(0, origin_y, max_x, origin_y); // X-axis
line(origin_x, 0, origin_x, max_y); // Y-axis
// Plot the function
for (x = -origin_x; x <= origin_x; x++) {
float fx = (float)x / 10; // Scale x for better visibility
float fy = ((fx + 4) * (fx * fx + 3 * fx + 2)) / (fx + 1);
y = origin_y - (int)(fy * 10); // Scale y for better visibility
putpixel(origin_x + x, y, GREEN);
}
getch();
closegraph();
}
int main() {
drawGraph();
return 0;
}
@@ -0,0 +1,51 @@
#include <iostream>
#include <cmath>
#include <graphics.h>
using namespace std;
int main() {
// Установка графического режима
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
// Параметры задачи
const double a = 11; // Меньшая сторона треугольника
const double k1 = 6, k2 = 7, k3 = 23; // Отношения дуг
// Вычисление углов треугольника
double alpha = (k1 / (k1 + k2 + k3)) * 360;
double beta = (k2 / (k1 + k2 + k3)) * 360;
double gamma = (k3 / (k1 + k2 + k3)) * 360;
// Вычисление радиуса описанной окружности
double R = a / (2 * sin(gamma * M_PI / 180));
// Вывод условия задачи в графическом виде
setcolor(WHITE);
outtextxy(10, 10, "Вершины треугольника делят описанную около него окружность");
outtextxy(10, 30, "на три дуги, длины которых относятся, как 6:7:23.");
outtextxy(10, 50, "Найти радиус окружности, если меньшая из сторон треугольника равна 11.");
// Рисование треугольника
int x0 = 200, y0 = 200;
int x1 = x0 + a / 2, y1 = y0 + a * sqrt(3) / 2;
int x2 = x0 - a / 2, y2 = y0 + a * sqrt(3) / 2;
line(x0, y0, x1, y1);
line(x1, y1, x2, y2);
line(x2, y2, x0, y0);
// Рисование описанной окружности
circle(x0, y0+6, R*1.2);
// Вывод ответа
char text[50];
sprintf(text, "Радиус окружности: %.2f", R);
outtextxy(10, 70, text);
getch();
closegraph();
return 0;
}
@@ -0,0 +1,51 @@
#include <iostream>
#include <cmath>
#include <graphics.h>
using namespace std;
int main() {
// Установка графического режима
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
// Параметры задачи
const double AB = 16; // Боковая сторона AB
const double CD = 34; // Боковая сторона CD
const double BC = 2; // Основание BC
// Вычисление высоты трапеции
double h = AB / 2; // Высота равна половине боковой стороны AB
// Вычисление площади трапеции
double S = (AB + CD) * h / 2;
// Вывод условия задачи в графическом виде
setcolor(WHITE);
outtextxy(10, 10, "Боковые стороны AB и CD трапеции ABCD равны соответственно 16 и 34, а основание BC равно 2.");
outtextxy(10, 30, "Биссектриса угла ADC проходит через середину стороны AB. Найти площадь трапеции.");
// Рисование трапеции
int x0 = 100, y0 = 300; // Вершина A
int x1 = x0 + AB, y1 = y0; // Вершина B
int x2 = x1 - BC, y2 = y0 - h; // Вершина C
int x3 = x2 - (CD - AB), y3 = y2; // Вершина D
line(x0, y0, x1, y1);
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x0, y0);
// Рисование биссектрисы
line(x3, y3, x0 + AB / 2, y0);
// Вывод ответа
char text[50];
sprintf(text, "Площадь трапеции: %.2f", S);
outtextxy(10, 50, text);
getch();
closegraph();
return 0;
}
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="С(2024)" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/С(2024)" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/С(2024)" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Extensions />
</Project>
</CodeBlocks_project_file>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
</CodeBlocks_layout_file>