0% found this document useful (0 votes)
17 views5 pages

Programming Quiz 2 Ebis

The document contains a programming quiz with multiple tasks related to arrays, salary input validation, string manipulation, and pseudocode debugging. It includes requirements for calculating averages, finding specific items, and correcting pseudocode errors. Each task is structured with prompts for coding and expected outputs.

Uploaded by

Samuel Elias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Programming Quiz 2 Ebis

The document contains a programming quiz with multiple tasks related to arrays, salary input validation, string manipulation, and pseudocode debugging. It includes requirements for calculating averages, finding specific items, and correcting pseudocode errors. Each task is structured with prompts for coding and expected outputs.

Uploaded by

Samuel Elias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Eng.

Omar El Sa,y OL Computer Science

Programming Quiz 3

1 The 1D array Products[] contains the names of 50 items in a supermarket.


The 1D array Prices[] contains the price of each item in the supermarket.

Both arrays have already been declared and the data initialised.

Write a program that would meet the following requirements:


• calculate and output the average price of all items in the supermarket.
• find and output the name of items with price less than 10

You must add comments to your code


Declare Total, Count, Avg : REAL
…………………………………………………………………………………………………………………………………………
Total <--- 0
Count <---- 0
…………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………
//coding the count
For i <--- 1 to 50
…………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………
Total <--- total + Price[i]
…………………………………………………………………………………………………………………………………………
If Prices[i] < 10 then
…………………………………………………………………………………………………………………………………………
Count <--- Count + 1
…………………………………………………………………………………………………………………………………………
endif
…………………………………………………………………………………………………………………………………………
NEXT
…………………………………………………………………………………………………………………………………………

//Coding the average


…………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………
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.

Declare Salaries[1:100] : REAL


…………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………

[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

Valid salaries are between 100 and 50000

…………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………
Declare Salaries[1:100], Highestsalary : REAL
…………………………………………………………………………………………………………………………………………
Highestsalary <--- -99999999
…………………………………………………………………………………………………………………………………………
For x <--- 1 to 100
output "Enter the salaries"
…………………………………………………………………………………………………………………………………………
input Salaries[x]
…………………………………………………………………………………………………………………………………………

if Salaries[x] <100 OR Salaries[x] >50000 then


…………………………………………………………………………………………………………………………………………
output "invalid. try again"
…………………………………………………………………………………………………………………………………………
input Salaries[x]
…………………………………………………………………………………………………………………………………………

if Salaries[x] > Highestsalary THEN


…………………………………………………………………………………………………………………………………………
Highestsalary <--- Salaries[x]
…………………………………………………………………………………………………………………………………………
endif
…………………………………………………………………………………………………………………………………………
NEXT
…………………………………………………………………………………………………………………………………………

OUTPUT "Highest salary is ",Highestsalary


…………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………

[6]
Eng. Omar El Sa,y OL Computer Science

3 The function LENGTH(X) finds the length of a string X.

The function SUBSTRING(X,Y,Z) finds a substring of X starting at position Y and Z characters


long.

The first character in X is in position 1

Write pseudocode statements to:

• store the string "Computer Science is fun" in X


• find the length of the string and output it
• extract the word Science from the string and output it

…………………………………………………………………………………………………………………………………………
Declare lengthofx: INTEGER
Declare x, Extractedword: STRING
…………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………

x <-- "Computer Science is fun"


…………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………
lengthofx <--- LENGTH(x)
…………………………………………………………………………………………………………………………………………

Extractedword <--- SUBSTRING(x, 9 , 15 )


…………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………
OUTPUT "Length of the word is ",lengthofx
OUTPUT "The extracted word is ", Extractedword
…………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………

[6]

4 The function LENGTH(X) finds the length of a string X.

The function SUBSTRING(X,Y,Z) finds a substring of X starting at position Y and Z characters


long.

The first character in X is in position 1

Show the value of the variable after each pseudocode statement has been executed.

Proxy Server & Firewall


01 G <- “Proxy Server & Firewall” ………………………………………………………………….[1]

PROXY SERVER & FIREWALL


02 Q <- UCASE(G) ……………………………………..…………………………………………………………….[1]

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

02 FOR Count <- 1 TO 50

03 INPUT Number

04 IF Number <> 0 THEN

05 Total ← Total + Count

06 ENDIF

07 ENDWHILE

08 OUTPUT Total

There are four errors in this code.

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

6 Write a program that would:

• allow numbers to be input until a zero is input

• find the average of the numbers

• output the average when zero is input and end the algorithm.

Declare guess, total, avg : INTEGER


…………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………….
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]

You might also like