Suppose that a text file Exercise13_3.txt contains an unspecified number of scores.Write a c++ program that reads the scores from the file and display their total and average.Scores are seperated by blanks.

Instead of displaying the results on the screen, send the results to an output named using your last name.

In addition to finding the average and total, find the number of grades.

Input

Example: Contents of Exercise13_3.txt:

70 88 91 95

66 82 71 99 84 57

80 100 93 73 82

Output

Contents of YourLastName.txt:

Your first and last name

Number of grades = 16

Total of all grades = 1231

Average grade = 82.1

Respuesta :

Answer:

#include <iostream>

#include <cmath>

#include <math.h>

#include <fstream>

#include <string>

#include <numeric>

using namespace std;

int main()

{

ifstream infile;

float num;

float total;

float x;

float aver;

x=0; total=0;

infile.open("Exercise13_3.txt");

while(!infile.eof())

{

infile>>num;

total=total+num;

x++;

}

aver=(total-num)/(x-1);

cout << "Number of grades = " <<x<< "\n";

cout<< "Total of all grades = " <<total<<'\n';

cout<< "Average grade = "<<aver<<'\n';

cout<< ""<<'\n';

infile.close();

getchar();

return 0;

}

ACCESS MORE