Question: my code: #include #include #include #include using namespace std; struct studentData { string studentFName; //student first name string studentLName; //student last name int testScore; char

my code:

#include #include #include #include using namespace std;

struct studentData { string studentFName; //student first name string studentLName; //student last name int testScore; char grade; }; studentData arr_stud[20];//an array of student to hold details of 20 students

void readData(ifstream&, studentData arr_stud[]) { ifstream infile; infile.open("Studentdata.txt"); int i = 0;

if (infile.fail()) { cout << "file contain error"; exit(0); } else if (!infile.eof()) { for (int i = 0;i < 20;i++) {

infile >> arr_stud[i].studentFName; infile >> arr_stud[i].studentLName; infile >> arr_stud[i].testScore; } } }

//function declaration to find highest score(max) int find_Highest_Score(studentData arr_stud[]) { int max = 0; //this function will help us find the highest score for(int i = 0;i < 20;i++) { if (arr_stud[i].testScore > max) { max = arr_stud[i].testScore; } } return max;

}

//function declarartion to assign grade according to the testScore achieved void assign_Grade(studentData arr_student[]) { for (int i = 0;i < 20;i++) { // if score is greater than or equals to 90,Student received "A" grade if (arr_stud[i].testScore >= 90 && arr_stud[i].testScore<=100) { arr_stud[i].grade = 'A'; } else if (arr_stud[i].testScore >= 80) { arr_stud[i].grade = 'B'; } else if (arr_stud[i].testScore >= 70) { arr_stud[i].grade = 'C'; } else if (arr_stud[i].testScore >= 60) { arr_stud[i].grade = 'D'; } else if (arr_stud[i].testScore >= 50) { arr_stud[i].grade = 'F'; } }

} // Function declaration for print data of students and max scores of student void printData( studentData arr_stud[20], int max) { cout << "Student Name\t\t\t\t"; cout << "Test Score\t\t"; cout << "Grade" << endl;

for (int i = 0;i < 20;i++) { cout << arr_stud[i].studentLName << " ," << setw(10) << arr_stud[i].studentFName << "\t\t\t" << setw(15) << left << arr_stud[i].testScore << "\t\t"<

cout << endl << endl; cout << "Highest testScore achieved of the students: " << max << endl; cout << "Name of the students having highest scores are: " << endl; // this is a for loop for siolaying which student is having a highest score(max) for (int i = 0;i < 20;i++) { if (arr_stud[i].testScore == max) { cout << arr_stud[i].studentLName << "," << arr_stud[i].studentFName <<" "<

} cout << "Good job! keep it up" << endl; }

int main(int argc, char** argv) { //opening input file ifstream infile; infile.open("Studentdata.txt");

//dcelaring an array of structure for students studentData arr_stud[20];

//calling all the function prototypes readData(infile, arr_stud); find_Highest_Score(arr_stud); assign_Grade(arr_stud); int max = find_Highest_Score(arr_stud); printData(arr_stud,max);

infile.close(); return 0;

} output:(i don't know why output is not displaying grades)

Smith ,Jon 85 Hope ,Bob 83 White ,Barbara 99 Thompson ,Timothy 75 Barker ,Bob 84 Dix ,Kathleen 77 Howard ,Joelle 98 Chingwa ,Michelle 100 Harris ,Jeanette 75 Kishigo ,Doris 99 Favela ,Marina 68 Roe ,Kimberly 76 Little ,Eliza 80 Awnemequom ,Amelia 87 Hatchett ,Terri 70 Joneson ,Joan 73 Smith ,Anna 72 Bulgarelli ,Celia 81

Highest testScore achieved of the students: 100 Name of the students having highest scores are: O'Brien,Thomas 100 Chingwa,Michelle 100

Good job! keep it up

question:

he program should read in the data till end of file is found (or the maximum students is reached) and then process the data as described here. The program should output each students name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score.

Student data should be stored in an array of structures. The structure should contain the following members; studentFName and studentLName of type string, testScore of type int , and grade of type char . Suppose that the class has 20 students. The array should be 20 elements long. Try to use exception handling in the event invalid data is found while reading the data file.

Your program must contain at least the following functions:

  • A function to read the students data into the structure array from a data file
  • A function to assign the relevant grade to each student.
  • A function to find the highest test score.
  • A function to print the names of the students having the highest test score.

Your program must output each students name in this form: last name followed by a comma, followed by a space, followed by the first name; the name must be left justified. Moreover, other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls.

You create your test data text file but it should be no more than 20 rows of data which have 2 names and a test score. It may look something like this:

The program should read in the data till end of file is found (or the maximum students is reached) and then process the data as described here. The program should output each students name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score.

input file:

ames Dean 95

Thomas O'Brien 100

Jon Smith 85

Bob Hope 83

Barbara White 99

Timothy Thompson 75

Bob Barker 84

Kathleen Dix 77

Joelle Howard 98

Michelle Chingwa 100

Jeanette Harris 75

Doris Kishigo 99

Marina Favela 68

Kimberly Roe 76

Eliza Little 80

Amelia Awnemequom 87

Terri Hatchett 70

Joan Joneson 73

Anna Smith 72

Celia Bulgarelli 81

my question is : please help me fix that why my grade is not dispalying

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!