Question: Write a program that will read data from the file p6.dat. The file (that you will create) always contains 15 test scores (whole numbers between

Write a program that will read data from the file "p6.dat". The file (that you will create) always contains 15 test scores (whole numbers between 0 and 100). The test scores are scores for 5 students taking 3 tests, and are arranged, in the file, by the student - that is the first 3 numbers are the test scores for test 1, 2, and 3 for the first student, etc. The program will print: - average per student (5 averages), on a single line, with 2 decimals - average per test (3 averages), on a single line, with 2 decimals - overall best score on a single line - how many scores were As (out of the 15, how many were at least 90) on a single line To simplify the code, no validations are needed. That is, assume the file is successfully opened, and that all data are 0-100, and that there are exactly 15 numbers in the file. Note that the program reads the filename

I am having trouble creating the "p6.dat" file and writing the scores to it.

#include #include #include using namespace std;

int main() { const int STUDENTS = 5; const int TESTS = 3; int scores[STUDENTS][TESTS];

ifstream infile; string fName;

cout << "Enter the file name: "; cin >> fName;

infile.open(fName);

for(int i = 0; i < STUDENTS; i++) { for(int j = 0; j < TESTS; j++) { infile >> scores[i][j]; } }

cout << endl; for(int i = 0; i < STUDENTS; i++) { double sum = 0; for(int j = 0; j < TESTS; j++) { sum += scores[i][j]; }

double avg = sum / 5.0; printf("%.2f ", avg); }

cout << endl;

for(int j = 0; j < TESTS; j++) { double sum = 0; for(int i = 0; i < STUDENTS; i++) { sum += scores[i][j]; }

double avg = sum / 5.0; printf("%.2f ", avg); }

cout << endl; int high = scores[0][0]; int count90s = 0;

for(int i = 0; i < STUDENTS; i++) { for(int j = 0; j < TESTS; j++) { if(high < scores[i][j]) high = scores[i][j];

if(scores[i][j] >= 90) count90s++; } }

cout << high << endl; cout << count90s << endl << endl;

system("pause"); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!