Ch3_AverageTestScoreVersion2

Ch3_AverageTestScoreVersion2 - //Update sum inFile...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//Program to calculate the average test score. #include <iostream> #include <fstream> #include <iomanip> #include <string> # using namespace std; u int main() { //Declare variables; ifstream inFile; //input file stream variable ofstream outFile; //output file stream variable double testScore; double sum = 0; string firstName; string lastName; inFile.open("a:\\test.txt"); outFile.open("a:\\testavg.out"); outFile << fixed << showpoint; outFile << setprecision(2); cout << "Processing data" << endl; inFile >> firstName >> lastName; outFile << "Student name: " << firstName << " " << lastName << endl; outFile << "Test scores: "; inFile >> testScore; //Read the first test score outFile << setw(6) << testScore; //Output the test score sum = sum + testScore;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //Update sum inFile &gt;&gt; testScore; //Read the second test score outFile &lt;&lt; setw(6) &lt;&lt; testScore; //Output the test score sum = sum + testScore; //Update sum inFile &gt;&gt; testScore; //Read the third test score outFile &lt;&lt; setw(6) &lt;&lt; testScore; //Output the test score sum = sum + testScore; //Update sum inFile &gt;&gt; testScore; //Read the fourth test score outFile &lt;&lt; setw(6) &lt;&lt; testScore; //Output the test score sum = sum + testScore; //Update sum inFile &gt;&gt; testScore; //Read the fifth test score outFile &lt;&lt; setw(6) &lt;&lt; testScore; //Output the test score sum = sum + testScore; //Update sum outFile &lt;&lt; endl; outFile &lt;&lt; &quot;Average test score: &quot; &lt;&lt; setw(6) &lt;&lt; sum / 5.0 &lt;&lt; endl; inFile.close(); outFile.close(); return 0; }...
View Full Document

This note was uploaded on 03/08/2011 for the course CSIT 139 taught by Professor Duzut during the Spring '11 term at Los Angeles City College.

Page1 / 2

Ch3_AverageTestScoreVersion2 - //Update sum inFile...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online