Problem An instructor has a list of marks representing the scores of students in
ID: 3621552 • Letter: P
Question
ProblemAn instructor has a list of marks representing the scores of students in a test. Each line contains a student id (integer) followed by an integer score in the range 0-100. The last line contains the number -9999.
Sample Data
5000 45
4000 32
1000 75
-9999
Requirements
(a) Write algorithms to read the data and find and print
- The average mark in the exam
- The ID of the student who scored the highest if the highest is unique. If more than one student scored the highest mark, print all of their IDs.
(b) Write an algorithm to print a list of all students with IDs in the range 4000-7000 and the score each obtained.
(c) Clearly explain the main steps.
Explanation / Answer
struct student { char firstName[20]; char lastName[20]; double grade; int ID; } ; typedef struct student Student; int main () { double average; // Create three students Student Luke, Leia; struct student R2D2; // Fill up each of the students with information strcpy(Luke.firstName, "Luke"); strcpy(Luke.lastName, "Skywalker"); Luke.grade = 98.6; Luke.ID = 1977; strcpy(Leia.firstName,"Princess"); strcpy(Leia.lastName,"Leia"); Leia.grade = 69.37; Leia.ID = 1978; strcpy(R2D2.firstName,"R2D2"); strcpy(R2D2.lastName,"Robot"); R2D2.grade = 90.0; R2D2.ID = 1979; // Calculate the average credit hours of the students average = (Leia.grade + Luke.grade + R2D2.grade) / 3.0; // Print out some stuff printf ("Their average grade is %.4lf ",average); return 0; } This is how we find the average grade... to find the highest grade, we would use a bubble sort to put the grades in order, then we would take the highest grade and display it along with the ID of the student. To print a list of students with their IDs in range, we would use a if statement to compare all ids one at a time. if id is in range, display name to screen and go to next id, if id is not in range, go to the next id (we can leave the list sorted as we did in the bubble sort so the names are displayed in order by id number) hope this is helpful :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.