FPG511S Examination 2, Opportunity 1
FPG511S Examination 2, Opportunity 1
FPG511S Examination 2, Opportunity 1
=[ ]% =[ ]%
Total Marks Lecturer Signature Total Marks Student Signature
Programme:
BTech. Electronics Engineering (BELL), and
BTech. Power Engineering (BPEN)
INSTRUCTIONS TO CANDIDATE:
1.Before you begin the Exam make sure you have good internet connection
2.The Exam is strictly online, no submission through email will be accepted
3.Students must complete the questions within time frame allocated for the exam.
4.Marks are indicated at the end of each question.
5.EXTRA EXAM ATTEMPT WILL NOT BE PROVIDED IF
Students fail to appear for exam within specified timings.
Student ignores instructions and rules
Student face internet or power failure problems.
Question 1 [6]
A. myValue
B. vo*value
C. our values
D. 9valueThem
1.2. Variables and constants are used in many algorithms, which statement is false about
variables?
1.4. An algorithm is needed to calculate y, given that for every numeric value of z entered
by the user, y=3z-2.
Which of the following are valid processes in a defining diagram for the algorithm?
1.5. An algorithm is needed to calculate the value of a variable Tn, given that for every
numeric values of x and h entered by the user, Tn = (9x)/h. Which of the following are valid
processes in a defining diagram for the algorithm?
Question 2 [6]
High-level
problem-oriented,
much easier (and faster) for humans to read and write,
needs complex conversion to get into machine code (interpreters and compilers)
(2 marks)
Assembly
written in mnemonics (short codes),
so (relatively) easier for humans to read,
needs an assembler to convert into machine code (2 marks)
Machine Code
written in binary,
hard for humans to read,
too slow and error-prone for humans to write,
easy for computer to ‘understand’ and run efficiently (2 marks)
Question 3 [10]
Analyse the following algorithms and determine what will be their outputs? Show steps
that lead to your answer.
Analyse the following algorithm and determine what will be the output if you enter p =7.0
and r = 2.0? Show steps that lead to your answer.
3.1. What will be the output if you enter p =7.0 and r = 2.0? [2]
START
REAL p, r, W
1. GET p, r
2. IF p! =0 THEN
3. W =pr-p
ENDIF
4. DISPALY W
STOP
Solutions
r=2
SOLUTIONS
p= -90
Solutions
SOLUTIONS
k=-7.12
r=0
Inputs e>= 0 k=e*7.12 Answer
3.4. The structure of a nested if statement is presented in the algorithm segment below. [3]
Write the same pseudo code segment using combined IF statement (that is, an IF
statement where the two conditions form one condition without changing the outcome of
running the code segment).
IF condition 1 THEN
IF Condition 2 THEN
Statements(s)
ENDIF
ENDIF
SOLUTIONS
IF condition 1 AND Condition 2 THEN 2 marks
Statements(s) 0.5
ENDIF 0.5
Question 4 [26]
4.1. Write a pseudo code algorithm of a BMI calculator application that reads the user’s
weight and height and then calculates and displays the user’s body mass index. The
formula for calculating BMI is: BMI=Weight/(Height * Height). Also, the application should
display the following information from the scale provided below.
[11]
BMI VALUES:
SOLUTIONS MARKS
START
REAL Weight,Height, BMI 0.5
GET Weight, Height 0.5
BMI =Weight/(Height*Height) 1
IF BMI <18.8 THEN 1
Result ="Underweight" 0.5
ELSE 0.5
IF BMI < =24.9 AND BMI> =18.9 THEN 1
Result ="Normal" 0.5
FPG511S Page 5 E2/06/2020
4.2. In efforts to reduce road accidents in Namibia, the Namibia Police Traffic division has
come up with measures to reduce speeding by enforcing heavy fines on the drivers caught
disobeying the law. The table below gives an overview of the fines relative to the speed
driven.
You are required to write a Pseudocode algorithm that receives input of the driver’s full
names, gender, speed driven and then print out the fine if necessary, otherwise print out a
praising message for the law-abiding citizen. [15]
IF Speed >=200THEN 1
Fine = N$15000 0.5
ELSE 0.5
IF Speed >=160 THEN 1
Fine = N$5500 0.5
ELSE 0.5
IF Speed >=140 THEN 1
Fine = N$3500 0.5
ELSE 0.5
IF Speed >=130 THEN 1
Fine = N$2800 0.5
ELSE 0.5
IF Speed >=125 THEN 1
Fine = N$2000 0.5
ELSE 0.5
DISPLAY“law-abiding Citizen” 0.5
ENDIF 0.5
FPG511S Page 6 E2/06/2020
Question 5 [22]
Analyse the diagram below and determine pseudo code syntax that correctly represents
the flowchart represented.
5.1. [4.5]
START
REAL speed,time,distance 0.5
set distance =80 0.5
GET time 0.5
IF time >= 0 THEN 0.5
speed = distance/time 0.5
ELSE 0.5
DISPLAY "Error:time must be >0 0.5
ENDIF 0.5
DISPLAY speed 0.5
STOP
START
INTEGER num1, num2, sum, product,average 0.5
set sum =0 0.5
GET num1, num2 0.5
IF num1==0 AND num2==0 THEN 1
STOP 0.5
ENDIF 0.5
Sum =Num1+Num2 0.5
Average =sum/2 0.5
Product =num1*num2 0.5
IF sum > 200 THEN 1
DISPLAY sum 0.5
ELSE 0.5
DISPLAY ** 0.5
ENDIF 0.5
FPG511S Page 10
E2/06/2020