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

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,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>