You are on page 1of 29

DEV1 EXERCISES 01

For each of the following, write a detailed set of instructions, in the correct order, to complete
the task. Make sure every step needed is included! Don’t forget to ask extra questions if you
need to.
Before your first step, write down all the assumptions you have made in order to produce the
solution (e.g. in question 1 you have to assume that the person following the instructions has
electricity or a stove or wood to make a fire and a kettle or a pot).

Follow the 5 major steps when solving these problems.

Work in groups.

1. Make one cup of coffee.

2. Buy a loaf of bread from the local shop.

3. Send an sms to your mother telling her that you will be late.

4. Write the instructions to be followed if someone wants to be able to walk from inside the
security gate at the main entrance of the campus to the Resource Centre.
Swop solutions with another group and walk up to the main entrance. Then try to follow the
other group’s instructions and see if their solution works!

5. Add up the first ten integers. (You can say ADD but not COUNT).
In your solution you can use a calculator to help you (and a pencil and paper if you need
them).

6. Calculate your friend’s average mark for isiZulu. He has written 4 tests.
(You can say ADD but not COUNT).
In your solution you can use a calculator to help you (and a pencil and paper if you need
them).

7. Count how many students in your class are under the age of 21 and live in Mdantsane.
** You cannot use the instruction ‘COUNT’ – you need to instruct the person how to count.
You can say ADD. In your solution you can use a pencil and paper to help you but NOT a
calculator.

8. Your neighbour’s son has a box containing red, yellow and blue building blocks.
Write the instructions which tell someone how to count how many blocks there are of each
colour. ** You cannot use the instruction ‘COUNT’ – you need to instruct the person how
to count. You can say ADD.
There are too many blocks for you to keep the totals in your head – in your solution you
can use a pencil and paper to help you but NOT a calculator.

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 EXERCISES 02a

PART A

Student number
Student’s last name
Cell number of student
Course code
Number of tests
Mark for first test
Mark for second test
Average mark for the student

1. For each of the above:


a. Make up a suitable variable name and write a pseudocode instruction to declare the
variable (think carefully about what data type it should be).
b. Write a pseudocode instruction to assign a (realistic) literal value to the variable name
you have used.
c. Write a pseudocode instruction to assign a value input by the user to the variable name
you have used.
d. Write a pseudocode instruction to display the value in the variable on the screen.

2. a. Write a pseudocode instruction to add the values input for the two test marks together
and to store the answer in a variable called total
b. Write a pseudocode instruction to display the value of the calculated total on the
screen.

PART B

Buffalo City Rent-A-Car collects the following data for each person who rents a car from them:
customer id number, customer last name, customer initials, number of days the car is rented
for.

1.For each item of data to be input, write a single instruction to declare a variable to hold the
data
2.For each item of data to be input, write a single instruction to accept the data from the user
and store it in the variable you have declared

The price for renting a car is R300-00 a day.

3.Write a instruction to declare a variable to hold the total price.

4.Write a single instruction to calculate the total price and store it in the variable you declared
in 3.

5.Write a pseudocode instruction to display a message saying THE TOTAL IS followed by


the value of the calculated total price on the screen.

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 EXERCISES 02b

1.1 Write an instruction to declare a variable that can be used to hold the name of a country
1.2 Write an instruction that displays a message that asks the user to input the name of a
country
1.3 Write an instruction that gets the name of a country from the keyboard
1.4 Write an instruction that displays the input name of a country on the screen

2.1 Write an instruction to declare a variable that can be used to hold the name of a town
2.2 Write an instruction that displays a message that asks the user to input the name of a
town
2.3 Write an instruction that gets the name of a town from the keyboard
2.4 Write an instruction that displays the input name of a town on the screen

3.1 Write an instruction to declare a variable that can be used to hold the total number of
people living in a town
3.2 Write an instruction that displays a message that asks the user to input the total number
of people living in a town
3.3 Write an instruction that gets the total number of people living in a town from the keyboard
3.4 Write an instruction that displays the input total number of people living in a town on the
screen

4.1 Write an instruction to declare a variable that can be used to hold the total number of
females living in a town
4.2 Write an instruction that displays a message that asks the user to input the total number
of females living in a town
4.3 Write an instruction that gets the total number of females living in a town from the
keyboard
4.4 Write an instruction that displays the input total number of females living in a town on the
screen

5.1 Write an instruction to declare a variable that can be used to hold the total number of
males living in a town
5.2 Write an instruction that displays a message that asks the user to input the total number
of males living in a town
5.3 Write an instruction that gets the total number of males living in a town from the keyboard
5.4 Write an instruction that displays the input total number of males living in a town on the
screen

BONUS
Write an instruction that calculates what percentage of the population living in the town is
male

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 EXERCISES 02c

1. A programmer has written the following declarations:

DECLARE myAge AS Integer


DECLARE yourRate AS Real
DECLARE departmentCode AS String

For each of the following, indicate if the instruction is valid or invalid.


If it is invalid, explain clearly why (your answer must make sense).

a. myAge = 23

b. myAge = yourRate

c. myAge = departmentCode

d. myAge = “departmentCode”

e. 42 = myAge

f. yourRate = 3.5

g. yourRate = myAge

h. yourRate = departmentCode

i. 6.91 = yourRate

j. departmentCode = Personnel

k. departmentCode = “Personnel”

m. departmentCode = “413”

n. 413 = departmentCode

o. “413” = departmentCode

p. myAge - 50 = myAge

q. myAge = myAge - 50

r. yourRate = 50 * 1.5

s. yourRate = yourRate * 1.5

t. yourRate = myAge / 1.5

u. yourRate = yourRate + 1,5

Adapted from:
Farrell, J. (2002). Programming Logic and Design. Comprehensive. Second Edition. Canada.
Course Technology.

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 EXERCISES 02d

PART A

DECLARE studentname as STRING

Variable name Value in variable after above instruction is executed

DECLARE mark1 as REAL

Variable name Value in variable after above instruction is executed

DECLARE mark2 as REAL

Variable name Value in variable after above instruction is executed

DECLARE total as REAL

Variable name Value in variable after above instruction is executed

ACCEPT studentname
* The user types in THABO
Variable name Value in variable after above instruction is executed

ACCEPT mark1
* The user types in 55
Variable name Value in variable after above instruction is executed

ACCEPT mark2
* The user types in 45
Variable name Value in variable after above instruction is executed

total = mark1 + mark2

Variable name Value in variable after above instruction is executed

All variables in use


Variable name Current value in variable

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


ACCEPT studentname
* The user types in Zuko
All variables
Variable name Current value in variable

ACCEPT mark1
* The user types in 83.5
All variables
Variable name Current value in variable

ACCEPT mark2
* The user types in 74
All variables
Variable name Current value in variable

total = mark1 + mark2

All variables in use


Variable name Current value in variable

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 EXERCISES 02e

1. Write all of the pseudocode instructions needed for a program that must do the following:
Display messages which ask the user to input a student’s first name, name of the town
or village where they live and their age (as a whole number)
Store all of the input in variables
Calculate how old the student will be in 67 years’ time and store the result in a variable
Display the following on the screen:
Good morning followed by the student’s first name
You live in followed by the name of the town/village that the student lives
in
In 67 years you will be followed by the result of your calculation

2. Write all of the pseudocode instructions needed for a program that must do the following:
Display messages which ask the user to input a student’s name, first test mark and
second test mark
Store all of the input in variables
Calculate the average mark for the student and store it in a variable (the average mark
is calculated by adding the marks together and dividing the answer by 2)
Display the message Average = followed by the value of the calculated average mark
on the screen

4. A programmer has written the following pseudocode instructions for a program that should
ask the user to input a student’s number and the number of courses the student has enrolled
for. The program should then calculate and display the value of the total fee the student must
pay. Each course costs R1660 and the registration fee for each student is R500-00.

BEGIN
DECLARE student’s number, number of courses AS NUMERIC
DECALRE registration_fee AS CHARACTER
DISPLAY Please input student number
ACCEPT 200609890
ACCEPT number of course
totalFee = number * R1660,00 + registration-fee
DISPLAY “The total fee the student must pay”

a. Find and explain all of the errors.


b. Rewrite all of the instructions so that the solution is correct.

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 EXERCISES 03

1a. Write down exactly what is displayed – in the correct order - by the following pseudocode if
the input is: NU4 7612

BEGIN
DECLARE street, town AS CHARACTER
DECLARE housenumber AS INTEGER
town = “MDANTSANE”
ACCEPT street, housenumber
DISPLAY housenumber, street, town
END

1b. Rewrite the DISPLAY so that a comma is displayed between the street and the town.
1c. Rewrite the DISPLAY so that the town is displayed underneath the house number and
street.

2. A student has been asked to design a program which will convert Rands into U S Dollars
or into British Pounds. The program should accept a rand amount and a single character:
U or P
If the character input is U the rand amount must be converted to U S Dollars. If the
character input is P the rand amount must be converted to British Pounds. The correct
formula must be used (as given below) and the result must be displayed.
Dollars = Rands / 16
Pounds = Rands / 20

The student has written the following pseudocode (all correct so far):

BEGIN
DECLARE rands, dollars, pounds AS REAL
DECLARE type AS STRING
ACCEPT rands, type
IF type = “U” THEN

2a. Write the rest of the pseudocode instructions needed to complete the program as
specified.
You may only use the variables already declared.

For EACH of the following questions:


a. draw an IPO Chart
b. write the pseudocode

3. Design a program which will ask the user to input two numbers. Calculate and display the
sum of the numbers and the difference between the first and second number.

4. Design a program to convert Fahrenheit temperature to Celsius. The user should enter
the temperature in degrees Fahrenheit. The program must then convert the temperature
to degrees Celsius and display it. The formula to convert the temperature is given below.
Celsius = (Fahrenheit – 32) * 5 / 9

5. Accept the length and width of a rectangle. Calculate and display the area and the
perimeter of the rectangle using the following formulae:
Area = length * width Perimeter = 2 * (length + width)
If the length and the width are equal, display the message “THIS IS A SQUARE”.

6. Design a program to calculate and display a student’s final mark. The program should
accept the student’s year mark and exam mark. The final mark is the sum of 40% of the
year mark and 60% of the exam mark. If the final mark is greater than or equal to 50,

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


display the message “PASS”. If the final mark is less than 50, display the message
“FAIL”.

7. Design a program that will accept a worker’s name and the hours he has worked. If he
has worked 40 hours or less, his hourly pay rate is R20-00. If he has worked more than
40 hours, his hourly pay rate is R25-00. Calculate and display his total pay by multiplying
the hours worked by the correct hourly rate.

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 EXERCISES 04

1. Draw an IPO chart and a flowchart for a program to calculate and display a student’s final
mark. The program should accept the year mark and the exam mark. The final mark is the
sum of 40% of the year mark and 60% of the exam mark. Display a message based on
the final mark. The message that must be displayed is given in the following table:

Final Mark Message


>= 75 CONGRATULATIONS - YOU HAVE PASSED WITH
DISTINCTION.
<75 but >= 60 PASS FIRST CLASS.
<60 but >= 50 PASS.
<50 FAIL – YOU MUST REPEAT THE COURSE.

2. Siya’s Flower Shops delivers flowers in East London. The flower arrangements come in
three sizes: small, medium and large. The flowers cost R150 for a small arrangement,
R170 for a medium arrangement and R190 for a large arrangement.
There is also a delivery fee which is calculated at R20-00 per kilometre.
Draw an IPO chart and a flowchart for a program which will ask the user to input the size
of the arrangement wanted and the distance (in kilometres). The program must then
calculate and display the total the customer must pay. (The user will input S for small, M
for medium and L for large).

3. Border Transporting Company delivers cargo to various towns from East London. The
cargo is packed in containers which come in three sizes: small, medium and large. There
is a minimum charge of R2000 for every delivery. Thereafter there are the following
additional charges:
a. R1000 for a small container, R2000 for a medium container and R3000 for a large
container.
b. Insurance calculated as follows:
10% of the value of the cargo, if the value of the cargo is under R10000.
If the value is between R10000 and R50000, 12% of the value of the cargo.
If the value is over R50000, 18% of the value of the cargo.
Draw an IPO Chart and write the pseudocode for a program which will calculate and
display the total charges after the size of the container and the value of the cargo have
been input. (The user will input S for small, M for medium and L for large).

4. A student has been asked to design a program to calculate the tax and the net salary of
an employee. The tax is calculated according to the following table:

Salary Tax
From R 0 to R 195 000 18% of the amount
From R 195 001 to R 305 000 R 35 000 + 26% of amount above 195 000
From R 305 001 to R 423 000 R 63 850 + 31% of amount above 305 000
From R 423 001 to R 555 000 R100 000 + 36% of amount above 423 000
From R 555 001 to R 708 000 R 148 000 + 39% of amount above 555 000
From R 708 001 to R 1 500 000 R 207 000 + 41% of amount above 708 000
Over R1 500 000 R 532 000 + 45% of amount above 1 500
000

The program should accept the salary of the employee and then calculate and display the
tax and the net salary (i.e. the salary after the tax has been deducted).
The student has written the following pseudocode (which is all correct so far):

BEGIN
DECLARE salary, tax, net AS REAL
DISPLAY “Please input salary of employee”
ACCEPT salary
IF salary > 1500000 THEN

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


tax = 532000 + (0.45 * (salary – 1500000))
END IF

4a. Write the rest of the instructions needed to complete the program as specified.
You may only use the variables already declared.

5. Thabo Bazaars is having a special on potatoes and onions.


They are selling potatoes for R12-00 a kilogram and onions for R10-00 a kilogram.
If the customer wants more than 5 kilograms of potatoes they will only pay R10-00 a
kilogram for the potatoes. (These prices do not include VAT).

Draw an IPO chart and write the pseudocode for a program which will do the following:

Accept (with meaningful messages):


a. the number of kilograms of potatoes the customer wants (user will input 0 if none are
wanted)
b. the number of kilograms of onions the customer wants (user will input 0 if none are
wanted)

Calculate and display (with meaningful messages):


a. the total amount before VAT
b. the VAT amount (15% of the total)
c. the total amount including VAT that the customer must pay

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 EXERCISES 05

1. This program should accept a student number and 2 test marks. It should then calculate
and display the average of the 2 marks. If the average is less than 40 it should display the
message
YOU HAVE TO WORK HARDER

Draw 2 trace tables for the following pseudocode using the input values:
1a. 219091208 50 60 (What should the output be?)
1b. 219430017 35 40 (What should the output be?)
1c. Does the solution provide the correct output for both sets of data?

BEGIN
DECLARE studnum AS string
DECLARE mark1, mark2, total AS integer
DECLARE average AS real
DISPLAY “INPUT STUDENT NUMBER AND 2 TEST MARKS”
ACCEPT studnum, mark1, mark2
total = mark1 + mark2
average = total / 2
DISPLAY “AVERAGE = ” average
IF average < 40 THEN
DISPLAY “YOU HAVE TO WORK HARDER”
END IF
END

2. This program should accept the number of courses a student has registered for. It should
then calculate and display the total fee the student must pay. The student has to pay R1660
per course plus R500 registration fee. If the number of courses input is less than 1 or greater
than 4, the total fee should not be calculated or displayed and the message “Invalid input”
should be displayed.

Draw 2 trace tables for the following pseudocode using the input values:
2a. 4 (What should the output be?)
2b. 5 (What should the output be?)
2c. Does the solution provide the correct output for both sets of data?
If not, rewrite the solution so that it is correct. Then redo both trace tables to check your
new solution.

BEGIN
DECLARE num_courses, fee, reg AS integer
reg = 500
DISPLAY “Please input number of courses”
ACCEPT num_courses
IF num_courses <= 4 THEN
fee = num_courses * 1660 + reg
END IF
IF num_courses > 4 AND num_courses < 1 THEN
DISPLAY “Invalid input”
END IF
DISPLAY “The total fee is ” fee
END

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 EXERCISES 05B
.
Draw a trace table for each of the following pseudocode programs:
1.
BEGIN
DECLARE CODE AS INTEGER
DECLARE MSG AS STRING
ACCEPT CODE
IF CODE > 8 THEN
MSG = “FIRST”
END IF
IF CODE = 5 THEN
MSG = “SECOND”
END IF
IF CODE < 3 THEN
MSG = “THIRD”
ELSE
MSG = “FOURTH”
END IF
DISPLAY “THE ANSWER IS ” MSG
END
Use the following input value: 10

2.
BEGIN
DECLARE x, y AS REAL
x = 2
y = 3 * x
x = y + 5
DISPLAY x
y = y+ 1
END

3.
BEGIN
DECLARE n, N AS REAL
n = 4 + 6 / 3 – 2 * 2
DISPLAY n
n = (3 * 2) ^ 2 + 6 / 3 – 4 + 18
DISPLAY n, N
N = n + 1 + (33-28) / (21 – 16)
N = N * 2 + 3
DISPLAY N
END

4.
BEGIN
DECLARE Z, X, Y AS REAL
ACCEPT X, Y
Z = X + Y / 2 – (X + Y) / Y
DISPLAY X, Y, Z
END
Use the following input values: 30 6

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


5. BEGIN
DECLARE Z, X, Y AS REAL
ACCEPT X, Y
IF X > Y – 3 THEN
DISPLAY “Relational condition 1 is True”
ELSE
DISPLAY “Relational condition 1 is False”
ENDIF
IF X <> Y – 3 THEN
DISPLAY “Relational condition 2 is True”
ELSE
DISPLAY “Relational condition 2 is False”
ENDIF
END
Use the following input values: 2 4
6.
BEGIN
DECLARE Z, X, Y AS REAL
ACCEPT X, Y
IF X / (4 + Y) < Y * (15 – 6) +20
DISPLAY “Relational condition is True”
ENDIF
END
Use the following input values: 12 2

7. BEGIN
DECLARE answerT, answerF as character
answerT = “TRUE”
answerF = “false”
IF 5 > 3 OR 7 <= 4
DISPLAY “Logical condition 1 is “, answerT
ENDIF
IF 5 > 3 AND 7 <= 4
DISPLAY “Logical condition 2 is “, answerT
ELSE
DISPLAY “Logical condition 2 is “, answerF
ENDIF
END

8. BEGIN
DECLARE A1 AS CHARACTER
DECLARE B, d, e, F AS REAL
A1 = “t”
F = 5
ACCEPT B, d, e
IF (F < B+3*4) AND (d+e) <> 10 OR B+d > F*2 THEN
B = B * 2
ENDIF
DISPLAY B
IF NOT B = e AND e * F <> 25 - d THEN
DISPLAY “Logical condition 2 is “, A1
ELSE
DISPLAY “Logical condition 2 is “, “False”
ENDIF
END
Use the following input values: 10 2 3

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 Exercises 06

1a. Write the pseudocode for a program which will use a FOR loop to calculate and display
the sum of the first five even numbers (i.e. 2, 4, 6, 8, 10)

1b. Draw a trace table for your solution.

2a. Write the pseudocode for a program which will use a FOR loop to accept a classroom
‘number’ (it includes characters) and the number of chairs in the classroom for 3 different
classrooms. Accumulate the total number of chairs.
When there is no more input, display the total number of chairs and the average number of
chairs per classroom.

2b.Draw a trace table for your solution using the following data:
D1G1 45
C1.6 32
D2F2 73

3. Write the pseudocode for a program which will accept the family name of 4 sisters and the
height of each of the sisters. Calculate and display the total height of the sisters in each
family.
The program steps must be repeated 20 times using a FOR loop.
When there is no more input, display the total number of families in which the sisters have
a total height less than 7,0m.

4. Write the pseudocode for the following program:


Ask the user to input how many students they want to input marks for.
Use a FOR loop to accept each student’s year mark and exam mark. Calculate each
student’s final mark using 50% of the year mark plus 50% of the exam mark. Repeat this
for all of the students.
After all input has been accepted, display:
- the total number of students who passed the course (i.e. whose final mark is greater
than 50%).
- the total number of students who passed the course with distinction (i.e. whose final
mark is 75% or higher).

5. A women’s co-op is growing and selling the following vegetables:


SPINACH LETTUCE CABBAGE PUMPKIN
The following codes are used to represent each vegetable:
SP for SPINACH
LE for LETTUCE
CA for CABBAGE
PU for PUMPKIN
Write the pseudocode for a program which will use a FOR loop to accept each person’s
order (i.e. the code for one of the vegetables listed above) and how many they want (the
quantity)
e.g. LE 3 means they want 3 lettuces.
Repeat the input 100 times.
When there is no more input display the total quantity ordered of each of the four
vegetables. (Use meaningful messages).

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 Exercises 07

1a. Write the pseudocode for a program which will use a DO WHILE LOOP to accept a
student number and 3 test marks for each student. Accumulate the total mark for each of
the 3 tests.
Use a sentinel value of 0 to end the input.
When there is no more input, calculate and display the average mark for each of the 3
tests.

1b.Draw a trace table for your solution using the following data:
219141111 50 60 50
219141112 80 90 70
219141113 40 50 40
0 0 0 0

2a.Write the pseudocode for a program which will accept the surname of a pair of brothers
and the weight of each of the brothers. Calculate and display the average weight of the
brothers in each pair. The program steps must be repeated using a DO WHILE loop,
until ZZZ is input as the surname.
When there is no more input, display the total number of pairs of brothers with an average
weight above 55kg.

2b. Draw a trace table for your solution using the following data:
Mandela 53 56
Mbeki 45 65
Green 62 50
ZZZ 0 0

3. Write the pseudocode for the following program:


Use a DO WHILE loop to accept the name of the town that a student lives in (in
uppercase), the student’s age and gender (M or F). Use a sentinel value of XXX to end the
input.
After all input has been accepted, display:
- the total number of male students who live in Mdantsane
- the total number of female students who are over 21 years old
- the total number of students under the age of 30 who live in Bhisho

4. A car company has done a survey to find out which colour car most people prefer. The
colours they chose from were: BLACK WHITE RED SILVER BLUE.
Write the pseudocode for a program which will use a DO WHILE loop to accept each
person’s choice (i.e. one of the colours listed above) and then display the total number of
people who chose each of the five colours. Also display the total number of people who
took part in the survey. Use your own sentinel value to end the input.

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 Exercises 08

1. Write the pseudocode for a program which will use a DO WHILE LOOP to accept a
student number and 4 test marks until the user inputs ZZZ for the student number.
Calculate and display the average mark for each student.
When there is no more input, display the following (with meaningful messages):
a. The number of students with an average less than 40
b. The number of students with an average greater than 40 but less than 75
c. The number of students with an average greater than or equal to 75

2. XXX stores is having a special sale. If customers spend more than R100-00, they get
10% discount. If they spend more than R200-00 they get 15% discount. If they spend
more than R300-00 they get 20% discount. (The discount is a percentage of the
accumulated total amount). The customer has to pay 15% VAT on the final amount
after the discount amount has been subtracted.
i. Write the pseudocode for a program which will accept the quantity (how many) and
price for an item. Calculate and accumulate the total for each item.
Use a FOR LOOP to repeat the input for 3 different items.
When there is no more input:
a. Calculate and display the discount amount (if any).
b. Calculate and display the VAT amount the customer must pay.
(This will be 15% of the accumulated total after the discount amount has been
subtracted).
c. Calculate and display the final amount the customer must pay (i.e. after the discount
amount has been subtracted and the VAT amount added).
** Display meaningful messages with the values
Hint: First make up some sample input data and work out (on paper) what the answers
should be.

ii. Draw a trace table for your pseudocode using your own sample input data.

3. This program should accept the course code a student has registered for. The fee for
each course code is shown in the table below. If the input is invalid, it should display an
error message. The input should be repeated for 2 courses. The program should then
calculate and display the total fee the student must pay, i.e. the total fee for all of the
courses plus a R500-00 registration fee plus a R300-00 administration fee.

Course Code Fee


BEE0090 R1800
AAV8765 R3200

BEGIN
DECLARE n, total, fee AS integer
DECLARE course AS String
FOR n = 1 to 2
DISPLAY “Please input course code”
ACCEPT course
IF course = “BEE0090” then
fee = 1800
END IF
IF course = “AAV8765” then
fee = 3200
END IF
IF course <> “BEE0090” AND course <> “AAV8765” then
DISPLAY “Invalid input”
total = total + fee
END IF
ENDFOR
total = total + 500 + 300
DISPLAY “The total fee is ” total

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


END

i. Draw a trace table for the program using: aav8765 BEE0090

ii. If the program does not produce the correct answer, rewrite it so that it does.
You must write the whole program. You may not change the variable names or data
types or add new variables/constants or remove any of the variables.

4. A company wants to launch a new flavoured drink. They have done a survey to find out
which flavour most people prefer. The flavours to choose from are: ORANGE APPLE
LIME MANGO
Write the pseudocode for a program which will accept each person’s choice and then
display the total number of people who chose each of the four flavours. 500 people took
part in the survey.

5. A car hire company charges different daily rates for different types of cars which they rent
to customers. Customers also pay an additional charge for the type of sound system which
they want in the car (this is a single charge, NOT a daily charge).
Write the pseudocode for a program which will accept the type of car, the number of days
the car was hired for and the type of sound system the customer used. (Example: AUDI,
2, USB)
The program must then :
a. Calculate and display the rental price using the formula:
rental price = number of days * daily rate
The daily rate is based on the type of car as shown in Table 1.
Use the correct daily rate in your calculations.
b. Display the price of the sound system based on the type of sound system as shown in
Table 2.
c. Calculate and display the total price the customer must pay using the formula:
total price = rental price + price of sound system

Table 1 Table 2

Type of Car Daily Rate Sound System Price


VW POLO 700 STANDARD 300
HYUNDAI 550 USB 500
AUDI 1200 BLUETOOTH 700

6. A textile factory is taking orders for different colours of cotton fabric which costs R80 per
metre.
The colours available are: PINK GREEN BLUE.
Write the pseudocode for a program which will accept the colour wanted and the number
of metres.
Repeat the input until ZZZ is input for the colour.
When the input is complete, display - in the same order as below:
a. The total metres ordered for the pink fabric
b. The total cost for the green fabric
c. The total number of orders for the blue fabric
d. The total metres ordered altogether (i.e. for all colours)
e. The total cost for all the fabrics (i.e. for all colours)
f. The total number of orders (i.e. for all colours)

7. A student has written the following pseudocode to calculate the age of a person. The
person inputs his/her year of birth. If the input value is > 0, the program should calculate
and display the person’s age. If the input value is less than or equal to 0, the program should
display an error message and not do the calculation.

BEGIN
DECLARE age, birthyear AS INTEGER

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DISPLAY “Please input your year of birth”
ACCEPT birthyear
IF birthyear > 0 THEN
age = birthyear – 2011
DISPLAY “Your age is ”, age
ELSE
DISPLAY “Invalid input”
ENDIF
END

i. Draw a trace table for the pseudocode using the following input value: 1986

ii. If the program does not produce the correct answer, rewrite it so that it does.
You must write the whole program. You may not change the variable names or data
types or add new variables/constants or remove any of the variables.

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 Exercises 09

1a. Write the pseudocode for a program which will ask the user to input a number between
10 and 12. Store the number in a variable.
Use a SELECT CASE statement to do the following:
- if the input number is 10:
- write the instructions* to multiply the number by 10, divide the result by 4.5 and
display the answer
- if the input number is 11:
- write the instructions* to calculate the square of the number, add 15% to the
result and display the answer
- if the input number is 12:
- display the following message YOU HAVE WON R100-00!
- if the input number is not between 10 and 12:
- display a message telling the user that the input is not valid
* use the input variable name in the instructions and store the results/answers in variables

1b. Draw a trace table for your solution using the input value 11
1c. Draw a trace table for your solution using the input value 20

2. A television station has done a survey to find out which language group their viewers
belong to.
Each language group was given a code as follows:

Group Code
XHOSA LX
ZULU LZ
SOTHO LS
ENGLISH LE
AFRIKAANS LA

2a. Write the pseudocode for a program which will use a FOR LOOP to accept the language
group code for 100 people.
Use a SELECT CASE statement to display a message if the input is not valid or, if the
input is valid, to count the number of people from each different language group.
When there is no more input, display the following (each with a meaningful message):
- the number of Xhosa speaking people
- the number of Zulu speaking people
- the number of Sotho speaking people
- the number of English speaking people
- the number of Afrikaans speaking people

3. A radio station has done a survey to find out which type of music people like the most.
The types of music they chose from were: KWAITO HIP HOP R&B
Each music type was given a code as follows:

Type Code
KWAITO K
HIP HOP H
R&B R

3a. Write the pseudocode for a program which will use a DO WHILE loop to accept each
person’s choice (K or H or R). Use a sentinel value of Z to end the input.
Use NESTED IF statements to count the number of people who chose each different type
of music.
When there is no more input, display the following (each with a meaningful message):
- the number of people who chose KWAITO
- the number of people who chose HIP HOP
- the number of people who chose R&B

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


3b. Draw a trace table for your pseudocode using the following input:
K
p
Z

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 Exercises 10

1. Write the pseudocode for a program which will use a DO WHILE LOOP to accept a
student name and 2 marks for the student.
The program must do the following input validation:
a. validate that each of the input marks is numeric
b. validate that each of the marks is not less than 0
If the data is not valid, display a message which explains the error(s) and do not do the
calculations.
If the data is valid:
The program must calculate and display the student’s average mark. The average must be
rounded to 0 decimal places.
Repeat the input until ZZ is input for the student name.
When there is no more input, display the number of students for whom valid data was
input.

2. A paint factory is taking orders for different colours of paint. Each customer can only order
one colour.
Details are:

COLOUR CODE PRICE PER LITRE


WHITE W R20-00
GREEN G R35-00
SILVER S R45-00

Write the pseudocode for a program which will accept the code of the colour wanted and
the number of litres. This is the order for one customer. A customer will receive a discount
of 10% off the calculated price if the calculated price is more than R1000-00
The program must do the following input validation:
a. Colour code must be valid
b. Number of litres must be numeric and greater than 0 and an integer
If the data is not valid, display a message which explains the error(s) and do not do the
calculations.
If the data is valid:
Calculate and display the final price the customer must pay after discount (if any) has
been subtracted.
Accumulate or count the required totals.
Repeat the input until Z is input for the colour.
When the input is complete, display - in the same order as below:
a. The total litres ordered for the silver paint
b. The total price charged for the white paint (i.e. after any discount)
c. The total number of orders for the green paint
d. The total litres ordered altogether (i.e. for all colours)
e. The total discount given for all the orders (i.e. for all colours)
f. The total number of orders (i.e. for all colours)
** Remember to round all multiplication and division calculations to 2 decimal places

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 PRAC 01

Create a Visual Basic program for Exercises 03 Question 3:


i.e.
Write a program that does the following:
Asks the user to input two numbers then calculates and displays the sum of the numbers
and the difference between the first and second number. (Display meaningful messages
with the answers).

Give your solution the name PRAC01


** Don’t forget to save often when you are typing!

Do the following:
a. When typing in your instructions, practise using Intellisense until you feel comfortable with
it.
b. Write the program and run it using the input values 60 and 20.
Does it show the correct answers? If not, why not? FIND YOUR BUG!
c. Set a breakpoint on your first instruction after the declares and trace your program.
Make sure the LOCALS WINDOW is showing.
Pay attention to when the values in the variables change.
Clear the breakpoint.
d. Run the program and input a name instead of a number. What happens? Why?
What type of error is this?
e. Close your solution and then close VB.
Start VB again and open your solution for this prac.
f. Change the sum calculation to use a variable name that is not declared. What happens at
design time? What happens at run time? What type of error is this?
g. Move the calculation for the sum of the numbers to after the instruction that displays the
result of the calculation. What happens when you run the program? What type of error is this?
h. Omit the last Console.Readline() (before the End Sub). What happens when you run the
program?

** Before you close your solution, make sure that you are saving a correct solution

DEV1 PRAC 02

Create a Visual Basic program for Exercises 02e Question 1:


i.e.
Write a program that does the following:
a. Displays messages which ask the user to input a student’s first name, name of the
town or village where they live and their age (as a whole number)
b. Stores all of the input in variables
c. Calculates how old the student will be in 67 years’ time and stores the result in a
variable d. Displays the following on the screen:
Good morning followed by the student’s first name
You live in followed by the name of the town/village that the student lives
in
In 67 years you will be followed by the result of your calculation

Give your solution the name PRAC02


** Don’t forget to save often when you are typing!

Practise tracing your program.

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 PRAC 03

You need to write a program that does the following:


Asks the user to input the prices of 4 items and then calculates and displays the total VAT
(15% of the total price) and the total amount including VAT that the customer must pay.
Display meaningful messages with the answers. See if you can display R before the
calculated values.

Do the following:
a. Draw an IPO chart
b. Write the pseudocode
c. Write the VB program

Give your solution the name PRAC03


** Don’t forget to save often when you are typing!

Practise tracing your program.

DEV1 PRAC 04

The Walter Sisulu Youth Group is gathering information about its members.
For each member they will input the following:
id number, gender (which will be M or F ), age, town (which will be in uppercase)
They want a program which will accept the above input and do the following:
a. If the member is a male under the age of 18, display the member’s age.
b. If the member is a female who lives in PEDDIE, display the message SHE LIVES IN
PEDDIE
c. If the member is over 18 but under 21, display the member’s id number.

Do the following:
a. Draw an IPO chart
b. Draw the flowchart
c. Write the VB program

Give your solution the name PRAC04


** Don’t forget to save often when you are typing!

Practise tracing your program.

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 PRAC 05

A security company pays its workers for each hour worked according to their job grade (A or
B).
If they work more than 40 hours a week, they are paid an overtime rate of 50% more than
their normal hourly rate for every hour over 40.
They want a program which will accept a worker’s surname, job grade and hours worked. The
program must then calculate and display the worker’s normal pay (i.e. for hours up to 40),
overtime pay (i.e. for hours over 40) and total pay (normal pay plus overtime pay).
If the worker has not worked more than 40 hours, the overtime pay is 0.
The normal hourly rate for each job grade is as follows:
Job Grade A - normal hourly rate is R40
Job Grade B - normal hourly rate is R30

Example: If a worker on job grade A works 50 hours his normal pay will be 1600 (40*40), his
overtime pay will be 600 (10*60) and his total pay will be 2200.
If a worker on job grade B works 20 hours his normal pay will be 600 (20*30), his
overtime pay will be 0 and his total pay will be 600.

Do the following:
a. Draw an IPO chart
b. Write the pseudocode
c. Draw a trace table to check your pseudocode (use the input values shown in the example)
d. Write the VB program

Give your solution the name PRAC05


** Don’t forget to save often when you are typing!

Practise tracing your program.

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 PRAC 06A

A radio station has done a survey to find out which type of music people of different ages
prefer.
The types of music they chose from were: KWAITO HIP HOP R & B ROCK

Each type was given a code as follows:

Type Code
KWAITO A
HIP HOP B
R&B C
ROCK D

They want a program which will accept each person’s choice (A or B or C or D) and the
person’s age. When there is no more input, the program must display the following in the
order shown (each with a meaningful message):
a. the number of people under 18 who chose HIP HOP
b. the number of people 50 years or older who chose KWAITO
c. the number of people who chose ROCK
d. the number of people over 25 but under 40 who took part in the survey

The input must be repeated for 5 people.

Do the following:
a. Write the pseudocode
b. Write the VB program

Give your solution the name PRAC06A


** Don’t forget to save often when you are typing!

Practise tracing your program.

DEV1 PRAC 06B

Rewrite the program created for PRAC 06A – this time use a DO WHILE loop which accepts
the input until Z is input for the choice.

Do the following:
a. Write the pseudocode
b. Write the VB program

Give your solution the name PRAC06B


** Don’t forget to save often when you are typing!

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 PRAC 07

Your friend who owns a bookshop wants a program which will do the following:
Accept the price of a book and the quantity (how many) a customer wants. (The price
includes VAT). The program must then calculate and display the total for each book and
accumulate the total.
[Example: if the input is 125.00 2 it means the customer wants 2 copies of a book
which cost 125.00 each, which makes a total of 250.00 for that book.]
Repeat the input for 3 different books.
When there is no more input calculate and display (with meaningful messages):
a. the discount amount the customer will be given if the discount is 10% of the accumulated
total.
b. the total amount the customer must pay after the discount has been subtracted.

The program must use a FOR loop.

Do the following:
a. Write the pseudocode
b. Write the VB program

Give your solution the name PRAC07


** Don’t forget to save often when you are typing!

Practise tracing your program.

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 PRAC 08a

Write a program which will ask the user to input 3 numbers and store them in variables called
var1, var2 and var3.
If the value in variable var1 is greater than the value in variable var2, increase the value in
var1 by 10%, else, if the product of the values in var2 and var3 exceeds 100, reduce the
value in var3 by 20%, else, halve the value in the variable var1.
Display the sum of the values in var1 and var2 on the screen.

Use a NESTED IF. Repeat the instructions until the user inputs 0 0 0 for the 3 numbers.

Do the following:
a. Write the pseudocode
b. Write the VB program

Give your solution the name PRAC08a


** Don’t forget to save often when you are typing!

Practise tracing your program.

DEV1 PRAC 08b

A cell phone company is offers the following sms bundles:

CODE COST
S1 R50-00
S2 R65-00
S3 R75-00
S5 R100-00

Write a program which will ask the user to input the code of the bundle wanted by the
customer and how many bundles of that code the customer wants. The customer must pay an
additional R5-00 for a service fee.
Use a SELECT CASE to calculate and display the total price the customer must pay.

Use a FOR LOOP to repeat the instructions 5 times.

Do the following:
a. Write the pseudocode
b. Write the VB program

Give your solution the name PRAC08b


** Don’t forget to save often when you are typing!

Practise tracing your program.

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA


DEV1 PRAC 09a

Write the VB program for Exercises 10 number 1.

Give your solution the name PRAC09a


** Don’t forget to save often when you are typing!

DEV1 PRAC 09b

Write the VB program for Exercises 10 number 2.

Give your solution the name PRAC09b


** Don’t forget to save often when you are typing!

©WSU DEVELOPMENT SOFTWARE 1 THINK / CINGA

You might also like