-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8_4.cpp
More file actions
47 lines (35 loc) · 1.12 KB
/
8_4.cpp
File metadata and controls
47 lines (35 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Student {
string name;
int score;
};
bool compareByScoreDescending(const Student& a, const Student& b) {
return a.score > b.score;
}
int main() {
vector<Student> students;
int numStudents;
cout << "Enter the number of students: ";
cin >> numStudents;
cin.ignore(); // Clear newline character from the input buffer
for (int i = 0; i < numStudents; ++i) {
Student s;
cout << "Enter full name of student " << i + 1 << ": ";
getline(cin, s.name);
cout << "Enter score of " << s.name << ": ";
cin >> s.score;
cin.ignore(); // Clear newline character for next getline
students.push_back(s);
}
sort(students.begin(), students.end(), compareByScoreDescending);
cout << "\nStudent Rankings:\n";
int rank = 1;
for (const auto& s : students) {
cout << "Rank " << rank++ << ": " << s.name << " - " << s.score << " marks\n";
}
cout<<endl<<"24CE052_Pushtikansara"<<endl;
return 0;
}