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

Assignment – Compute Test Score Grades using array of Structures You are asked t

ID: 3908102 • Letter: A

Question

Assignment – Compute Test Score Grades using array of Structures                                                        

You are asked to write a program that will compute the grades for each student’s test score, number of students passed the score and the test score average. Test scores and grades will be stored in an array of structures-students. The score average is rounded to one digit after decimal point.

There are 5 students and NUM_STUDENTS is defined as a constant.

The element of the array-students has the following members:

struct studentInfo {

string id;

int score;

char grade;

};

            studentInfo students[NUM_STUDENTS]; //array of structures declaration

The grades are assigned based on the following table.

                       

                                    Score               Grade

                                    90 - 100              A

                                    80 - 89               B

                                    70 - 79               C

                                    60 - 69               D

                                    0   - 59               F

Use the following functions to perform different tasks.

//Function getScore is used to enter student id, test score

getData (students, NUM_STUDENTS);

//Function computeGrade will determine the grade for each student and store the grade

computeGrade (students, NUM_STUDENTS);    

//Function pass will determine and return the number of passing scores.

//A score greater than or equal to 60 is considered a passing score.

numberPasses = pass (students, NUM_STUDENTS);

//Function findAverage will compute average of test scores and return the test score //average

averageScore = find_Average (students, NUM_STUDENTS);

//Function printSummary will print the output as shown.

printSummary (students, numberPasses, averageScore, NUM_STUDENTS);

The output will be displayed as follows:

                        ID                     Score               Grade

                        123                  90                    A

                        345                  60                    D

                        333                  70                    C

                        678                  59                    F

                        555                  87                    B

                       

                        Number of students passed the test: 4

                       

                        The test score average:          73.2     (rounded to one digit after decimal point)

Explanation / Answer

#include <iostream>
using namespace std;

int NUM_STUDENTS=5;

struct studentInfo {
string id;
int score;
char grade;
};

//Function getScore is used to enter student id, test score
void getData (studentInfo students[], int NUM_STUDENTS);
//Function computeGrade will determine the grade for each student and store the grade
void computeGrade (studentInfo students[], int NUM_STUDENTS);  
int pass (studentInfo students[], int NUM_STUDENTS);
double find_Average (studentInfo students[], int NUM_STUDENTS);
void printSummary (studentInfo students[], int numberPasses, double averageScore, int NUM_STUDENTS);


int main() {

studentInfo students[NUM_STUDENTS]; //array of structures declaration

getData(students,NUM_STUDENTS);

computeGrade(students,NUM_STUDENTS);


int numberPasses = pass(students, NUM_STUDENTS);


double averageScore = find_Average (students, NUM_STUDENTS);


printSummary (students, numberPasses, averageScore, NUM_STUDENTS);

return 0;
}

void getData(studentInfo students[], int NUM_STUDENTS)
{
for(int i=0;i<NUM_STUDENTS;i++)
{
cout<<" Enter id and score : ";
cin>>students[i].id>>students[i].score;
}
}
void computeGrade (studentInfo students[], int NUM_STUDENTS)
{
for(int i=0;i<NUM_STUDENTS;i++)
{
if(students[i].score >= 90 && students[i].score <=100)
students[i].grade= 'A';
else if(students[i].score >= 80 && students[i].score <=89)
students[i].grade= 'B';
else if(students[i].score >= 70 && students[i].score <=79)
students[i].grade= 'C';
else if(students[i].score >= 60 && students[i].score <=69)
students[i].grade= 'D';
else if(students[i].score >= 0 && students[i].score <=59)
students[i].grade= 'F';
}
}
int pass (studentInfo students[], int NUM_STUDENTS)
{
int passCount = 0;
for(int i=0;i<NUM_STUDENTS;i++)
{
if(students[i].grade != 'F')
passCount++;
}
return passCount;
}

double find_Average (studentInfo students[], int NUM_STUDENTS)
{
double avg = 0.0;
for(int i=0;i<NUM_STUDENTS;i++)
{
avg = avg+ students[i].score;
}
return avg/NUM_STUDENTS;
}

void printSummary (studentInfo students[], int numberPasses, double averageScore, int NUM_STUDENTS)
{
cout<<" ID Score Grade";
for(int i=0;i<NUM_STUDENTS;i++)
{
cout<<" "<<students[i].id<<" "<<students[i].score<<" "<<students[i].grade;
}
cout<<" Number of students passed the test: "<<numberPasses;
cout<<" The test score average: "<<averageScore;

}

Output:


Enter id and score :123 90
Enter id and score :345 60
Enter id and score :333 70
Enter id and score :678 59
Enter id and score :555 87
ID Score Grade
123 90 A
345 60 D
333 70 C
678 59 F
555 87 B

Number of students passed the test: 4
The test score average: 73.2

Do ask if any doubt. Please upvote.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote