Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- const int n = 5; // брой на оценките
- double list[n]; // масив с оценки
- // въвеждане на оценките от клавиатурата
- for (int i = 0; i<n; ++i)
- {
- do { // въвеждането е с проверка за коректност
- cout << "Evaluation for student No " << i + 1 << ": ";
- cin >> list[i];
- } while (list[i]<2.0 || list[i]>6.0); // само от 2 до 6
- }
- // извеждане на списъка с оценки на екрана
- 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 << " - \t"
- << "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