Calculates the student * averages and quiz averages based upon input from the us
ID: 3553908 • Letter: C
Question
Calculates the student * averages and quiz averages based upon input from the user. Modify this program to read in the following grade text file, * with a maximum number of students set to 35 and having five quiz scores for each student. The output should be displayed to both the console and the output file. Please submit the output file created by the program with the C++ source code and executable ...Copy paste the program into the answer area make sure you post small discrepitions of what is happening
Explanation / Answer
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream myfile;
int n,n1;
cout<<"NAME: XYZ HOMEWORK NO: 2 DATE:03/04/2014"<<endl;
cout<<"enter no of students"<<endl;
cin>>n1;
float temp;
float quiz[n1];
cout<<"Enter marks of all student in all 5 quizes "<<endl;
for(int i=0;i<n1;i++)
{
quiz[i]=0;
for(int j=0;j<5;j++)
{
cout<<"Enter marks of student no "<<i+1<<" in quiz no "<<j+1<<": ";
cin>>temp;
cout<<" "<<endl;
quiz[i]+=temp;
}
quiz[i]=quiz[i]/5;
}
cout<<"The average marks of all student in all 5 quizes are "<<endl;
for(int j=0;j<n1;j++)
{
cout<<"Average of marks of student no "<<j+1<<" in all quizes is "<<quiz[j]<<endl;
}
cout<<" The average values of all students (values taken from an external file) are"<<endl;
myfile.open ("input.txt");//taking input from a file
myfile>>n; //no of students
float data;
float sum;
ofstream ifile;//output file
ifile.open ("output.txt");
ifile<<" The average values of all students are"<<endl;
for (int i=0;i<n;i++)
{
sum=0;
for(int j=0;j<5;j++)
{
myfile>>data;
sum+=data;
}
sum=sum/5;//creating average of each student
cout<<"Student "<<i+1<<" is "<<sum<<endl;//writing average to an console
ifile<<"Student "<<i+1<<" is "<<sum<<endl;//writing average to an output file
}
myfile.close();
ifile.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.