Question: C + + output isn't displaying the students grades beside their names when sorted alphabetically. Also, the class average is not working correctly. / /
C
output isn't displaying the students grades beside their names when sorted alphabetically. Also, the class average is not working correctly.
Function to sort names alphabetically
void sortNameschar names int numberOfStudents, int numberOfGrades const
char tempName; Temporary variable to assist in swapping names
int gradesnumberOfStudentsnumberOfGrades;
int tempGradesnumberOfGrades; Temporary array to swap grades
for int i ; i numberOfStudents ; i
for int j i ; j numberOfStudents; j
strcmp returns if namesi namesjie namesi is not in order
if strcmpnamesi namesj
Swap names to sort them alphabetically
strcpytempName namesi;
strcpynamesi namesj;
strcpynamesj tempName;
Swap grades to keep them aligned with the correct student name
for int k ; k numberOfGrades; k
tempGradesk gradesik;
gradesik gradesjk;
gradesjk tempGradesk;
Function to display sorted names
void displaychar names int numberOfStudents, int numberOfGrades const
int gradesnumberOfStudentsnumberOfGrades;
cout
output:
Enter the name of student : bee
Enter the name of student : ace
Enter the name of student : fred
Enter the name of student : hal
Enter the name of student : jey
Enter the name of student : bea
Enter the name of student : tee
Enter the name of student : see
Enter the name of student : dee
Enter the name of student : jay
Enter grades for bee:
Enter grades for ace:
Enter grades for fred:
Enter grades for hal:
Enter grades for jey:
Enter grades for bea:
Enter grades for tee:
Enter grades for see:
Enter grades for dee:
Enter grades for jay:
Displaying names of students in ascending order with their grades:
ace:
bea:
bee:
dee:
fred:
hal:
jay:
jey:
see:
tee:
Class Average: e
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
