0% found this document useful (0 votes)
12 views1 page

Lab 12.12

Uploaded by

k61ca.2242219031
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Lab 12.12

Uploaded by

k61ca.2242219031
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

#include <fstream>
#include <vector>
using namespace std;

int main() {
ifstream inFS; // Input file stream
vector<string> firstNames(20);
vector<string> lastNames(20);
vector<int> midterm1Scores(20);
vector<int> midterm2Scores(20);
vector<int> finalScores(20);

// step 1 : Open the file


inFS.open("StudentInfo.tsv");
if (!inFS.is_open()) {
cout << "Could not open file myfile.txt." << endl;
return 1;
}

//step 2: Read the file content


int n = 0;
while (inFS >> firstNames.at(n)
>> lastNames.at(n)
>> midterm1Scores.at(n)
>> midterm2Scores.at(n)
>> finalScores.at(n)) {
n++;
}
if (!inFS.eof()) {
cout << "Input failure before reaching end of file." << endl;
}
cout << "Closing file myfile.txt." << endl;
// Done with file, so close it
inFS.close();

//Step 3: Ouput results to a text file here.


ofstream outFS; // Output file stream
outFS.open("report.txt");// Open file
if (!outFS.is_open()) {
cout << "Could not open file report.txt." << endl;
return 2;
}
// step 3.1 Compute the average exam score of each student
/* write your code here */

// Output the data and letter grade (you need to calculate the grade)
/* write your code here */

for (int j=0; j<n ; j++){


outFS << firstNames.at(j) << "\t"
<<lastNames.at(j) << "\t"
<< midterm1Scores.at(j)<< "\t"
<< midterm2Scores.at(j)<< "\t"
<< finalScores.at(j)<< "\t"
//<</* write your code here */ << "\t"
<< endl;
}
// step 3.2 Compute the average exam score of each student
/* write your code here */

// Done with file, so close


outFS.close();

return 0;
}

You might also like