Archived
63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
#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;
|
|
}
|