Ch3_AverageTestScore - //Step 5 outFile...

Info iconThis preview shows page 1. 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; Step 1 ifstream inFile; //input file stream variable ofstream outFile; //output file stream variable double test1, test2, test3, test4, test5; double average; string firstName; string lastName; inFile.open("a:\\test.txt"); //Step 2 outFile.open("a:\\testavg.out"); //Step 3 outFile << fixed << showpoint; //Step 4 outFile << setprecision(2); //Step 4 cout << "Processing data" << endl; inFile >> firstName >> lastName;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //Step 5 outFile &lt;&lt; &quot;Student name: &quot; &lt;&lt; firstName &lt;&lt; &quot; &quot; &lt;&lt; lastName &lt;&lt; endl; //Step 6 inFile &gt;&gt; test1 &gt;&gt; test2 &gt;&gt; test3 &gt;&gt; test4 &gt;&gt; test5; //Step 7 outFile &lt;&lt; &quot;Test scores: &quot; &lt;&lt; setw(6) &lt;&lt; test1 &lt;&lt; setw(6) &lt;&lt; test2 &lt;&lt; setw(6) &lt;&lt; test3 &lt;&lt; setw(6) &lt;&lt; test4 &lt;&lt; setw(6) &lt;&lt; test5 &lt;&lt; endl; //Step 8 average = (test1 + test2 + test3 + test4 + test5) / 5.0; //Step 9 outFile &lt;&lt; &quot;Average test score: &quot; &lt;&lt; setw(6) &lt;&lt; average &lt;&lt; endl; //Step 10 inFile.close(); //Step 11 outFile.close(); //Step 11 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.

Ask a homework question - tutors are online