-
Notifications
You must be signed in to change notification settings - Fork 26
/
Villegas_fileIO_B.cpp
64 lines (40 loc) · 1.36 KB
/
Villegas_fileIO_B.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
55
56
57
58
// Name: Sarah Villegas
// October 22,2015
// FileIO B
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <fstream>
using namespace std;
int main(){
ifstream fin;
ofstream fout;
char fileName [12];
string firstName, lastName, winner;
double score1, score2, score3, score4, score5, score6;
double bestavg = 0, avg = 0;
cout << "Please enter the file name you want to open: ";
cin >> fileName;
fin.open(fileName);
if(fin.fail()){
cout << "File failed to open " << endl;
exit(1);
}
fout.open("results.txt");
while (fin >> firstName >> lastName >> score1 >> score2 >> score3 >> score4 >> score5 >> score6){
fout.setf(ios::fixed);
fout.setf(ios::showpoint);
fout.precision(2);
fout.setf(ios::left);
avg = (score1 + score2 + score3 + score4 + score5 + score6) / 6.0;
if(bestavg < avg ){
bestavg = avg;
winner = firstName + " " + lastName;
}
fout << setw(12) << firstName << setw(12) << lastName << setw(12) << score1 << setw(8) << score2 << setw(8) << score3 << setw(8) << score4 << setw(8) << score5 << setw(8) << score6 << setw(8) << endl;
}
fout << "Highest Score: " << winner << endl;
fin.close();
fout.close();
return 0;
}