Professional Documents
Culture Documents
1. TUTORIAL 1
1.1 Indicate the exact output that will be produced after the following code has been
executed: (5)
mainModule
num1 = 5
num2 = 10
do while num1 < num2
result = DoFunc1 (num2, num1)
display result
num1 = num1 + 3
loop
display num1, “,”, num2
answer = DoFunc2 (num2)
display “Answer = ”, answer
if result = answer then
display “The same”
else
display “Not the same”
endif
end
1 DSO17AT
2.2 Write a full algorithm in pseudocode to solve the following:
Troy Baloyi owns four communes near Excellent University of Technology, as follows:
He wants you to write a program to calculate the rent per month for each room of each
commune. Each commune has a different number of rooms. The rent is determined by the
size of the room. Enter for each commune, for each room in the commune, the name of the
room, as well as the length and width of the room. Calculate the size of the room in a function.
Then determine the rent for the room in another function. Display the rent. Also determine
the total rent that each commune brings in, as well as the address of the commune that
brought in the highest rent. Determine this address also in a function.
2 DSO17AT
2. PRACTICAL ASSIGNMENT 2
2.1 Convert the following design into C++. Also enter appropriate comments and any
additional instructions required by the compiler. See figure 1 for sample output:
DetermineBookWorth
~ This program determines the price of books delivered to a
~ bookstore. The price is dependent on a certain mark-up on the
~ purchase price, that in tern is dependent on the mark-up code.
totAmntForDelivery = 0
highestWorth = 0
highestSupplName = “”
moreBoxes = true
do while moreBoxes
boxWorth = 0
display “Enter the name of the supplier of the box ”
enter supplierName
display “How many books in this box?”
enter numBooks
for book = 1 to numBooks
display “Enter the book’s mark-up code”
enter markUpCode
display “Enter the purchase price of the book”
enter purchasePrice
3 DSO17AT
endselect
return price
4 DSO17AT
2.2 Consider the following programming problem and solution algorithm. Code this
solution in C++, then compile and run it. See figure 3 for sample output.
For each customer, enter the number of items bought and the unit price for one
item. The amount due must then be calculated and displayed as follows:
Call a function to determine the percentage discount:
o If a user bought 5 or fewer items, no discount is granted.
o If the user bought more than 5 but less than or = 10 items, 5%
discount is granted
o If the user bought more than 10 but less than or equal to 20 items,
7.5% discount is granted
o If the user bought more than 20 items, 10% discount is granted.
o The function must return the value 0, 5, 7.5 or 10, depending on the
outcome of the if-statement.
Calculate the initial amount due in the main algorithm
Call a second function to calculate the discount amount
Deduct the discount amount from the amount due in the main algorithm
Call a third function to add 14% vat to the amount due
Display the answer in the main algorithm.
Repeat this for a number of purchases. In the end display the total amount due by all
customers. Accumulate the total amount due
MainAlgorithm
totalAmntDue = 0
display “Enter the number of items bought (-1 to end)”
enter number
do while number <> -1
display “Enter the unit price”
enter price
discountPerc = CalcDiscPerc(number)
amountDue = number * price
discountAmount = CalcDiscount(amountDue, discountPerc)
amountDue = amountDue – discountAmount
amountDue = CalcFinal(amountDue)
display “The amount due = R”, amountDue
totalAmntDue = totalAmntDue + amountDue
5 DSO17AT
endif
return discPerc
function CalcDiscount(valAmt, valDisc)
return valAmt * valDisc / 100
function CalcFinal(valAmtDue)
return valAmtDue * 1.14
2.3 Write а value-turning function, isVowel, that returns the value true if а given
character is а vowel and otherwise return false.
Write а program that prompts the user to input а sequence of characters and
outputs the number of vowels. (Use the function isVowel)
Refer to figure 1 and 2 for sample output. Save your source file as
runTest11.cpp. Include your student number, surname and initials, and group
at the beginning of the source files. Submit only the C++ source file.
6 DSO17AT
Figure 1: output 1
Figure 2: output 2
7 DSO17AT
INSTRUCTIONS TO SUBMIT PRACTICAL ASSIGNMENT 2
1. Copy and paste all the Practical Assignment Solutions into one document (e.g. Ms Word
or Notepad or Any code editor)
2. Include the Student Number, Surname and Initials, Group and Lecturer Surname as
comments inside the document.
3. Logon to myTutor
4. Select the Subject on myTutor Dashboard
5. Click the Delicious Dishes link on the left menu
6. Click on Delicious Dish1 link (Not on the Attached File)
7. Click Browse My Computer button to attach your file
8. Navigate to the file that contains all your Programs and click Open button from the
Choose File Dialog
9. Click on Submit Button on from Top-Right or Bottom-Right of web page
8 DSO17AT