Answer to Question #209248 in C++ for ASAP

Question #209248

Topic: Files and Streams


Codes discussed will be posted here. Write your conclusion


File name: "zCh4_AverageTestScore.cpp"

Note: Need the proper answer not a wrong answer

Code: 


*Note: use the link below to view the codes


https://drive.google.com/file/d/1oGJvoH9fkwtj3htKhDvv9WlAqLdiahgh/view?usp=sharing


1
Expert's answer
2021-06-23T17:07:27-0400
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
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("test.txt"); //open the input file
if (!inFile)
{
cout << "Cannot open the input file. "
<< "The program terminates." << endl;
return 1;
}
outFile.open("testavg.out"); //open the output file
outFile << fixed << showpoint;
outFile << setprecision(2);
cout << "Processing data" << endl;
inFile >> firstName >> lastName;
outFile << "Student name: " << firstName
<< " " << lastName << endl;
inFile >> test1 >> test2 >> test3
>> test4 >> test5;
outFile << "Test scores: " << setw(4) << test1
<< setw(4) << test2 << setw(4) << test3
<< setw(4) << test4 << setw(4) << test5
<< endl;
average = (test1 + test2 + test3 + test4 + test5) / 5.0;
outFile << "Average test score: " << setw(6)
<< average << endl;
inFile.close();
outFile.close();
return 0;
}

In the input file the input data is given in the image:

Output:


In the given code, we have to take the input from the file and make the required output and post the result in the another output file.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS