Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h" // само при Visual Studio <= 2017
- #include <iostream>
- #include <cmath>
- #include <ctime> // заради time()
- using namespace std;
- int main()
- {
- srand(static_cast<unsigned>(time(NULL))); // init random generator
- const int n = 1000; // брой на оценките
- double list[n]; // масив с оценки
- // генериране на случайни оценки
- for (int i = 0; i<n; ++i)
- {
- // list[i] = rand() % 5 + 2 ; // 2-6 цяло число
- list[i] = 2.0 + static_cast <double> (rand()) /
- (static_cast <double> (RAND_MAX / (6.00 - 2.00)));
- // закръгляме до втория знак
- list[i] = list[i] * 100;
- int x = list[i];
- list[i] = x / 100.0;
- }
- // извеждане на списъка с оценки на екрана
- cout << endl << "----- Results -----\n";
- cout.setf(ios::fixed | ios::showpoint);
- cout.precision(2);
- for (int i = 0; i<n; ++i)
- cout << "Student No " << i + 1 << " - "
- << "evaluation: " << list[i] << endl;
- cout << endl;
- // намиране на средната оценка (среден успех)
- double sum = 0;
- for (int index = 0; index < n; index++)
- sum = sum + list[index];
- cout << "Sum of all evaluations is: " << sum << endl;
- double average = sum / n;
- cout << "Average evaluation is: " << average << endl;
- // намиране на минимална оценка (стойност)
- double min = list[0]; // приемаме че 1-вият елемент е най-малък
- for (int index = 1; index < n; index++)
- if (list[index] < min)
- min = list[index];
- cout << "Minimal evaluation is: " << min << " and is at position(s): ";
- // намиране на минимална оценка (позиции)
- for (int index = 0; index < n; index++)
- if (list[index] == min)
- cout << index + 1 << " ";
- cout << endl;
- // намиране на максимална оценка (стойност)
- double max = list[0]; // приемаме че 1-вият елемент е най-голям
- for (int index = 1; index < n; index++)
- if (list[index] > max)
- max = list[index];
- cout << "Maximal evaluation is: " << max << " and is at position(s): ";
- // намиране на максимална оценка (позиции)
- for (int index = 0; index < n; index++)
- if (list[index] == max)
- cout << index + 1 << " ";
- cout << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment