Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int studentCount;
- cin >> studentCount;
- double grade3 = 0, grade4 = 0, grade5 = 0, grade6 = 0, totalGradeSum = 0, currentGrade;
- for (int i = 0; i < studentCount; i++) {
- cin >> currentGrade;
- if (currentGrade >= 5) {
- grade6++;
- }
- else if (currentGrade >= 4) {
- grade5++;
- }
- else if (currentGrade >= 3) {
- grade4++;
- }
- else if (currentGrade >= 2) {
- grade3++;
- }
- totalGradeSum += currentGrade;
- }
- cout.setf(ios::fixed);
- cout.precision(2);
- cout << "Top students: " << 100.0 * grade6 / studentCount << "%\n";
- cout << "Between 4.00 and 4.99: " << 100.0 * grade5 / studentCount << "%\n";
- cout << "Between 3.00 and 3.99: " << 100.0 * grade4 / studentCount << "%\n";
- cout << "Fail: " << 100.0 * grade3 / studentCount << "%\n";
- cout << "Average: " << 1.0 * totalGradeSum / studentCount << endl;
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- int studentCount;
- cin >> studentCount;
- double grade3 = 0, grade4 = 0, grade5 = 0, grade6 = 0, totalGradeSum = 0, currentGrade;
- for (int i = 0; i < studentCount; i++) {
- cin >> currentGrade;
- currentGrade >= 5 ? grade6++ : currentGrade >= 4 ? grade5++ : currentGrade >= 3 ? grade4++ : grade3++;
- totalGradeSum += currentGrade;
- }
- cout.setf(ios::fixed);
- cout.precision(2);
- cout << "Top students: " << 100.0 * grade6 / studentCount << "%\n";
- cout << "Between 4.00 and 4.99: " << 100.0 * grade5 / studentCount << "%\n";
- cout << "Between 3.00 and 3.99: " << 100.0 * grade4 / studentCount << "%\n";
- cout << "Fail: " << 100.0 * grade3 / studentCount << "%\n";
- cout << "Average: " << 1.0 * totalGradeSum / studentCount << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement