We have the following task:
Discuss the solution
#Pseudocode #Declare array of size 10 Array_Name[1:10] #Put value 10 in the first #position Array_Name[1] <- 10 #Access value in first pos PRINT Array_Name[1]
#Python #Initialize array of size 10 and zero all elements ArrName = [0 for i in range(10)] #Access item in the first position #Note Python array index starts with 0 ArrName[0] = 10 print(ArrName[0]) #Access the value in zero
Enter student name 1: Jimmy Enter student name 2: Amy ... Students: Jimmy Amy ...
Enter student name: Jimmy Enter Score of Jimmy: 45 ... Results: Jimmy 45 Amy 86 ...
... Results: Jimmy: 45 Amy: 86 ... Amy, who got 86 points, is the highest Class average score is 72
Display whether the student is above average or not
... Results: Jimmy 45 below average Amy 86 above average ... Amy, who got 86 points, is the highest Class average score is 72
The class teacher need a program to collect the height of all students. Name is not required. The data will store in an array and later use it for statistical calculations.
1. A constant is needed for total number in school. Suggest the name of the constant.
2. Suggest the name of the array for storing the data.
3. Write the algorithm to collect the data for the teacher. (either pseudocode, flowchart, or python)
4. The teacher need to know the average height of students. Write the algorithm that display the average height (assuming that part 3 is already done)
Answer is just for reference - any reasonable answer is acceptable
1. A constant is needed for total number in school. Suggest the name of the constant.
StudentCount
2. Suggest the name of the array for storing the data.
StudentHeight
3. Collect data
Note: Constant StudentCount is supposed to be pre-defined (i.e. should not have input)
#Declare array, index from 1 StudentHeight[1:StudentCount] FOR i <- 1 to StudentCount INPUT StudentHeight[i] NEXT i
#This example is zero indexed, similar to python StudentHeight[StudentCount] FOR i <- 0 to StudentCount-1 INPUT StudentHeight[i] NEXT i
Total <- 0 FOR i <- 1 to StudentCount Total <- Total + StudentHeight[i] NEXT i Average <- Total / StudentCount PRINT Average
Again, you can use zero based array...