-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSTL.cpp
More file actions
63 lines (49 loc) · 1.53 KB
/
STL.cpp
File metadata and controls
63 lines (49 loc) · 1.53 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <map>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
double calculateAverage(const vector<int>& marks) {
int sum = 0;
for (int i = 0; i < marks.size(); i++) {
sum += marks[i];
}
return sum / 3.0;};
int main() {
map<string, vector<int>> students;
string name;
vector<int> marks(3);
char choice;
do {
cout << "Enter student name: ";
cin >> name;
cout << "Enter marks for 3 subjects: ";
for (int i = 0; i < 3; i++) {
cin >> marks[i];
}
students[name] = marks;
cout << "Do you want to add another student? (y/n): ";
cin >> choice;
} while (choice == 'y' || choice == 'Y');
cout << "\nStudent Records:\n";
for (auto it = students.begin(); it != students.end(); it++) {
double avg = calculateAverage(it->second);
cout << "Student: " << it->first << ", Marks: ";
for (int i = 0; i < 3; i++) {
cout << it->second[i] << " ";
}
cout << ", Average: " << avg << endl;
}
string topperName;
double highestAvg = -1;
for (auto it = students.begin(); it != students.end(); it++) {
double avg = calculateAverage(it->second);
if (avg > highestAvg) {
highestAvg = avg;
topperName = it->first;
}
cout << "\nTopper: " << topperName << " with average " << highestAvg << endl;
return 0;
}
}