Final answer:
This detailed answer provides a C++ program that reads scores from a file, calculates their total, average, and count, and writes the output to another file named with the user's last name.
Step-by-step explanation:
The following C++ program demonstrates how to read scores from a text file, calculate the total, average, and number of scores, and write the output to a file named with the user's last name.
#include
#include
#include
using namespace std;
int main() {
ifstream inputFile("Exercise13_3.txt");
ofstream outputFile("YourLastName.txt");
int score;
int total = 0;
int count = 0;
while (inputFile >> score) {
total += score;
count++;
}
inputFile.close();
if(count > 0) {
outputFile << "Your first and last name\\";
outputFile << "Number of grades = " << count << "\\";
outputFile << "Total of all grades = " << total << "\\";
outputFile << "Average grade = " << fixed << setprecision(1) << (total / static_cast(count)) << "\\";
}
outputFile.close();
return 0;
}
This program uses streams from the fstream library to read from and write to files, and includes components like while loops and basic file I/O operations. Modify "YourLastName.txt" with the actual last name and replace "Your first and last name" with the user's actual name.