0% found this document useful (1 vote)
235 views

Assignment 1-2.1.2 Pseudocode and Flowcharts

This document contains instructions for a computer science assignment on algorithm design and pseudocode. It asks the student to: 1) List three types of repetition constructs in programming languages and describe each. 2) Write a pseudocode algorithm to calculate the amount of fuel needed for a train journey based on distance entered by the user, with validation checks. 3) Determine the output of a sample loop that subtracts from a starting total each iteration. 4) For five sample while loops, determine how many times each loop will execute.

Uploaded by

Aditya Ghose
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
235 views

Assignment 1-2.1.2 Pseudocode and Flowcharts

This document contains instructions for a computer science assignment on algorithm design and pseudocode. It asks the student to: 1) List three types of repetition constructs in programming languages and describe each. 2) Write a pseudocode algorithm to calculate the amount of fuel needed for a train journey based on distance entered by the user, with validation checks. 3) Determine the output of a sample loop that subtracts from a starting total each iteration. 4) For five sample while loops, determine how many times each loop will execute.

Uploaded by

Aditya Ghose
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Computer Science Assignment # 1

2.1 Algorithm Design and Problem Solving

2.1.2 Pseudocode
1. State three types of repetition construct available in high level languages, giving a
characteristic of each. [6]
2. Write an algorithm (using either pseudocode or a flowchart) that calculates the amount of
fuel a train will need to complete a journey. The algorithm must:
• ask the user how many kilometres the journey will be
• only continue if the user enters a value greater than zero
• set the amount of fuel to a number 100 times greater than the number of kilometers
• not allow the amount of fuel to be less than 1500
• finally, display the amount of fuel needed. [7]
3. What is the output of the following loop?
Declare total as Integer
Declare number as Integer
total = 25;
number = total DIV 2
For i = 1 to number
total = total – number
OUTPUT (total + “ “ + i)
Next
[5]
4. For each of the following while loops, how many times will the loop execute its body?
Remember that "zero," "infinity," and "unknown" are legal answers.
(i) Declare x As Integer
x = 1
While x < 100
OUTPUT (x & “ “)
x = x + 10
End While
[1]
(ii) Declare max As Integer
max = 10
While max < 10
OUTPUT (“count down: “ + max)
max = max – 1
End While
[1]
(iii) Declare x As Integer
x = 250
count = x MOD 3
While count <> 0
OUTPUT X
Count = count MOD 3
End While
[2]
(iv) Declare x As Integer
x = 2
While x < 200
Output x & “ “
x = x * x
Page 1 of 2
Computer Science Assignment # 1
2.1 Algorithm Design and Problem Solving

2.1.2 Pseudocode
End While
[2]
(v) Declare x as Integer
x = 100
While x > 0
OUTPUT (x DIV 10)
x = x DIV 2
End While
[1]

Page 2 of 2

You might also like