0% found this document useful (0 votes)
113 views

Pseudocode Assignment

The document contains several pseudocode examples and questions about identifying errors in pseudocode algorithms. The pseudocode examples include algorithms for: 1. Checking if a number is even or odd and counting the number of rejects. 2. Calculating a class average but contains an error that causes it to run indefinitely. 3. Finding the total sales for orders but contains an error in how it calculates the total. 4. Performing a bubble sort on an array of numbers to sort it. The questions ask the reader to identify errors, complete missing parts, and determine outputs of the algorithms for given inputs.

Uploaded by

Arhaan Pandey
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)
113 views

Pseudocode Assignment

The document contains several pseudocode examples and questions about identifying errors in pseudocode algorithms. The pseudocode examples include algorithms for: 1. Checking if a number is even or odd and counting the number of rejects. 2. Calculating a class average but contains an error that causes it to run indefinitely. 3. Finding the total sales for orders but contains an error in how it calculates the total. 4. Performing a bubble sort on an array of numbers to sort it. The questions ask the reader to identify errors, complete missing parts, and determine outputs of the algorithms for given inputs.

Uploaded by

Arhaan Pandey
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/ 4

Date: _________________________

Name: ________________________________________________________

Subject: _____________ Class: ____________

Question
Fill in the blanks question, 2 blanks
Complete the pseudocode that rejects any number that is not even. Run the
algorithm as many times as the user would like and on quitting, display the
number of rejects at the end of the algorithm.

Pass ← 0
Fail ← 0
INPUT Number
WHILE Number > 0 DO

IF MOD(Number,2) =
THEN
OUTPUT "pass"
Pass ← Pass + 1
ELSE
OUTPUT "fail"
Fail ← Fail + 1
ENDIF
OUTPUT "Enter 0 to quit program"

INPUT
ENDWHILE
OUTPUT "The number of rejects is", Fail

Question
The algorithm to calculate the class average of 100 pupils is given below. But the
algorithm runs indefinitely. Can you spot the error in the code?
StudentCount ← 100
ClassTotal ← 0
ClassAverage ← 0
WHILE StudentCount <=100 DO
INPUT IndividualTotal
ClassTotal ← ClassTotal + IndividualTotal
StudentCount ← StudentCount - 1
ENDWHILE ClassAverage ← ClassTotal / 100
OUTPUT ClassAverage

Garodia International Centre for Learning Mumbai. Url: www.giclm.edu.in


Question
A pseudocode is written to find the total sales for 50 orders at a restaurant. What
error do you see in the code and how would you fix it?
Orders ← 50
TotalSales ← 0
INPUT Amount
WHILE Orders > 0 DO
TotalSales = TotalSales + Amount
ENDWHILE

Question
Fill in the blanks question, 4 blanks
Given this pseudocode:

INPUT Number
FOR Index ← 0 TO 5
Sum ← Number + Index
IF MOD(Sum,2) = 0
THEN
OUTPUT “Lucky draw”
ELSE
OUTPUT “No draw”
INPUT Number
ENDIF
ENDFOR
NEXT Index
The input values are 3, 2, 4, 6, 1.

Number Index Sum Output

3 0 3 No Draw

2 1 3 No Draw

4 2 6 Lucky Draw

6 4 10 Lucky Draw

6 5 11 No Draw

Can you complete the missing row?

Garodia International Centre for Learning Mumbai. Url: www.giclm.edu.in


Question
The objective of the following algorithm is to decide if a baggage may be
considered overweight by an airline. A bag is considered overweight if it weighs
greater than 23 kilograms or if its length is greater than 62 inches. Can you
complete the missing part of the algorithm?
INPUT ParcelWeight
INPUT ParcelLength
NumberOfBags ← 100
WHILE NumberOfBags > 0 DO
IF________________________________________________
THEN
OUTPUT “overweight”
ELSE
OUTPUT “approved”
ENDIF
NumberOfBags ← NumberOfBags - 1
ENDWHILE

Question
This pseudocode represents the Bubble sort algorithm.
SizeOfArray ← LENGTH(MyArray)
FOR i ← 1 TO SizeOfArray
Swapped ← False
FOR j ← 1 to SizeOfArray - 1
IF MyArray[j] > MyArray[j+1]
THEN
temp ← MyArray[j+1]
MyArray[j+1] ← MyArray[j]
MyArray[j] ← temp
Swapped ← True
ENDIF
NEXT j
IF (NOT Swapped)
THEN
break
ENDIF
NEXT i
The array MyArray used in the pseudocode contains the following data:

MyArray [1] MyArray [2] MyArray [3] MyArray [4]

5 8 7 2

When you go through the array from left to right comparing adjacent elements
and swapping them, if necessary, you complete a pass.

This bubble sort algorithm might need to make several passes in order to sort the
array.

Garodia International Centre for Learning Mumbai. Url: www.giclm.edu.in


Question
Fill in the blanks question, 3 blanks
The pseudocode represents an algorithm.

temp ← Letters[i+1]
Letters[i+1] ← Letters[i]
Letters[i] ← temp
The array Letters used in the pseudocode contains:

Letters [1] Letters [2] Letters [3]

M R G

Fill in the blanks to show the new state of the array Letters when i has the
value of 2.

Letters [1] Letters [2] Letters [3]

Garodia International Centre for Learning Mumbai. Url: www.giclm.edu.in

You might also like