0% found this document useful (0 votes)
170 views10 pages

FPPGG Tutorial 3 PDF

This document provides instructions for a tutorial assignment with the following key details: 1. The assignment is due on a date to be announced in class and is to be completed during class time. 2. Students should consult even if they think they know the answers to fully understand the subject matter. 3. The theory section contains questions about writing pseudocode for loops with given variable values and determining loop execution details. 4. The practical section involves converting algorithms and IPO charts into C++ programs, including one to calculate ticket costs and another to calculate student test scores and statuses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views10 pages

FPPGG Tutorial 3 PDF

This document provides instructions for a tutorial assignment with the following key details: 1. The assignment is due on a date to be announced in class and is to be completed during class time. 2. Students should consult even if they think they know the answers to fully understand the subject matter. 3. The theory section contains questions about writing pseudocode for loops with given variable values and determining loop execution details. 4. The practical section involves converting algorithms and IPO charts into C++ programs, including one to calculate ticket costs and another to calculate student test scores and statuses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Tutorial 3 : Learning unit F 2019 S2

Due date: To be announced in class


Time: During class time
Slot will be announced in class

NB:
Please consult on these exercises even if you think you know the
answer you can even utilize the communication groups you have
for consultations.

Theory Section: Do not use Visual studio or any other compiler to answer this
Se questions, this will help you get a better understanding of the subject
matter at hand.

Question 1:

1.1 In each of the following cases, write only the specified structures do not write the while
algorithm. Make use of the pre-test loop (for-loop and do-while) in pseudocode using
the variable names as provided.
1.1.1 Use a counter variable called count that has an initial value of 5, a final value of
20, and an increment of 2.
1.1.2 Use a counter variable called count that has an initial value of 1.05, a final value of
16.5, and an increment of 0.2.

1.2 In each of the following cases indicate the following:


 The number of times that the loop will execute,
 The value of x after execution of the loop and
 The value of z after execution of the loop. You may assume that the initial value of z
is 0 in each case.

FPPGG01 Tutorials
1
1.2.1 for x = 31 to 15 step -3
z = z + (x – 5)
next x

1.2.2 for x = 1 to 7 step 4


z=9
next x

1.2.3 for x = 1 to 33 step 9


z=z*x
next x

1.2.4 z = 1
for x = 1 to 6 step 3
z=z+1
for y = 6 to 3 step -1
z=z+y*2
next y
next x

1.2.5 x = -4
z=1
do while x <= 7
display z, “ “ , x ~ On the same line
z=z+1
x=x+2
loop

1.2.6 x = 6
Z = 15
do
display x , “ ” z
x=x–1
z=z+1
loop until x <= 4

FPPGG01 Tutorials
2
1.3 Study the following algorithm in pseudocode. Display the exact output that will be
displayed after the statements have been executed:

1.3.1 ExactOutput1
x=5
y=x*4–2
z=x*y
display “This is the exact output”
for w = 0 to x step 2
y = y mod 4 + w + 3
z=z+y
display w, x, y, z ~ on new line
display “******”
next w
display “This is outside the loop”
end
1.3.2 ExactOutput2
k=5
m=2
n=9
do while k < n
k = k +2
m=m*n
loop
display k, m, n
end

1.3.3 ExactOutput3

d=2
e=4
do while d < e
display “d is less than e”
f=1
do while f < e
display “f is less than e”
f = f +1
loop
display “Outer loop ends”
d=d+1
Loop
display “Inner loop ends here”
end

FPPGG01 Tutorials
3
1.4 Rewrite the following using the specified looping structure/s:

1.4.1 Use pre-test (for-loop) and a post-test (do-loop until).

num1 = 20
do while x <= -15
display “x = “, x
x=x-3
loop

1.4.2 Use pre-test (do-while) and a post-test (do-loop until).


for value = 5 to -15 step - 3
display “x = “, x
next value

FPPGG01 Tutorials
4
Question 2

2 In each of the following cases, do the necessary planning (IPO) and write an algorithm in
pseudo code for the following:

2.1 Display every number from 1 to 25 along with it’ s value double and tripled.
2.1.1 Use a for-loop.
2.1.2 Use a while-loop.

2.2 The factorial of an integer, like 5, is the product of 5x4x3x2x1. Calculate the factorial of an
integer value entered by the user.

2.3 Write an algorithm to allow users to enter a quantity of numbers until a negative
number is entered. Then display the highest and lowest number entered.
2.3.1 Use a while-loop to determine the answer.
2.3.2 Use a do-loop-until to determine the answer.

2.4 Write an algorithm that will calculate the current tuition for Computer Systems
engineering. The current tuition is R35 000 per year, and the tuition is expected to
increase by 4 percent each year. Display the tuition each year for the next 10 years.

2.5 Write an algorithm that will accept the following for 100 students: The students’ name
(studName) and 3 test marks (marks), as well as one exam mark (examMark). The
program must calculate the final mark (finMark) for every student. The final mark
comprises of 50% of the exam mark added to 50% of the average (agv) of the 3 tests.
Display the final mark for every student.
2.5.1 Use a simple for-loop to determine the answer.
2.5.2 Use a nested for loop to determine the answer.
2.5.3 Mix the for loop with a do-while

2.6 The user must enter a positive integer between 5 and 15. If this number is valid, the
user must also choose between a triangle (T or t) and a square (S or s). Display suitable
error messages if necessary; otherwise, the program must use an asterisk to draw a
triangle or a square of the chosen size and display. Use a Select Case structure to make
the decision. Display appropriate error messages where applicable.

2.7 Do the necessary planning (IPO) and write an algorithm in pseudo code for the
following:

2.7.1 An unknown number of toddlers are taking part in a competition. 5 adjudicators


will give each competitor a mark out of 10. These marks are added together to get
a mark out of 100. Write a complete C++ program to do the following
 Enter the competitor’s number.
o -1 is entered to terminate the input.
 Enter 10 marks out of 10 for each competitor.
 Calculate the total mark.
 Compare it to the marks of previous competitors to obtain the highest mark.
FPPGG01 Tutorials
5
 Enter the number of the following competitor.
 When all data have been processed, display the number of the competitor with
the highest mark as well as the current competitor’s mark.

Practical Section:

Question 3
3.1 Convert the following design into C++:

Write C++ program for the algorithm planned in the design below into the source file. Also,
enter appropriate comments and any additional instructions required by the compiler.

The cost of a theatre ticket is R125 per ticket if less than 5 tickets are bought, R100 per
ticket if 5 to 24 tickets are bought, and R90 per ticket if a block of 25 or more tickets are
bought. Calculate the total cost for a purchaser depending on the number of tickets bought.
Continue with the process until the number of tickets bought is 0.

calculate_amount_due
~ get the first number of tickets
display “Enter the number of tickets bought – 0 to stop”
enter number
do while number <> 0
~ calculate the amount due
if number < 5
amount = number * 125
else
if number < 25
amount = number * 100
else
amount = amount * 90
endif
endif
~ display the result
display “The amount due is R“ amount
display “Ready for next customer”
display “Enter number of tickets bought – 0 to stop”
enter number
loop
end

FPPGG01 Tutorials
6
Question 4

Students in Programming 1 had written a test and they need to know their performance.
Write a C++ program that will help them achieve this using the information given below:

Enter the following input fields:


 Student number
 Student surname
 Marks obtained in a test
 The total for the test
o Convert this mark to a percentage and display the percentage on the screen in a
meaningful format that will include the student name and student number. It
must also include the status i.e.
 (Fail) if the percentage is less than 50%,
 (Pass) if the percentage is from 50% to 74.9% and
 (Pass with Distinction) if the percentage is 75% or above.
Many students did not perform well in this test and therefore the lecturer decided to
increase all final marks with 5%. Display the new percentage as well as the status of this new
percentage. This process must be repeated up until the user indicates that he or she does
want to calculate student’s marks.

Figure 4.1: Yes response

FPPGG01 Tutorials
7
Figure 4.2: No response

Question 5

Students in Engineering 1 would like to understand the concept of Ohm’s law. You are
required to write an application that will allow them to calculate the relation between
Voltage, Current and Resistance using the formulas below.

V = IR

Current (I) = V/R

Resistance= V/R

(where I is the current, V - Voltage and R is the resistance)

The program must do the following:

 Prompt the user for the calculation he/she would like to see or N/n to exit (See
Figure 5.1).
 Based on the option selected by the user (I/I, V/v, R/r),
o The user must be prompted for the related data as shown in Figure 5.2 –
Figure 5.4.
o The program must then calculate the related measurements based on the
option selected.
o Display the desired measurement.
 If an invalid option is selected an appropriate error message must be displayed, see
Figure 5.5.

NB: Use a switch for the selection

 If there are no calculations to performed, display a summary that consist of the


number of calculations performed. This number must exclude the invalid options,
see Figure 5.6.

FPPGG01 Tutorials
8
Figure 5.1 Options available

Figure 5.2 Options I/i

Figure 5.3 Options V/v

FPPGG01 Tutorials
9
Figure 5.4 Options R/r

Figure 5.5 Invalid option

Figure 5.4 Option N for termination

FPPGG01 Tutorials
10

You might also like