Programming Quiz 2 Ebis
Programming Quiz 2 Ebis
Programming Quiz 3
Both arrays have already been declared and the data initialised.
…………………………………………………………………………………………………………………………………………
//coding the count
For i <--- 1 to 50
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
Total <--- total + Price[i]
…………………………………………………………………………………………………………………………………………
If Prices[i] < 10 then
…………………………………………………………………………………………………………………………………………
Count <--- Count + 1
…………………………………………………………………………………………………………………………………………
endif
…………………………………………………………………………………………………………………………………………
NEXT
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
Avg <---- total/50
…………………………………………………………………………………………………………………………………………
//outputting the average and prices below 10
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
Output "The average price between all products = ", Avg
output "items with a price below 10 = ", Count
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
[8]
Eng. Omar El Sa,y OL Computer Science
2 (a) Declare an array that should store the salaries of 100 employees in a company.
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
[2]
(b) Write a program that would:
• input & validate 100 salaries and store them in the array declared in part (a)
• find and output the highest salary entered
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
Declare Salaries[1:100], Highestsalary : REAL
…………………………………………………………………………………………………………………………………………
Highestsalary <--- -99999999
…………………………………………………………………………………………………………………………………………
For x <--- 1 to 100
output "Enter the salaries"
…………………………………………………………………………………………………………………………………………
input Salaries[x]
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
[6]
Eng. Omar El Sa,y OL Computer Science
…………………………………………………………………………………………………………………………………………
Declare lengthofx: INTEGER
Declare x, Extractedword: STRING
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
lengthofx <--- LENGTH(x)
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
OUTPUT "Length of the word is ",lengthofx
OUTPUT "The extracted word is ", Extractedword
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
[6]
Show the value of the variable after each pseudocode statement has been executed.
20
03 R <- LENGTH(Q) ……………………………………..…………………………………………………………..[1]
04 S <- SUBSTRING(G,1,12)Proxy
………………………………………………………………………………….
Server & [1]
Eng. Omar El Safty OL Computer Science
5 An algorithm has been written in pseudocode to input 50 numbers and total only the positive
numbers.
01 Total ← 10000
03 INPUT Number
06 ENDIF
07 ENDWHILE
08 OUTPUT Total
Locate these errors and suggest a corrected piece of code for each error.
Error 1
line 1 should be Total <- 0
………………………………………………………………………………………………………………………………………………………..[1]
Error 2
………………………………………………………………………………………………………………………………………………………..[1]
line 4 should be IF Number >=0 THEN
Error 3
LINE 5 should be Total <--- Total + Number
………………………………………………………………………………………………………………………………………………………..[1]
Error 4
line 7 should be NEXT
………………………………………………………………………………………………………………………………………………………..[1]
Eng. Omar El Safty OL Computer Science
• output the average when zero is input and end the algorithm.
…………………………………………………………………………………………………………………………………………………….
total <---- 0
…………………………………………………………………………………………………………………………………………………….
Repeat
…………………………………………………………………………………………………………………………………………………….
Output "guess the number"
input guess
…………………………………………………………………………………………………………………………………………………….
total <--- total + guess
…………………………………………………………………………………………………………………………………………………….
UNTILL guess = 0
…………………………………………………………………………………………………………………………………………………….
avg <--- total/guess
…………………………………………………………………………………………………………………………………………………….
OUTPUT "the average of your guesses is ", avg
…………………………………………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………………………………………….
…………………………………………………………………………………………………………………………………………………[5]