-
Notifications
You must be signed in to change notification settings - Fork 2
/
map.cpp
38 lines (34 loc) · 813 Bytes
/
map.cpp
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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct StudentGrade{
string name;
char grade;
};
class GradeMap{
vector<StudentGrade> m_map;
public:
GradeMap(){};
char& operator[](string student_name){
for(auto& student : m_map){
if(student.name == student_name){
return student.grade;
}
}
m_map.push_back(StudentGrade{student_name, ' '});
return m_map.back().grade;
}
};
int main(int argc, char const *argv[]){
GradeMap grades;
grades["Joe"] = 'A';
grades["Frank"] = 'B';
cout << "Joe has a grade of: " << grades["Joe"] << endl;
cout << "Frank has a grade of: " << grades["Frank"] << endl;
char& shawn_grade = grades["Shawn"];
shawn_grade = 'C';
cout << "Shawn has a grade of: " << grades["Shawn"] << endl
<< shawn_grade << endl;
return 0;
}