forked from orazaro/accelerated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03-05-several.cpp
46 lines (37 loc) · 1.04 KB
/
03-05-several.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
39
40
41
42
43
44
45
46
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> students;
vector<double> grades;
while(1) {
cout << "Please, enter your name or end: ";
string name;
cin >> name;
if( name == "end" ) break;
cout << "Hello, " << name << "!" << endl;
cout << "Please enter your midterm and final exam grades: ";
double midterm, final;
cin >> midterm >> final;
int ngrades = 3;
cout << "Enter "<< ngrades << " your homework grades: ";
int count = 0;
double sum = 0;
double x;
for(int i = 0; i < ngrades && cin >> x; i++) {
++count;
sum += x;
}
double grade = 0.2 * midterm + 0.4 * final + 0.4 * sum / count;
students.push_back(name);
grades.push_back(grade);
}
cout << endl << "Students:" << endl;
for(int i = 0; i < (int)students.size(); i++)
{
cout << students[i] << " " << grades[i] << endl;
}
return 0;
}