0% found this document useful (0 votes)
5 views9 pages

Lab Practice

Programming

Uploaded by

miqie 03
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)
5 views9 pages

Lab Practice

Programming

Uploaded by

miqie 03
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/ 9

TK2053 – PROGRAMMING PARADIGM

LAB PRACTICES PREPARED BY: DR. WANDEEP KAUR

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:

Category Age Price (RM)

Toddler 0-3 Free

Kid 4-12 15.75

Teen 13-17 22.50

Adult 18-64 30.00

Senior 65+ 12.50

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.

The system should prompt an error in the following situations:

• The number of tickets purchased must be no less than one


• The number of tickets purchased must be an integer value
• The number of tokens purchased must be an integer value
• Any other error prompt you deem necessary
TK2053 – PROGRAMMING PARADIGM
LAB PRACTICES PREPARED BY: DR. WANDEEP KAUR

SAMPLE RUN

Welcome to The Enchanted Kingdom Ticketing System!

Enter the number of toddler tickets (0-3 years, Free): 0

Enter the number of kid tickets (4-12 years, RM15.75): 2

Enter the number of teen tickets (13-17 years, RM22.50): 0

Enter the number of adult tickets (18-64 years, RM30.00): 2

Enter the number of senior tickets (65+ years, RM12.50): 1

Enter the number of token units to purchase (each unit is RM35.75): 3

Receipt Itinerary

Tickets: RM104.00

Token purchased: RM100.50 + RM107.25

Discount: RM37.41

Total Amount to be paid: RM274.34


TK2053 – PROGRAMMING PARADIGM
LAB PRACTICES PREPARED BY: DR. WANDEEP KAUR

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:

• The number of hours worked is a positive integer.


• The number of hours late is a positive integer.
• Any other errors you deem necessary.

SAMPLE RUN

Welcome to the Bus Driver Payment Calculator!

Enter the number of hours worked in a month: 311

Enter the number of hours late: 4

Is the driver promoted to Driver of the Week? (1 for Yes, 0 for No): 1

Normal Wage Hours: RM3060.00

Overtime payment: RM2454.37

Late Penalty: RM502.00

Driver of the week bonus: RM501.23

Total pay: RM5513.60


TK2053 – PROGRAMMING PARADIGM
LAB PRACTICES PREPARED BY: DR. WANDEEP KAUR

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.

Following is a sample of the current inventory with prices:

Product Quantity In Unit Price


Store (RM)

Milk (3 L) 54 19.06

Butter 114 9.88

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.

The system should prompt an error in the following situations:

• Quantity must be a positive integer.


• Unit price must be a positive number.
• Any other error prompt you deem necessary.
• If user purchases quantity that is more than in store then prompt error
TK2053 – PROGRAMMING PARADIGM
LAB PRACTICES PREPARED BY: DR. WANDEEP KAUR

SAMPLE RUN

Welcome to the Grocery Store Inventory Management System!


Please find the following items

Product Quantity In Unit Price


Store (RM)

Milk (3 L) 54 19.06

Butter 114 9.88

Bread 36 3.75

Enter the number of product to be purchased: 3

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

Total sale value: RM82.76

Inventory After Sale:


Product Quantity In Unit Price
Store (RM)

Milk (3 L) 52 19.06

Butter 111 9.88

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:

• The number of students is a positive integer.


• The number of courses is a positive integer.
• Any other error prompt you deem necessary.

GPA Calculation Formula: (Σ (Grade Points * Credit Hours)) / (Σ Credit Hours)

CGPA Calculation Formula: (Σ (GPA * Credit Hours)) / (Σ Credit Hours)


TK2053 – PROGRAMMING PARADIGM
LAB PRACTICES PREPARED BY: DR. WANDEEP KAUR

SAMPLE RUN

Enter the number of students: 2

Student 1:

Enter the number of courses: 4


Enter the course name for course 1: Introduction to Programming
Enter the credit hours for Introduction to Programming: 3
Enter the grade obtained for Introduction to Programming: A
Enter the course name for course 2: Data Structures and Algorithms
Enter the credit hours for Data Structures and Algorithms: 4
Enter the grade obtained for Data Structures and Algorithms: B
Enter the course name for course 3: Database Management Systems
Enter the credit hours for Database Management Systems: 3
Enter the grade obtained for Database Management Systems: B+
Enter the course name for course 4: Computer Networks
Enter the credit hours for Computer Networks: 3
Enter the grade obtained for Computer Networks: A-

GPA for Student 1: 3.68

CGPA for Student 1: 3.63

Student 2:

Enter the number of courses: 3


Enter the course name for course 1: Web Development
Enter the credit hours for Web Development: 4
Enter the grade obtained for Web Development: B
Enter the course name for course 2: Operating Systems
Enter the credit hours for Operating Systems: 3
Enter the grade obtained for Operating Systems: A-
Enter the course name for course 3: Software Engineering
Enter the credit hours for Software Engineering: 3
Enter the grade obtained for Software Engineering: A

GPA for Student 2: 3.67

CGPA for Student 2: 3.72


TK2053 – PROGRAMMING PARADIGM
LAB PRACTICES PREPARED BY: DR. WANDEEP KAUR

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:

Welcome to the Hospital Bill Calculator!

Enter patient's name: John Doe


Enter the number of different medical services received during the hospital stay: 5
Enter the cost for in house medications: RM120.50
Enter the room charges per night: RM85.25
Enter the hospital charges: RM200.75
Enter the facility charges: RM50.00
Enter the surgery charges (if any, enter 0 if none): RM0.00
Enter the outpatient medication cost: RM45.80
Does the patient have medical insurance? (1 for Yes, 0 for No): 1

Total Bill Amount for John Doe: RM716.81

You might also like