forked from Sarah-Villegas/fileIO_B
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lomeli_FileIO_B.cpp
57 lines (52 loc) · 1.55 KB
/
lomeli_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
//Name: Noe Lomeli
//Date: October 22, 2015
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
string firstName, lastName;
double num1, num2, num3, num4, num5, num6, average, sum;
double maxAve = 0;
string maxName;
ifstream fin;//input stream
ofstream fout;//output stream
char fileName[12];
cout << "Please enter name of file: ";
cin >> fileName;//user input
fin.open(fileName);//opens the file that the user called
if(fin.fail())
{
cout << "Input file opening failed." << endl;
exit(1);
}//if
fout.open("results.txt");
if(fout.fail())
{
cout << "Output file opening failed." << endl;
exit(1);
}//if
while(fin >> firstName >> lastName >> num1 >> num2 >> num3 >> num4 >> num5 >> num6)
{
//magic formula for formatting
fout.setf(ios::fixed);
fout.setf(ios::showpoint);
fout.precision(2);
fout.setf(ios::left);
average = ((num1 + num2 + num3 + num4 + num5 + num6) / 6);
fout << setw(12) << firstName << setw(12) << lastName ;
//fout.setf(ios::right);
fout << setw(8) << num1 << setw(8) << num2 << setw(8) << num3 << setw(8) << num4 << setw(8) << num5 << setw(8) << num6 << average <<endl;
if(average > maxAve)
{
maxAve = average;
maxName = firstName + " " + lastName;
}//if
}//while
fout << "Highest Score: " << maxName << endl;
fin.close();
fout.close();
return 0;
}//main