Archived
Работы по программированию
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user