-
Notifications
You must be signed in to change notification settings - Fork 1
/
gpaCalc.cpp
55 lines (48 loc) · 1.3 KB
/
gpaCalc.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
49
50
51
52
53
54
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include "student.h"
#include "gradeValue.h"
using namespace std;
void gpaCalc (istream& input, ostream& output)
{
string name;
getline (input, name);
int credits;
double qp;
input >> credits >> qp;
Student student(name, credits, qp);
string grade;
input >> grade >> credits;
while (grade != "0" && credits != 0)
{
student.addGrade (grade, credits);
input >> grade >> credits;
}
double gpa = student.computeGPA();
output << student.name << ' '
<< fixed << setprecision(2) << gpa << endl;
}
int main (int argc, char** argv)
{
// A useful "trick": The code below looks to see if
// a command line parameter has been specified. If so,
// e.g.: gpaCalc fileName
// the command line paraemter is assumed to name an input file
// and the rest of the program reads form that file.
// If no command parameter is given, the program reads its
// input from cin.
//
// What makes this useful is that it is often easier to supply
// input from a file during debugging, even if the program is
// normally supposed to read from standard input (cin).
if (argc > 1)
{
ifstream inputFile (argv[1]);
gpaCalc (inputFile, cout);
}
else
gpaCalc (cin, cout);
return 0;
}