0% found this document useful (0 votes)
112 views

Tutorial Sheet 1-Introduction To Algorithm-Software Engineering

This tutorial sheet provides 17 algorithms for students to write, including algorithms to: 1. Calculate the area of a rectangle given its two sides 2. Calculate the square of a given integer 3. Calculate total revenue given price and quantity using a formula 3 sentences
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

Tutorial Sheet 1-Introduction To Algorithm-Software Engineering

This tutorial sheet provides 17 algorithms for students to write, including algorithms to: 1. Calculate the area of a rectangle given its two sides 2. Calculate the square of a given integer 3. Calculate total revenue given price and quantity using a formula 3 sentences
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Tutorial Sheet 1-Introduction to Algorithm-Software Engineering

1. Write an algorithm and draw a flowchart that will read the two sides of a rectangle and
calculate its area.
2. Write an algorithm which prompt the user for an integer and print the square of that integer
3. Write an algorithm that prompts a user for numbers and determines total revenue using the
following formula: Total Revenue = Price * Quantity.
4. Write an algorithm and draw a flow chart to calculate 24 using sequence control structure.
5. Write an algorithm and draw a flow chart to calculate 24 using a loop. Modify your algorithm to
compute 21000
6. Write down an algorithm and draw a flow chart to count and print from 1 to 10.
7. Write an algorithm and draw a flow chart to calculate the factorial of a number (N). Verify your result
by a trace table by assuming N = 5.
Hint: The factorial of N is the product of numbers from 1 to N.
8. Write an algorithm to determine a student’s final grade and indicate whether it is passing or
failing. The final grade is calculated as the average of four marks.
9. Give the values of the variables A, B and C after the execution of the following instructions?
10. Write an algorithm and flowchart which a given number N increased by 100 if N is less than
100, otherwise N is decreased by the 100. Print this result.
11. To display the first ten natural numbers using DO WHILE loop.
12. To display the first ten natural numbers using REPEAT-UNTIL loop.
13. Write a program which consists to say whether a student has passed a test or he has failed,
being given an average. The student has passed if the average is greater than 12.00
14. Write an algorithm which ask the user to enter an integer, test the integer and say whether the
number is an even or not.
15. The price of CDs in a shop varies according to the number purchased.
 350 FCFA each if the number of CDs purchased is less than 10.
 300 FCFA each if the number of CDs purchased is between 10 and 20.
 200 FCFA each if the number of CDs purchased is more than 20

Write an algorithm which prompt the user to the number of CDs to buy and display the
amount to pay.
16. Write an algorithm that solve an equation of second degree (in the form ax2 + bx + c = 0).
The program receive the three coefficients a, b and c. (use the function sqrt() to calculate the
square root of a number). Display either the solution(s) or a message when the equation has
no solution in .
17. Develop an algorithm (Flowchart and pseudocode) for the problem of printing numbers
between 0 and 100.
18. Create a counting program that counts from 1 to 100 in increments of 5. Create a
counting program that counts backward from 100 to 1in decrements of 10.
19. Write an algorithm and draw a flowchart to
a) read an employee name (NAME), overtime hours worked (OVERTIME), hours absent
(ABSENT) and
Bonus Schedule
OVERTIME – (2/3)*ABSENT Bonus Paid
>40 hours 50,000 FCFA
>30 hours but <=40 hours 40,000 FCFA
>20 hours but <=30 hours 30,000 FCFA
>10 hours but <=20 hours 20,000 FCFA
<=10 hours 10,000 FCFA
b) determine the bonus payment (PAYMENT)

20. Use trace table to test the accuracy of the logic of the following pseudocode.
Use the following test data as input: 12, 23, 34, 0

Sum = 0
Read Number
While Number <> 0 do
Sum = Sum + Number
Read Number
Endwhile
print “ Sum of number is”, Sum

21. Test the logics of the pseudocode below for correctness using a trace table. Use the following
as your test data: -12, 23, 30, 0, -120, 50, 0, 0, 15, 999
NCount = 0 Statements to
ZCount = 0 initialize count
PosSum =0

Read Number
If statement to
while Number <> 999 do test if number is
less than zero
if Number < 0 then
NCount = NCount + 1
endif If statement to
test if number is
if Number <> 0 then zero
ZCount = ZCount + 1
Endif

If Number > 0 then If statement to


PosSum = PosSum + Number test if number is
Endif positive
Endwhile

Print “Number of negative numbers is ”, NCount Statements to


Print “Number of zeros is”, ZCount print content of
Print “Sum of positive numbers is”, PosSum the variable

22. Do a trace table to show the final state of the variable in the following

Sum = 0
N = 10
While N < 40 do
Sum = Sum + N
Print N, Sum
N=N+ 5
Endwhile

23. Use a trace table to determine what is printed by the following algorithm.

Sum = 0
N = 20
While N < 30 do
Sum = Sum + N
Print N, Sum
N=N+3
endwhile
24. Use a trace table to determine what is printed by the following algorithm.

Count = 1
X=2
While Count < 25 do
X=X+2
Print Count, X
Count = Count + 5
Endwhile

25.The following flowchart shows how barcodes are used at the point of sale in an automatic
stock control system. Select statements from the list below, using numbers only, to complete
the flowchart.
26.Carefully study the following flowchart:
Complete the trace tables for the following two sets of test data:
a) number = 7, temp = -5, 0, 5, -4, 0, 10, -2
b) number = 6, temp = 21, 20, 30, 19, 21, 15

27. The following flowchart inputs the size of a number of car engines; a value of -1 stops the
input. The following information is output: average engine size and number of engines with size
> 1.5.
Complete the trace table for the following input data: 1.8, 2.0, 1.0, 1.3, 1.0, 2.5, 2.0, 1.3, 1.8, 1.3, -
1

You might also like