4 Algorithms and flowcharts (3)
Resources |
Revision Questions |
Information Technology IT
Login to see all questions
Click on a question to view the answer
1.
Consider a list of student scores. Write an algorithm to determine the average score and identify any students who scored above the average. Assume the list of scores is stored in an array called scores.
Algorithm:
- Start
- Get the number of students (
num_students) from the scores array. - Calculate the sum of all scores:
totalscore = 0. Iterate through the scores array, adding each score to totalscore. - Calculate the average score:
averagescore = totalscore / num_students. - Initialize an empty list called
aboveaveragestudents. - Iterate through the
scores array again. For each score:- If the current score is greater than
average_score then:- Add the student's index (or identifier) to the
aboveaveragestudents list.
- Output:
averagescore and aboveaverage_students.
Pseudocode:
START
INPUT scores (array)
INPUT num_students (length of scores)
total_score = 0
FOR i = 1 TO num_students DO
totalscore = totalscore + scores[i]
END FOR
averagescore = totalscore / num_students
aboveaveragestudents = []
FOR i = 1 TO num_students DO
IF scores[i] > average_score THEN
APPEND studentidentifier[i] TO aboveaverage_students
ENDIF
END FOR
OUTPUT averagescore, aboveaverage_students
END
2.
Consider a simple program to calculate the area of a rectangle. Represent the algorithm using a flowchart. Include input, processing, and output steps. Clearly indicate the data types involved.
Flowchart:
| Start (Oval) |
| Input: Length (Real) (Rectangle) |
| Input: Width (Real) (Rectangle) |
| Calculate Area: Area = Length * Width (Process) |
| Output: Area (Real) (Rectangle) |
| End (Oval) |
Data Types:
- Length: Real (floating-point number)
- Width: Real (floating-point number)
- Area: Real (floating-point number)
3.
Write pseudo-code to determine if a given number is a prime number. The user will input a number. You must use a FOR loop and the concept of divisibility. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.