This output should also be printed to the screen.
An Array Program for Grading Utilizing Data Files
Create 2 text files:
Create a program that:
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.
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:

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