Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could you please fix this program and make sure it runs you can put a link at th

ID: 3555187 • Letter: C

Question

Could you please fix this program and make sure it runs you can put a link at the bottom of the page to your code


// Two dimensional Array for reading stduents grades from teh input file
// Reads quiz scores for each student into the two-dimensional array grad
// A Maximum number of students is 35 and each student has 5 quizzes
// This computes the average score for each student and the average score for each quiz
// This displays the quiz scores and the averages and will output the information to a file

#include<iostream>
#include<iomanip>
#include<fstream>//for files io
#include<cstdlib>//for exit()
using namespace std;

const int NUMBER_STUDENTS = 35, NUMBER_QUIZZES = 5;

void compute_st_ave(const double grade[][NUMBER_QUIZZES],double st_ave[]);
//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES
//are the dimensions of the array grade. Each of teh indexed variables
//grade[st_num-1,quiz_num-1]contains the score for student st_num on quiz
//quiz_num.
//Postcondition:Each quiz_ave[quiz_num-1]contains the average for quiz number
//quiz_num.

void display(const int st_id[],const double grade[][NUMBER_QUIZZES],
const double st_ave[],const double quiz_ave[],ofstream& out_stream);
//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES are the
//dimensions of the array grade. Each of the inexed variables grade[st_num-1,
//quiz_num-1] contains the score for student st_num on quiz quiz_num. Each
//st_ave[st_num-1 contains the average for student stu_num. Each
//quiz_ave[quiz_num-1] contains the average for quiz number quiz_num.
//Postcondition:All the data in grade, st_ave, and quiz_ave has een output.

int main()
{
using namespace std;
int index;
char next_symbol;
double next;
//array declarations for grades, student id, student average, and quiz averages
double grade[NUMBER_STUDENTS][NUMBER_QUIZZES];
int st_id[NUMBER_STUDENTS];
double st_ave[NUMBER_STUDENTS];
double quiz_ave[NUMBER_QUIZZES];
//
//open file names for input and output
//
ifstream in;
ofstream out;
//This shows the class name, assignment name, student name, and the date
cout<<endl;
cout<<
"************************************************************************** ";
cout<<"Program is written to Compute Student's Average Grades ";
cout<<"Homework 6 CSC 175 ";
cout<<"By: on April 17th, 2014 ";
"************************************************************************** ";
//
//Check gpt rttpt pm go;r p[rm vp,,smfd smf og go;rd fp mpy p[rm yjrm rcoy
//
in.open("gradebook.txt");
if (out.fail())
{
cout<<"Failed to open the output file gradebook.txt ";
exit(1);
}
out.open("gradebook2.txt");
if (out.fail())
{
cout<<"Failed to open the output file gradebook2.txt ";
exit(1);

}
//
//Fill in the students ID array and the quiz grades:
//
//Uses iostream to get grades for one student
//
for (int st_num=1; st_num <= NUMBER_STUDENTS;st_num++)
{
next=0;
index=0;
//read in the student id number
in>>st_id[st_num - 1];
//read in all the quiz grades
do
{
in.get(next_symbol);//skip past the blank space or tab
//
//read in all grades for quizes until array limit is reached or new line is found
//
while (index<NUMBER_QUIZZES)
{
in>>next;
grade[st_num-1][index]=next;
index++;
}
}

//
//compute the student average and quiz average
//
compute_st_ave(grade,st_ave);
compute_quiz_ave(grade,quiz_ave);
//
//Generate output to screen and file
//
display(st_id,grade,st_ave,quiz_ave,out);
//
//Close files
//
in.close();
out.close();
return 0;
}
void compute_st_ave(const double grade[][NUMBER_QUIZZES],double st_ave[])
{
for (int st_num = 1; st_num<=NUMBER_STUDENTS;st_num++)
{//process one st_num:
double sum=0;
for(int quiz_num=1;quiz_num <=NUMBER_QUIZZES; quiz_num++)
sum=sum + grade[st_num-1][quiz_num-1];
//sum contains the sum of the quiz scores for student number st_num.
st_ave[st_num-1] = sum/NUMBER_QUIZZES;
//Average for student st_num is the value of st_ave[st_num-1]
}


}
void compute_quiz_ave(const double grade[][NUMBER_QUIZZES],double quiz_ave[])
{
for (int quiz_num=1; quiz_num<=NUMBER_QUIZZES;quiz_num++)
{//Process one quiz(for all students):
double sum=0;
for (int st_num = 1;st_num<=NUMBER_STUDENTS;st_num++)
sum=sum +grade[st_num-1][quiz_num-1];
//sum contains the sum of all student scores on quiz number quiz_num.
quiz_ave[quiz_num-1]= sum/NUMBER_STUDENTS;
//Average for quiz quiz_num is the value of quiz_ave[quiz_num-1]

}
}
//Uses iostream and iomanip:
void display (const int st_id[],const double grade[][NUMBER_QUIZZES],
const double st_ave[],const double quiz_ave[],ofstream&out_stream)
{
using namespace std;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<setw(15)<<"Student"
<<setw(5)<<" Ave"
<<setw(35)<<"Quizzes ";
out_stream<<setw(15)<<"student"
<<setw(5)<<" Ave"
<<setw(35)<<"Quizzes ";

for (int st_num = 1;st_num<=NUMBER_STUDENTS;st_num++)
{
//Display for one st_num:
cout<<setw(15)<<st_id[st_num-1]<<" "
<<setw(5)<<st_ave[st_num-1]<<" ";
out_stream<<setw(15)<<st_id[st_num-1]<<""
<<setw(5)<<st_ave[st_num-1]<<"";
for (int quiz_num + 1; quiz_num <=NUMBER_QUIZZES;quiz_num++)
{
cout<<setw(10)<<grade[st_num-1][quiz_num-1];
out_stream<<setw((10))<<grade[st_num-1][quiz_num-1];
}
cout<<endl;
out_stream<<endl;
}
cout <<" Quiz averages=";
out_stream<<" Quiz averages=";
for (int quiz_num=1; quiz_num<= NUMBER_QUIZZES;quiz_num++)
{
cout<<setw(10)<<quiz_ave[quiz_num-1];
out_stream<<setw(10)<<quiz_ave[quiz_num-1];
}
cout<<endl;
}

Explanation / Answer

// Two dimensional Array for reading stduents grades from teh input file
// Reads quiz scores for each student into the two-dimensional array grad
// A Maximum number of students is 35 and each student has 5 quizzes
// This computes the average score for each student and the average score for each quiz
// This displays the quiz scores and the averages and will output the information to a file
#include<iostream>
#include<iomanip>
#include<fstream>//for files io
#include<cstdlib>//for exit()
using namespace std;
const int NUMBER_STUDENTS = 35, NUMBER_QUIZZES = 5;

void compute_st_ave(double grade[][NUMBER_QUIZZES],double st_ave[]);
//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES
//are the dimensions of the array grade. Each of teh indexed variables
//grade[st_num-1,quiz_num-1]contains the score for student st_num on quiz
//quiz_num.
//Postcondition:Each quiz_ave[quiz_num-1]contains the average for quiz number
//quiz_num.
void display(const int st_id[],const double grade[][NUMBER_QUIZZES],
const double st_ave[],const double quiz_ave[],ofstream& out_stream);
//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES are the
//dimensions of the array grade. Each of the inexed variables grade[st_num-1,
//quiz_num-1] contains the score for student st_num on quiz quiz_num. Each
//st_ave[st_num-1 contains the average for student stu_num. Each
//quiz_ave[quiz_num-1] contains the average for quiz number quiz_num.
//Postcondition:All the data in grade, st_ave, and quiz_ave has een output.
void compute_quiz_ave(const double grade[][NUMBER_QUIZZES],double quiz_ave[])
{
for (int quiz_num=1; quiz_num<=NUMBER_QUIZZES;quiz_num++)
{//Process one quiz(for all students):
double sum=0;
for (int st_num = 1;st_num<=NUMBER_STUDENTS;st_num++)
sum=sum +grade[st_num-1][quiz_num-1];
//sum contains the sum of all student scores on quiz number quiz_num.
quiz_ave[quiz_num-1]= sum/NUMBER_STUDENTS;
//Average for quiz quiz_num is the value of quiz_ave[quiz_num-1]
}
}


int main()
{
using namespace std;
int index;
char next_symbol;
double next;
//array declarations for grades, student id, student average, and quiz averages
double grade[NUMBER_STUDENTS][NUMBER_QUIZZES];
int st_id[NUMBER_STUDENTS];
double st_ave[NUMBER_STUDENTS];
double quiz_ave[NUMBER_QUIZZES];
//
//open file names for input and output
//
ifstream in;
ofstream out;
//This shows the class name, assignment name, student name, and the date
cout<<endl;
cout<<
"************************************************************************** ";
cout<<"Program is written to Compute Student's Average Grades ";
cout<<"Homework 6 CSC 175 ";
cout<<"By: on April 17th, 2014 ";
"************************************************************************** ";
//
//Check gpt rttpt pm go;r p[rm vp,,smfd smf og go;rd fp mpy p[rm yjrm rcoy
//
in.open("gradebook.txt");
if (out.fail())
{
cout<<"Failed to open the output file gradebook.txt ";
exit(1);
}
out.open("gradebook2.txt");
if (out.fail())
{
cout<<"Failed to open the output file gradebook2.txt ";
exit(1);
}
//
//Fill in the students ID array and the quiz grades:
//
//Uses iostream to get grades for one student
//
for (int st_num=1; st_num <= NUMBER_STUDENTS;st_num++)
{
next=0;
index=0;
//read in the student id number
in>>st_id[st_num - 1];
//read in all the quiz grades
do
{
in.get(next_symbol);//skip past the blank space or tab
//
//read in all grades for quizes until array limit is reached or new line is found
//

{
in>>next;
grade[st_num-1][index]=next;
index++;
}
}while (index<NUMBER_QUIZZES);
}

//
//compute the student average and quiz average
//
compute_st_ave(grade,st_ave);
compute_quiz_ave(grade,quiz_ave);
//
//Generate output to screen and file
//
display(st_id,grade,st_ave,quiz_ave,out);
//
//Close files
//
in.close();
out.close();
return 0;
}
void compute_st_ave(double grade[][NUMBER_QUIZZES],double st_ave[])
{
for (int st_num = 1; st_num<=NUMBER_STUDENTS;st_num++)
{//process one st_num:
double sum=0;
for(int quiz_num=1;quiz_num <=NUMBER_QUIZZES; quiz_num++)
sum=sum + grade[st_num-1][quiz_num-1];
//sum contains the sum of the quiz scores for student number st_num.
st_ave[st_num-1] = sum/NUMBER_QUIZZES;
//Average for student st_num is the value of st_ave[st_num-1]
}
}
//Uses iostream and iomanip:
void display (const int st_id[],const double grade[][NUMBER_QUIZZES],
const double st_ave[],const double quiz_ave[],ofstream&out_stream)
{
using namespace std;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<setw(15)<<"Student"
<<setw(5)<<" Ave"
<<setw(35)<<"Quizzes ";
out_stream<<setw(15)<<"student"
<<setw(5)<<" Ave"
<<setw(35)<<"Quizzes ";
for (int st_num = 1;st_num<=NUMBER_STUDENTS;st_num++)
{
//Display for one st_num:
cout<<setw(15)<<st_id[st_num-1]<<" "
<<setw(5)<<st_ave[st_num-1]<<" ";
out_stream<<setw(15)<<st_id[st_num-1]<<""
<<setw(5)<<st_ave[st_num-1]<<"";
for(int quiz_num=1; quiz_num <=NUMBER_QUIZZES;quiz_num++)
{
cout<<setw(10)<<grade[st_num-1][quiz_num-1];
out_stream<<setw((10))<<grade[st_num-1][quiz_num-1];
}
cout<<endl;
out_stream<<endl;
}
cout <<" Quiz averages=";
out_stream<<" Quiz averages=";
for (int quiz_num=1; quiz_num<= NUMBER_QUIZZES;quiz_num++)
{
cout<<setw(10)<<quiz_ave[quiz_num-1];
out_stream<<setw(10)<<quiz_ave[quiz_num-1];
}
cout<<endl;
}