The following pseudocode contains errors. Locate the errors and suggest a correction
1.The following section of the pseudocode inputs 500 numbers and outputs the largest positive number and the largest negative number. Identify the errors in the pseudocode.
2. The following section of the pseudocode inputs the number of people buying some tickets at $5 each. A discount is given if 3 or more tickets are bought. The tickets are output. Identify the errors in the pseudocode.
3. The following section of the pseudocode inputs 100 numbers and outputs how many numbers were 100 and over and how many were less than 1000.Identify the errors in the pseudocode.
Collections and arrays
Collections
Collections store a set of elements. The elements may be of any type (numbers, objects, arrays, Strings, etc.).
A collection provides a mechanism to iterate through all of the elements that it contains. The following code is guaranteed to retrieve each item in the collection exactly once.
// STUFF is a collection that already exists
STUFF.resetNext()
loop while STUFF.hasNext()
ITEM = STUFF.getNext()
// process ITEM in whatever way is needed
end loop
Writing Pseudo codes using the approved notation:
Work in groups and complete the pseudo-code for the following situations.
- Write a pseudo-code to validate the password entered. The username and password is stored in a collection named SECURITY.
Give the user 3 tries to access the system. Youmust display appropriate messages.
- The array TVSALEScontains a list of 100 whole numbers (integers). Write a pseudo-code that will count how many of these numbers are non-zero, adds up all those numbers and then prints the average of all the non-zero numbers.
- Write a pseudo-code to read all the names from a collection, SURVEY, and then copy these names into an array, NEWARRAY, in reverse order. HL
Writing Pseudo codes using the approved notation:
Work in groups and complete the pseudo-code for the following situations
- HEIGHTS is a collection that already exists and stores the heights of 500 students in a school. Write an algorithm using pseudocode which reads data from a collection and outputs how many students were taller than 1.45 meters and how many wereshorter than 1.45 meters.
- Write a pseudo-code that reads all the names from a collectionFLIGHTS, and copies them into an array, FLIGHTLIST, but eliminates any duplicates. That means each name is checked against the names that are already in the array.
Extension
- Some students have been carrying out 5 experiments; 10 temperature readings were taken in each experiment
Write an algorithm using pseudocode, which inputs all the temperature readings, and outputs the average temperature for each experiment, the average temperature for all 10 experiments and the highest temperature recorded from all the readings taken.
- Assume that NAMES is an array containing the names of 10 students who apply for a job. A parallel array MATHMARKS stores the math score in the SAT exam. The MATHMARKS are in descending order (highest to lowest). NAMES[0] contains the name of the player with the top score.
NAMES [9] contain the name of the student with the lowest score as shown below.
NAMES = ["Hi","Fy","Di","Ed","Al","Go","Ma","Mi","Ha","Lo"]
MATHMARKS = [789, 790, 740, 738, 730, 724, 720, 719, 716, 714]
Write an algorithm to insert a new name and marks into the correct place in the list. It must move all the lower scores down one position in the list, eliminating the lowest score. The student to be added is below.
NEWSTUDENT=”Kim”
SCORE=670