Question: Will you check this? It's my attempt at this problem. Please post any corrections or comments. Thanks! You are given a file that contains the
Will you check this? It's my attempt at this problem. Please post any corrections or comments. Thanks!
You are given a file that contains the course number and the number of students enrolled in each course. You need to use a modular design to solve the problem. 1. Place the course numbers and enrollment in parallel arrays. 2. Print a listing of all course numbers and enrollments. 3. Calculate and print the total number of students in all classes. 4. Calculate and print the average number of students in the classes. 5. Print the class numbers and enrollments for classes with less than 10 students. 6. Print the class number and enrollment for the class with the highest enrollment.
Module main () Declare Constant Integer SIZE Declare Integer courseNumbers[SIZE] Declare Integer enrollment[SIZE] Declare Integer totalStudents
Call showClassEnrollment (Integer courseNumber[Size], Integer enrollment[SIZE], SIZE) Call calcTotal (Integer courseNumber[Size], Integer enrollment[SIZE], SIZE) Call calcAverage (Integer totalStudents) Call belowTen (Integer courseNumber[Size], Integer enrollment[SIZE], SIZE) Call getHighest (Integer courseNumber[Size], Integer enrollment[SIZE], SIZE)
Module showClassEnrollment (Integer courseNumber[Size], Integer enrollment[SIZE], SIZE) Declare Integer index For index = 0 To SIZE -1 Display The course, courseNumber[index], has, numberStudents[index], students. End For End Module
Function Integer calcTotal (Integer courseNumber[Size], Integer enrollment[SIZE], SIZE) Declare Integer index Declare Integer totalStudents = 0 For courseNumber[index] = 0 To SIZE -1 Set totalStudents = totalStudents + numberStudents[index] End For Display The total number of students in all classes is:, total Return totalStudents End Function
Module calcAverage (Integer totalStudents, SIZE) Declare Real average Set average = totalStudents / SIZE Display The average number of students in all classes is:, average, . End Module
Module belowTen (Integer courseNumber[Size], Integer enrollment[SIZE], SIZE) Declare Integer index For index = 0 To SIZE -1 If enrollment[index] < 10 Then Display The class, courseNumber[index] has less than 10 students. Display It has, enrollment[index], students. End If End For End Module Module getHighest (Integer courseNumber[Size], Integer enrollment[SIZE], SIZE) Declare Integer index Declare Integer highestEnrollement Declare Integer highestClass Set highestEnrollment = enrollment [0] For index = 1 To SIZE -1 If enrollment[index] > highestEnrollment Then Set highestEnrollment = enrollment[index] Set highestClass = courseNumber[index] End If End For Display The class with the most students is:, highestClass, with, highestEnrollment, Display students. End Module
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
