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

//header section #include <iostream> #include <fstream> #include <iomanip> using

ID: 3627068 • Letter: #

Question

//header section

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

//student structure

struct Student

{

long studentID;

double hwAve;

double testAve;

double finalScore;

double testScore[2];

double homeWorkScore[7];

char grade;

};

//prototypes

int getInput ( Student []);

void process ( Student [], int );

void display ( Student [], int );

fstream input,output;

//main function

int main()

{

struct Student std[30];

input.open("", ios::in);

int n=getInput(std);

process(std,n);

display(std,n);

system("pause");

return(0);

}

//method definitions

int getInput(Student std[])

{int i;

for(i=0;i<30;i++)

{

if(!input.eof())

{

input>>std[i].studentID;

for(int h=0;h<2;h++)

input>>std[i].testScore[h];

for(int t=0;t<7;t++)

input>>std[i].homeWorkScore[t];

}

else

break;

}

return(i);

}

void process ( Student std[], int n)

{

for(int i=0;i<n;i++)

{

std[i].testAve=(std[i].testScore[0]+std[i].testScore[1])/2;

std[i].hwAve=0;

for(int j=0;j<7;j++)

std[i].hwAve +=std[i].homeWorkScore[j];

std[i].hwAve =(std[i].hwAve/265)*100;

std[i].finalScore=(std[i].hwAve+std[i].testAve)/2;

if(std[i].finalScore>=90)

std[i].grade='A';

else if(std[i].finalScore<90&&std[i].finalScore>=80)

std[i].grade='B';

else if(std[i].finalScore<80&&std[i].finalScore>=70)

std[i].grade='C';

else if(std[i].finalScore<70&&std[i].finalScore>=60)

std[i].grade='D';

else std[i].grade='E';

}

}

void display(Student std[],int n)

{

cout<<setprecision(2);

int aC=0,bC=0,cC=0,dC=0,eC=0;

output.open("prg5out.txt",ios::out);

cout<<"STUDENT ID HWAVE TEST AVE FINAL SCORE GRADE ";

for(int i=0;i<n;i++)

{

cout<<std[i].studentID<<" "<<std[i].hwAve<<" "<<std[i].testAve<<" "<<std[i].finalScore<<" "<<std[i].grade<<endl;

output<<std[i].studentID<<" "<<setprecision(2)<<std[i].hwAve<<" "<<setprecision(2)<<std[i].testAve<<" "<<setprecision(2)<<std[i].finalScore<<" "<<std[i].grade<<endl;

switch(std[i].grade)

{

case 'A':aC++;break;

case 'B':bC++;break;

case 'C':cC++;break;

case 'D':dC++;break;

case 'E':eC++;break;

}

}

cout<<"Number of A's:"<<aC<<endl;

cout<<"Number of B's:"<<bC<<endl;

cout<<"Number of C's:"<<cC<<endl;

cout<<"Number of D's:"<<dC<<endl;

cout<<"Number of E's:"<<eC<<endl;

}

Explanation / Answer

/* Dear friend, There is only a very small mistake in your code.You have not give the name of input file.Just give it there, it will run perfectly.Here is your code again with input file. */ //header section #include #include #include using namespace std; //student structure struct Student { long studentID; double hwAve; double testAve; double finalScore; double testScore[2]; double homeWorkScore[7]; char grade; }; //prototypes int getInput ( Student []); void process ( Student [], int ); void display ( Student [], int ); fstream input,output; //main function int main() { struct Student std[30]; input.open("prg5data.txt", ios::in); // Here you have to give the name of the input file int n=getInput(std); process(std,n); display(std,n); return(0); } //method definitions int getInput(Student std[]) {int i; for(i=0;i>std[i].studentID; for(int h=0;h>std[i].testScore[h]; for(int t=0;t>std[i].homeWorkScore[t]; } else break; } return(i); } void process ( Student std[], int n) { for(int i=0;i