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