-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudentInfo.cpp
48 lines (45 loc) · 1.21 KB
/
studentInfo.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
47
48
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
class StudentInfo
{
public:
StudentInfo() : first(""), last(""), level(""), GPA(0.0){}
StudentInfo(string f, string l, string lev, double gpa) : first(f), last(l), level(lev), GPA(gpa){}
string firstName() {return first;}
string lastName() {return last;}
string classLevel() {return level;}
double getGPA() {return GPA;}
private:
string first, last, level;
double GPA;
};
int main()
{
ifstream f("studentlist1.txt");
string first, last, level;
double GPA;
vector<StudentInfo> si;
while (f >> first >> last >> level >> GPA)
{
StudentInfo s(first, last, level, GPA);
si.push_back(s);
}
double gpaSum = 0;
for (int i=0; i<si.size(); i++)
{
gpaSum += si[i].getGPA();
}
double gpaAve = gpaSum / si.size();
cout << gpaAve << endl;
ofstream file("studentScores.txt");
file << "Average GPA: " << gpaAve << endl;
file << "Students whose GPAs are above the average: " << endl;
for (int i=0; i<si.size(); i++)
{
if (si[i].getGPA() > gpaAve)
file << si[i].firstName() << " " << si[i].lastName() << endl;
}
return 0;
}