# 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&#039; letter grade, and five single- dimensional arrays of four doubles to hold each student&#039;s set of test score. the program should allow the user to enter each student&#039;s name and his or her four test score. it should then calculate and display each student&#039;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.
#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);
int Maximum(int arrayofscores);
int AverageScore(int arrayofscores);
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;
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;
for(int i=0;i<ROWS;i++){
cout<<"ID: "<<students[i]<<", total
score:"<<CalculateStudentTotals(i,students)<<"
";
arrayofscores[i]=CalculateStudentTotals(i,students);
}
idHigh=students[Maximum(arrayofscores)];
idLow=students[Minimum(arrayofscores)];
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) {
int max=arrayofscores;
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) {
int min=arrayofscores;
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){
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!