63 151
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #24466 in C++ for kalpesh

Question #24466
A teacher has five students who have taken four tests. the teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four test scores...

test score letter grade
90-100 A
80-89 B
70-79 C
60-69 D
0-59 F

write a program that using two-dimensional array of character to hold the five student names. a single-dimensional array of five characters to hold the five students' letter grade, and five single- dimensional arrays of four doubles to hold each student's set of test score.

the program should allow the user to enter each student's name and his or her four test score. it should then calculate and display each student's average test score and a letter grade based on the average.

input validation : do not accept test scores less than 0 or grater than 100.
Expert's answer
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <conio.h>
using namespace std;

const int COLUMNS = 7;
const int TOT_COL = COLUMNS - 1;

int CalculateStudentTotals(int row, int students[][COLUMNS]);
int Minimum(int arrayofscores[5]);
int Maximum(int arrayofscores[5]);
int AverageScore(int arrayofscores[5]);
int main()
{
const int ROWS = 5;
int students[ROWS][COLUMNS];
int idHigh, idLow,average;
bool haveData;
int countforrow=0;
int countforcolumn=0;
string line;
ifstream inFile;
int countofline=0;
inFile.open("scores.txt");
if (!inFile){
cout << "Could not open file." << endl;
return false;
}
else{

while (inFile.good()){
countforcolumn=0;
getline (inFile,line);//read each lines
char* cstr = new char [line.size()+1];
strcpy (cstr, line.c_str());
char* pch= strtok(cstr," ");
while (pch != NULL)
{
//cout<<pch<<"
";
students[countforrow][countforcolumn]=atoi(pch);
pch = strtok (NULL, " ");
countforcolumn++;

}
countforrow++;

}
inFile.close();//cloe file
}
int arrayofscores[5];
for(int i=0;i<ROWS;i++){
cout<<"ID: "<<students[i][0]<<", total
score:"<<CalculateStudentTotals(i,students)<<"
";
arrayofscores[i]=CalculateStudentTotals(i,students);
}
idHigh=students[Maximum(arrayofscores)][0];
idLow=students[Minimum(arrayofscores)][0];
average=AverageScore(arrayofscores);
cout<<"
";
cout<<"Student with highest score:
"<<idHigh<<"
";
cout<<"Student with lowest score:
"<<idLow<<"
";
cout<<"Average score: "<<average<<"
";
cout<<"Press any key to exit...";
getch();
return 0;
}

int CalculateStudentTotals(int row, int students[][COLUMNS]){
int sum=0;
for(int j=1;j<6;j++){
sum+=students[row][j];
}
return sum;
}

int Maximum(int arrayofscores[5]) {
int max=arrayofscores[0];
int id=0;
for(int i=0;i<5;i++){
if(arrayofscores[i]>max){
max=arrayofscores[i];
id=i;
}
}
return id;
}

int Minimum(int arrayofscores[5]) {
int min=arrayofscores[0];
int id=0;
for(int i=0;i<5;i++){
if(arrayofscores[i]<min){
min=arrayofscores[i];
id=i;
}
}
return id;
}


int AverageScore(int arrayofscores[5]){
int sum=0;
for(int i=0;i<5;i++){
sum+=arrayofscores[i];
}
return sum/5;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions