Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am needing this program to pause when ran at the console. Also, this program i

ID: 3627688 • Letter: I

Question

I am needing this program to pause when ran at the console. Also, this program is writing to an output file and it is correct. I want the output file to show in the console. Here is the Input file information. Also, the output file is not lining up correctly. Please modify!
Input file information:
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63

Output

Student     Test1     Test2     Test3     Test4     Test5   Average     Grade
   Johnson        85        83        77        91        76     82.00         B
   Aniston        80        90        95        93        48     81.00         B
    Cooper        78        81        11        90        73     66.00         D
     Gupta        92        83        30        69        87     72.00         C
     Blair        23        45        96        38        59     52.00         F
     Clark        60        85        45        39        67     59.00         F
   Kennedy        77        31        52        74        83     63.00         D
   Bronson        93        94        89        77        97     90.00         A
     Sunny        79        85        28        93        82     73.00         C
     Smith        85        72        49        75        63     68.00         D
Class Average: 70.60






// include statement(s).
#include
#include
#include
#include
#include

// using namespace statement.
using namespace std;

// function prototypes
void calculateAverage(ifstream& _inFile, ofstream& _outFile, double& _runningAverage);
char calculateGrade( double _grade);

const int numTests = 5;

int main()
{

// Declare Vatriables
int count = 0;
double runningAverage =0;
string studentName;

// Declare file streams
ifstream inFile;
ofstream outFile;

// opens the input file
inFile.open ("ch9_Ex13Data.txt");

// Display error if file was not opened
if ( !inFile.is_open() )
{
cout << "Error in opening file.";
cout << "Program terminates." << endl;
return 1;
}

// Opens the output file
outFile.open ("Ch9_Ex13Out.txt");
outFile << fixed << showpoint;
outFile << setprecision (2);
outFile << "Student" << setw(10) << "Test1" << setw(10) << "Test2" << setw(10)
<< "Test3" << setw(10) <<"Test4" << setw(10) << "Test5" << setw(10)
<< "Average" << setw(10) << "Grade" << setw(10) <

// Read and write a students name from the input file
inFile >> studentName;
while(inFile)
{
count++;
outFile << setw(10) << studentName;
calculateAverage(inFile, outFile, runningAverage);
inFile >> studentName;
}

outFile << "Class Average: " << (runningAverage/count);



//Close file Streams
inFile.close ();
outFile.close ();

return 0;

}
// deterime the average of the 5 test scores for each student
// Read and write a students test scores
void calculateAverage(ifstream& _inFile, ofstream& _outFile, double& _runningAverage)
{
int testsTotal = 0;
int test = 0;
double testsAverage = 0;

for(int i=0; i {
_inFile >> test;
testsTotal += test;
_outFile << setw(10) << test;
}

testsAverage = testsTotal / numTests;
_runningAverage += testsAverage;

_outFile << setw(10) << testsAverage;
_outFile << setw(10) << calculateGrade(testsAverage) << " ";
}

// determines and returns the students letter grade
char calculateGrade (double _grade)
{
if (_grade < 60)
return 'F';
else if (_grade < 70)
return 'D';
else if (_grade < 80)
return 'C';
else if (_grade < 90)
return 'B';
else
return 'A';


}



Explanation / Answer

Be sure to paste your code from plain text or word next time to avoid missing symbols. The output should be how you want it now all aligned up. Added cout lines after outfiles. Also I saw a mistake in your calculations with int division instead of double division for average and updated that. //include statement(s). #include<iostream> #include<fstream> #include<iomanip> #include<math.h> #include<string> // using namespace statement. using namespace std; // function prototypes void calculateAverage(ifstream& _inFile, ofstream& _outFile, double& _runningAverage); char calculateGrade( double _grade); const int numTests = 5; int main() { // Declare Vatriables int count = 0; double runningAverage =0.0; string studentName; // Declare file streams ifstream inFile; ofstream outFile; // opens the input file inFile.open ("ch9_Ex13Data.txt"); // Display error if file was not opened if ( !inFile.is_open() ) { cout << "Error in opening file."; cout << "Program terminates." << endl; return 1; } // Opens the output file outFile.open ("Ch9_Ex13Out.txt"); outFile << fixed << showpoint; outFile << setprecision (2); outFile << setw(10) << "Student" << setw(10) << "Test1" << setw(10) << "Test2" << setw(10) << "Test3" << setw(10) <<"Test4" << setw(10) << "Test5" << setw(10) << "Average" << setw(10) << "Grade" << endl; cout << fixed << showpoint; cout << setprecision (2); cout << setw(10) << "Student" << setw(10) << "Test1" << setw(10) << "Test2" << setw(10) << "Test3" << setw(10) <<"Test4" << setw(10) << "Test5" << setw(10) << "Average" << setw(10) << "Grade" << endl; inFile >> studentName; // Read and write a students name from the input file while(inFile) { count++; outFile << setw(10) << studentName; cout << setw(10) << studentName; calculateAverage(inFile, outFile, runningAverage); inFile >> studentName; } outFile << "Class Average: " << (runningAverage/count) << endl; cout << "Class Average: " << (runningAverage/count) << endl; //Close file Streams inFile.close (); outFile.close (); system("pause"); //to pause console*** return 0; } // deterime the average of the 5 test scores for each student // Read and write a students test scores void calculateAverage(ifstream& _inFile, ofstream& _outFile, double& _runningAverage) { int testsTotal = 0; int test = 0; double testsAverage = 0.0; for(int i=0; i < numTests; i++) { _inFile >> test; testsTotal += test; _outFile << setw(10) << test; cout << setw(10) << test; } testsAverage = (double)testsTotal / numTests; //conversion to double division*** _runningAverage += testsAverage; _outFile << setw(10) << testsAverage; _outFile << setw(10) << calculateGrade(testsAverage) << " "; cout << setw(10) << testsAverage; cout << setw(10) << calculateGrade(testsAverage) << " "; } // determines and returns the students letter grade char calculateGrade (double _grade) { if (_grade < 60) return 'F'; else if (_grade < 70) return 'D'; else if (_grade < 80) return 'C'; else if (_grade < 90) return 'B'; else return 'A'; }