blob: 1f59c4ebf86c0359e659ddf93938028140524e10 (
plain) (
blame)
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
59
60
61
62
63
|
// Name: msglm
// Date:
// Introduction:
// Description:
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
// Named constants
int main() {
//Variable declaration
ifstream inFile;
ofstream outFile;
string name;
double test1, test2, test3;
double average;
int iterator = 0;
//Program title and description for the user
//cout << "Title: " << endl << "Description: " << endl;
// User input
// Dealing with input/output files
inFile.open("studentScore.txt");
outFile.open("testavg.out");
//Output header information
outFile << fixed << showpoint << setprecision(2);
outFile << setw(17) << left << "Name: " << setw(8) << "Test 1" << setw(8) << "Test 2" << setw(8) << "Test 3" << setw(8) << "Average" << endl;
while (iterator < 3){
//Reading from the file
getline(inFile, name);
inFile >> test1 >> test2 >> test3;
inFile.ignore();
// Calculations
average = (test1+test2+test3)/3.0;
// Output to the screen
outFile << setw(17) << left << name << setw(8) << test1 << setw(8) << test2 << setw(8) << test3 << setw(8) << average << endl;
iterator++;
}
inFile.close();
outFile.close();
cout << "Please Check testavg.out file" << endl;
return 0;
}
/*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
|