Lab Practice
Lab Practice
LAB PRACTICE 1
The Enchanted Kingdom is organizing an event in Kuala Lumpur, Malaysia, and they need your assistance in creating a
ticketing system. The entry fees for the event are as follows:
Once visitors have paid the entry fee, they must purchase tokens for attractions and refreshments within the event.
Each ticket package requires a minimum purchase of RM100.50 worth of tokens in a single transaction, irrespective of
the number of tickets bought in the package. Additional tokens can be purchased in multiples of RM35.75. Visitors
who buy tokens worth RM150.25 or more in a single transaction will receive a 12% discount on the total payment.
This discount is only applicable for purchases of RM150.25 or more in additional tokens.
SAMPLE RUN
Receipt Itinerary
Tickets: RM104.00
Discount: RM37.41
LAB PRACTICE 2
The local bus company compensates their drivers based on the number of hours worked each week. The standard
hourly wage is RM12.75. If a driver works more than 240 hours in a month, they are paid 2.75 times their regular
hourly wage for the overtime hours. Additionally, the company imposes a lateness penalty, deducting the minimum
RM125.50 for every hour a driver is late to work. However, if a driver has been promoted to driver of the month, he
earns an additional 10% at the end of the month.
Write a program that calculates the amount of money a bus driver is paid based on the number of hours worked in a
month, considering both regular and overtime hours and penalties for lateness. The program should prompt the user
to enter the number of hours worked and the number of hours the driver was late and if he has been promoted as
driver of the week. Use user-defined functions to perform the necessary calculations.
Your program should validate the input and prompt an error in the following situations:
SAMPLE RUN
Is the driver promoted to Driver of the Week? (1 for Yes, 0 for No): 1
LAB PRACTICE 3
You are tasked with developing a bulk purchase management system for a grocery store. The system needs to keep
track of the quantity of each product, manage incoming and outgoing shipments, and provide basic reporting
functionalities. As part of the system, you are required to implement a function that calculates the value of the
remaining inventory based on the product quantity and unit price.
Milk (3 L) 54 19.06
Bread 36 3.75
Write a program in C. The program should prompt the user to enter the number of product types to be stored, the
quantity of each product, and their corresponding prices. Print the total inventory and the value of the remaining
inventory based on the provided information. Ensure that your function returns the total value as a floating-point
number. Also ensure the inventory quantity in store is updated after a purchase has been made.
SAMPLE RUN
Milk (3 L) 54 19.06
Bread 36 3.75
Product 1:
Enter the name of the product: Milk
Enter the quantity: 2 38.12
Product 2:
Enter the name of the product: Butter
Enter the quantity: 3 29.64
Product 3:
Enter the name of the product: Bread
Enter the quantity: 4 15
Milk (3 L) 52 19.06
Bread 32 3.75
TK2053 – PROGRAMMING PARADIGM
LAB PRACTICES PREPARED BY: DR. WANDEEP KAUR
LAB PRACTICE 4
You are tasked to create a program that calculates the Grade Point Average (GPA) and Cumulative Grade Point Average
(CGPA) for a group of students based on their grades in multiple courses. The program should prompt the user to input
the number of courses taken. For each course, the program should ask for the course name, credit hours, and the
grade obtained by the student.
The program should calculate the GPA for each course using the standard GPA scale as follow:
• A: 4.0
• B: 3.5
• C: 3.0
• D: 2.5
• F: 0.0
After obtaining grades for all courses, the program should calculate the CGPA by averaging the GPAs obtained for each
course based on their credit hours. The program should prompt the user to enter the number of student it wishes to
enter, the number of subjects the student is being graded for, the grade and finally calculate the GPA and CGPA. Use
user-defined functions to perform the necessary calculations. The program should also cater for grade to be non-case
sensitive.
Your program should validate the input and prompt an error on the following situations:
SAMPLE RUN
Student 1:
Student 2:
LAB PRACTICE 5
You are tasked with developing a C program to calculate the total bill for a patient's hospital stay. The program should
prompt the user to enter the patient's name and the number of different medical services received during the hospital
stay, along with their respective costs. Additionally, the program should account for any medication costs incurred,
room charges per night, hospital charges, facility charges, and surgery charges (if any). Finally, it should calculate and
display the total bill amount, considering any applicable discounts for patients with specific medical insurance.
The program should begin by prompting the user to enter the patient's name. Then, it should prompt the user to enter
the number of different medical services received during the hospital stay. For each medical service, the program
should prompt the user to enter the cost incurred. The medical services include:
• In house medications
• Room charges per night
• Hospital charges
• Facility charges
• Surgery charges (if any)
After entering the medical service costs, the program should prompt the user to enter the outpatient medication cost.
The program should calculate and display the total bill amount, which is the sum of all medical service costs plus the
medication cost. If the patient has medical insurance, apply a 15% discount to the total bill amount.
• Test the program with different inputs to ensure it calculates the total bill accurately.
• Add error handling to the program to handle invalid inputs (e.g., negative costs, non-numeric inputs).
• Modify the program to display the patient's name along with the total bill amount.
TK2053 – PROGRAMMING PARADIGM
LAB PRACTICES PREPARED BY: DR. WANDEEP KAUR
SAMPLE RUN: