-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.cc
More file actions
44 lines (42 loc) · 1.05 KB
/
strings.cc
File metadata and controls
44 lines (42 loc) · 1.05 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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int
main (int argc, char * argv[])
{
int num {0};
cout << "How many students info you want to enter?";
cin >> num;
if (num < 0) {
num = 6;
}
string fname;
string grade_str;
uint16_t grade;
uint32_t total {0};
vector<pair<string, int>> studentData;
for (auto i = 0; i < num; i++)
{
cout << "Enter first name";
cin >> fname;
do {
cout << "Enter grade (out of 100)";
cin >> grade_str;
grade = atoi(grade_str.c_str());
} while (grade < 0 || grade > 100);
total += grade;
studentData.emplace_back(fname, grade);
}
int row = 0;
for(auto it = studentData.begin(); it != studentData.end(); it++, row++)
{
cout << it->first << ": " << it->second;
if ((row + 1) % 3 == 0) {
cout << endl;
} else {
cout << ", ";
}
}
cout << "Average grade: " << total / studentData.size() << endl;
}