English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm a little confused on my programming design homework. The problem states:

An elementay school contains 30 classrooms numbered 1 through 30. Each classroom can contain any number of students up to 35. Each student takes an achievement test at the end of the school year and receives a score from 1 through 100. One record is created for each student in the school; each record contains a student ID, classroom number, and score on the achievement test. Design the logic for a program that lists the total points scored for each of the 30 classroom groups.

I'm wondering, will there be three different arrays? One for the classrooms, one for the students, and one for the scores? Any tips on how to write the pseudocode would be very helpful and very much appreciated.

2007-06-04 17:29:47 · 3 answers · asked by novelgirl 1 in Computers & Internet Programming & Design

3 answers

You only need one array of 30 elements to represent the number of classrooms.
Because you only have to find the total scores for each classroom. You do not need to store any other information.

There are two solutions to this depending on whether you want to do this easily or complex and save memory.

Complex
1) Define an array of 30 elements.
For each student record
add studentScore to classRoomArray[studentClass - 1]
end-for
print title
print array

Easy
2) Define an array of 31 elements.
For each student record
add studentScore to classRoomArray[studentClass]
end-for
print title
print array elements 1 to 30

2007-06-04 21:32:55 · answer #1 · answered by AnalProgrammer 7 · 0 0

Here's what I would do:
1. Very Object Oriented Style:
School class with array of classroom objects
Classroom class with array of child objects
Student class with array of student objects

Student will have accessor methods for the ID, clasroom number and score.
Classroom will have a method to calculate the total points score for all Student objects in classroom.

2. Less Object-Oriented:
Array of arrays with first array representing classrooms and second array representing each student which would be a Student object.

2007-06-04 18:51:32 · answer #2 · answered by zachwass2000 2 · 0 0

There can, but not necessarily, be only one array to store all students from the school. There must also be another array to store the results. This array is the array for classrooms.

for(i=1; i<=numOfStudents; i++) {
// identify the class he belongs to
int class_num = student[i].getClassNum( );

// add his score to the class room total
classScores[class_num] = classScores[class_num] + student[i].getScore( );
}

2007-06-04 22:18:40 · answer #3 · answered by JR 2 · 0 0

fedest.com, questions and answers