Last active
May 17, 2020 16:30
-
-
Save lablnet/fdddeb67264ed364d037fecd06a7d676 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //usr/bin/g++ | |
| #include <iostream> | |
| int main() { | |
| const int S = 5, M = 6, max = 1000; | |
| int subjects[S][M], avg[S], sum = 0; | |
| char students[S][max]; | |
| // Read the mark for students. | |
| for (int i = 0; i < S; i++) { | |
| std::cout << "Enter name of Student #" << i + 1 << " : "; | |
| //The extraction operations leave the trailing '\n' character in the stream. On the other hand, istream::getline() discards it. So when you call getline after an extraction operator, '\n' is the first character it encounters and it stops reading right there. so we need to call cin.ignore(). | |
| std::cin.ignore(); | |
| std::cin.getline(students[i], max); | |
| for (int j = 0; j < M; j++) { | |
| std::cout << "Enter mark of subect #" << j + 1 << " : "; | |
| std::cin >> subjects[i][j]; | |
| } | |
| } | |
| // Getting average marks. | |
| for (int i = 0; i < S; i++) { | |
| for (int j = 0; j < M; j++) { | |
| sum = sum + subjects[i][j]; | |
| } | |
| avg[i] = sum / 6; | |
| } | |
| // Printing... | |
| for (int i = 0; i < S; i++) { | |
| if (avg[i] >= 90) { | |
| std::cout << "A: " << students[i] << std::endl; | |
| } else if (avg[i] >= 75 && avg[i] < 90) { | |
| std::cout << "B: " << students[i] << std::endl; | |
| } else if (avg[i] >= 65 && avg[i] < 75) { | |
| std::cout << "C: " << students[i] << std::endl; | |
| } else if (avg[i] >= 50 && avg[i] < 65) { | |
| std::cout << "D: " << students[i] << std::endl; | |
| } else { | |
| std::cout << "Failed: " << students[i]; | |
| } | |
| std::cout << std::endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment