In: Computer Science
***USING C++***
(a) Write a program that reads a text file in which each line in the file consists of a first name, a last name, following by 4 grades (double types) like Tim Hanes 78.3 98.0 80.5 72.3 The program must read every line of the text file, find the average of the 4 grades then print the names followed by the averages (one name per line) in a second file as well as on the monitor. Create the text file with at least 5 entries with the format given in part (a). Give the absolute path of the file in your computer. Test your program in part 2(a) on this file.
#include <fstream>
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
ifstream inFile;
char filename[20];
cout<<"Enter The File Name With Extension\n";
cin>>filename;
inFile.open(filename);
/*Here You Have To Create A File And put some data on it.
Then Save the with Any Extension With File Name As Above Shown
*/
if (!inFile)
{
cerr << "File example.txt not found." << endl;
return -1;
}
ofstream outFile("sum.txt");
/*Here You Have Sum Of File Line By Line Sum */
string line;
while (getline(inFile, line))
{
if (line.empty())
continue;
istringstream iss(line);
float sum = 0, next = 0;
while (iss >> next)
sum += next;
cout<<sum
outFile << sum << endl;
}
inFile.close();
outFile.close();
cout<<"File Created Successfully Go To Sum.txt File And
Open\n";
return 0;
}