Question

This output should also be printed to the screen. An Array Program for Grading Utilizing Data...

This output should also be printed to the screen.

An Array Program for Grading Utilizing Data Files

Create 2 text files:

  • The first will be a “settings” file – Arrange this file so that it has two numbers on separate lines – the first number will represent the number of students in this class (25). The second number will represent the total number of points on a fictional “exam”
  • The second text file will be 25 “scores” for the test. These can be arranged on one line or with a new line for each...

Create a program that:

  • Reads the values from the “settings” file for how many students and total points for the test
  • Reads the values for the student’s scores into an array from the data file
  • Calculates the average for each student on the test
  • Creates an output file that prints a line for each student that shows the following:

Student 1 – 55 out of 100 – 55%

Student 2 – 87 out of 100 – 87%

Student 3 – 98 out of 100 – 98%

.

.

Average Score: 86.2%

This output should also be printed to the screen.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Source Code in C++:

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ifstream in("settings.txt"); //opening file for input
if(in.is_open())
{
int n,total;
in >> n >> total;
ifstream in("scores.txt"); //opening file for input
if(in.is_open())
{
ofstream out("scoresAverage.txt"); //opening file for output
int scores[n],i;
for(i=0;i<n;i++)
in >> scores[i];
double totalAv=0.0;
for(i=0;i<n;i++)
{
double av=scores[i]*100.0/total;
out << "Student " << i+1 << " - " << scores[i] << " out of " << total << " - " << av << "%" << endl; //output to file
cout << "Student " << i+1 << " - " << scores[i] << " out of " << total << " - " << av << "%" << endl; //output to screen
totalAv+=av;
}
out << "Average Score: " << totalAv/n << "%" << endl; //output to file
cout << "Average Score: " << totalAv/n << "%" << endl; //output to screen
}
else
cout << "Cannot open scores file"; //error message
}
else
cout << "Cannot open settings file"; //error message
return 0;
}

Output to screen:

Output to file:

Add a comment
Know the answer?
Add Answer to:
This output should also be printed to the screen. An Array Program for Grading Utilizing Data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT