FPG511S Examination 2, Opportunity 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Examiners Mark Moderated Mark

=[ ]% =[ ]%
Total Marks Lecturer Signature Total Marks Student Signature

Programme:
BTech. Electronics Engineering (BELL), and
BTech. Power Engineering (BPEN)

Fundamentals of Programming (FPG511S)

Examination 2, 1st Opportunity


TOTAL MARKS: 70
DURATION: 2 hours

DATE: 30 June 2020

EXAMINER: Ms. Aili Ashipala


MODERATOR: A/Prof Z. Oyedokun

STUDENT NAME: STUDENT NUMBER:

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]

1.1. Which of the following is a valid variable name?

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?

A. Variable cannot change its value during program execution.


B. Constant always take only integer values.
C. The value in a variable can change during program execution.
D. Variables have memory reserved for their values when they are declared.

1.3. Which of the following statements qualifies as a characteristic of every algorithm?

A. Algorithms are unambiguous.


B. Algorithms have no sequential, no selection and no repetition statement.
C. Algorithms are infinite.
D. Algorithms are ambiguous.

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?

A. GET y and y=3z-2


B. GET z and z=3y-2
C. GET z and y=3z+2
D. GET z and y=3z-2

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?

A. GET x, h and Tn = 9*x/h


B. GET x, h and h= 9*(x/h)
C. GET x, Tn and Tn = (9*x)/h)
D. GET x, x/h and Tn = 9*(x/h)

1.6. The difference between an algorithm and a program is that,

A. A program is written in a specific programming language whereas an algorithm is not


restricted to being written in a specific programming language.
B. A program is written in a specific programming language and an algorithm is also
restricted to being written in a specific programming language.
C. A program is never written in a specific programming language and an algorithm is
FPG511S Page 2 E2/06/2020

Total page marks:


not restricted to being written in a specific programming language.
D. A program is written in a specific programming language whereas an algorithm is a
statement.

Question 2 [6]

Match the following descriptions to the correct type of programming language.

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

Inputs p! =0 W=pr-p Answer

p=7 True 7.0*2.0 -7.0 12.0

r=2

FPG511S Page 3 E2/06/2020

Total page marks:


3.2. What will be the output if p = -9.0? [2]
START
REAL p, d
1. GET p
2. IF p < 0 THEN
3. d =p*10
ENDIF
4. DISPALY d
STOP

SOLUTIONS
p= -90

Solutions

Inputs p <0 d=p*10 Answer

p=9.0 True -9.0*10 -90

3.1.3. What will be the output if p = -1? [3]


START
Integer e, k =0, r =0
1. GET e
2. IF e>=0 THEN
3. r=e*7.12
ELSE
e= e*e
k=e*7.12
ENDIF
4. DISPALY k, r
STOP

SOLUTIONS
k=-7.12
r=0
Inputs e>= 0 k=e*7.12 Answer

e=-1 false -1*7.12 k=-7.12

FPG511S Page 4 E2/06/2020

Total page marks:


r=0

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:

Underweight: less than 18.5


Normal: between 18.5 and 24.9
Overweight: between 25 and 29.9
Obese: 30 or greater

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

Total page marks:


ELSE 0.5
IF BMI >=25 AND BMI >=29.9 THEN 1

Result ="Overweight" 0.5


ELSE 0.5
Result ="Obese" 0.5
ENDIF 0.5
ENDIF 0.5
ENDIF 0.5
DISPLAY BMI 0.5
STOP
Overall: 0.5 mark

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]

Speed Range Fine


Speed>=200 N$15000
160 >=Speed <200 N$5500
140 >=Speed <160 N$3500
130 >=Speed <140 N$2800
Speed >=125 N$2000

SOLUTIONS Marking Scheme


START
INTEGER Speed,Fine 0.5
CHARACTER Name,Gender 0.5
GET Speed, Name, Gender 0.5

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

Total page marks:


ENDIF 0.5
ENDIF 0.5
ENDIF 0.5
ENDIF 0.5
STOP

Overall: 0.5 mark

Question 5 [22]

Analyse the diagram below and determine pseudo code syntax that correctly represents
the flowchart represented.

5.1. [4.5]

SOLUTION Marking scheme

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

FPG511S Page 7 E2/06/2020

Total page marks:


5.2. [8]

SOLUTIONS Marking scheme

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 8 E2/06/2020

Total page marks:


5.3. [9.5]

SOLUTIONS Marking Scheme


START
INTEGER code 0.5
GET code 0.5
IF code==1 THEN 0.5
DISPLAY "drizzling" 0.5
ELSE 0.5
IF code==2 THEN 0.5
DISPLAY "moderate rain" 0.5
ELSE 0.5
IF code ==3 THEN 0.5
DISPLAY "Heavy rain" 0.5
ELSE 0.5
IF code ==4 THEN 0.5
DISPLAY "stormy rain" 0.5
ELSE 0.5
DISPLAY "It is not raining" 0.5
ENDIF 0.5
ENDIF 0.5
FPG511S Page 9 E2/06/2020

Total page marks:


ENDIF 0.5
ENDIF 0.5
STOP

FPG511S Page 10
E2/06/2020

Total page marks:

You might also like