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

LabExe_Week9

Uploaded by

Hizal Haziq
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)
2 views

LabExe_Week9

Uploaded by

Hizal Haziq
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/ 5

LAB EXERCISE - WEEK 9

PART A

Answer TRUE (T) OR FALSE (F) for the following questions.

1. Nested IF can produce different outcomes based on each condition's evaluation (T/F)

2. Flowchart can show the selection process graphically (T/F)

3. IF-ELSE statement is necessary if there is only a single condition to evaluate and a single

action to take based on that condition (T/F)

4. A post-test iteration places the condition at the end of the loop (T/F)

5. A program that will calculate the car's devaluation at a rate of 8% per year for a period of

7 years is best using repetition control structure (T/F)

6. A loop that continues to execute endlessly is called an endless loop (T/F)

7. While loop is not capable to repeat more than one block of code at a time (T/F)

8. Loop termination is always compulsory in computer programming (T/F)

9. User interaction with a program can be implemented using selection control structure (T/F)

10. Boolean expression can be combined using logical operators (T/F)


PART B

QUESTION 1

a) Explain TWO (2) importance of repetition control structure.


b) Discuss a difference between counter-controlled loop and sentinel-controlled loop.
c) Give an example of the execution of counter-controlled loop in programming.

QUESTION 2

Given the following pseudocode:


Start
Display "Enter citizenship: "
Input citizenship
Display "Enter age: "
Input age
IF (citizenship == "Malaysian")
IF (age >= 18)
status = "Congratulation. You are qualified."
ELSE
status = "Sorry... You are not qualified."
ENDIF
ELSE
status = "Sorry... You are not qualified."
ENDIF
Display status
End

a) Rewrite the above pseudocode using the correct the indentation

b) Draw the corresponding flowchart for the above pseudocode

QUESTION 3

Number Guess is a game which ask user to guess a secret number within the range of 0 to
20. Users are only allowed to input integer within the range. The program will continue to
prompt the user for guesses until the correct number is entered.
a) Write a pseudocode using while loop for the program.
b) Given that the secret number is 12, predict the number of iterations if user entered the
following data: 2, 3, -15, 12,7
c) Suggest a way to implement for loop to develop the program instead of while loop.
QUESTION 4
Start
Set a = 0
Set b = 1
While b <= 5
Set c = 1
While c <= 3
Read ab
a = a + ab
EndWhile
c = c – 1
EndWhile
b = b – 1
Read “Total 15 numbers is:”, a
End
The purpose of the above pseudocode is to calculate the total of 20 numbers entered by the
user. Study the given pseudocode and find the errors occurred. State the error and suggest a
reasonable correction for each error.

QUESTION 5
A bookstore franchise has commissioned your company to develop a program for their online
ordering system. To start the program, customer should input their membership type (M –
Member OR N – Non-member). Customer will be able to view the catalog of available books
along with their respective prices as shown in the following table:

Book code Title Price (RM)


CN01 Mandarin: Beginner Level 1 35.00
EN05 Cooking with Hilda 120.00
CB10 ABC to Z 12.00
BZ78 Twinkle to Shine 119.00

Then, prompt the user to enter the code of their chosen book and its quantity. Allow the user
to add more items to their order. Available payment methods are cash, online transfers, and
credit/debit card. Every cashless payment will get a 10% discount on the total purchase
amount. Members will be entitled to an additional 15% discount.

Before the check-out process, customers must choose the shipping method. They can
personally collect their orders from the bookstore without any additional charges. However, if
they prefer to have their orders shipped, the cost of shipping will differ based on the type of
shipping method. The full shipping cost will be added to the overall amount calculated after
applying discounts and tax.
Shipping Cost (RM)
Self-Collect No charge
Delivery 20.00 for each order

Upon exiting the program, display the final total amount of the book order including 6% tax.
The program will calculate the total amount to be paid for each order and generate the receipt.
The receipt should contain the same information as shown below. Please display necessary
instructions to customers. Below is the sample input and output for the program. The examples
of input values are represented in italics.
Choose membership type (M - Member | N - Non-member): M
***************Book Catalog*********************
Code Title Price (RM)
CN01 Mandarin: Beginner 35.00
EN05 Cooking with Hilda 120.00
CB10 ABC to Z 12.00
BZ78 Twinkle to Shine 119.00
************************************************

Start your order


Enter book code: CN01
Quantity: 1
Do you want to add more book? (Y-Yes | N-No): Y
Enter book code: BZ78
Quantity: 1
Do you want to add more book? (Y-Yes | N-No): N
Payment method (1-Cash | 2-Online | 3-Credit/Debit card): 2
Shipping option (1-Self-collect | 2-Delivery): 2
---------------------Receipt--------------------
Item purchased : 2
Total (RM) : 154
************************************************
Membership disc.(RM) : 23.1
Cashless disc.(RM) : 15.4
************************************************
Tax (RM) : 6.93
Shipping fee (RM) : 20
------------------------------------------------
Total (RM) : 142.43
a) Write a pseudocode to illustrate the algorithm of the system.

b) Identify the process/es which require sentinel value. Then state the sentinel value.

c) Calculate the total amount to be paid after discount if the customer is a non-member
and paying with credit card. Customer also choose to collect their order at the
bookstore. The books purchased are as follows:
Book code Title Price (RM) Quantity
CN01 Mandarin: Beginner Level 1 35.00 2
EN05 Cooking with Hilda 120.00 1
CB10 ABC to Z 12.00 1

You might also like