Professional Documents
Culture Documents
Learning Objectives/Outcomes:
Upon completion of this lab, the student should be able to:
i. define primitive data types, declare and initialize valid variables and constants
ii. write arithmetic expressions and assignment statements in C++
iii. write a program that read and process input and displays the result as console output
iv. write a program that process strings with the use of standard C++ string type
Practice 1: 15 minutes
Write a simple C++ program that calculates the area and circumference of a circle. First, get
the user input. Then compute and display the circle’s area and circumference with two decimal
places as illustrated in below sample run.
Sample Run:
Enter radius of circle :3.5
Practice 2: 20 minutes
Write a program that prompts the user to enter a positive integer ranging from 0 to 65535.
Subsequently, write an algorithm to break the entered integer into a sequence of individual digits
and then prints them in triangle shape as illustrated in sample run:
Sample Run:
Please enter a positive integer between 0 and 65535 : 65432
5 3
6 2
1
Sample Run:
Please enter a positive integer between 0 and 65535 : 12345
2 4
1 5
Practice 3: 35 minutes
You have saved RM 500 to use as a down payment on a car. Before beginning your car shopping,
you decide to write a program to help you figure out your monthly payment, given the car’s
purchase price, the monthly interest rate, and the period over which you will pay back the loan.
The formula for calculating your monthly payment is
payment = p[r(1+r)n/(1+r)n -1]
Where :
p = principal(the amount you borrow )
The program should prompt the user for the purchase price, the down payment, the annual
interest rate, and the total number of years. Subsequently, the program displays the amount
borrowed and the monthly payment, including a dollar sign and two decimal places as illustrated
in the sample run.
Sample Run:
****Loan Payment Calculation ******
Enter your purchasing price in RM (e.g 15000.00) : 15000
**************************************
Total borrowed amount is RM10000.00
Monthly interest is 0.625%
Monthly payment is RM200.38
Practice 3 (15 marks): Estimate 20 minutes to 40 minutes
**************************************
2
Sample Run 2:
****Loan Payment Calculation ******
Enter your purchasing price in RM (e.g 15000.00) : 65000
**************************************
Total borrowed amount is RM55000.00
Monthly interest is 0.625%
Monthly payment is RM843.60
Practice 4: 50 minutes
Write a C++ program that generates customer’s bill for a parcel delivery via sea shipment to
West Malaysia when the following information is given:
i. volumetric weight: Length(L), Width(W) and Height(H) in centimetres
ii. delivery charges price per kilometers
iii. distance in kilometers
iv. discount percentage for each customer
v. labour cost for parcel packaging and processing
The labour cost for parcel packaging and processing is fixed at RM 1.50 per cubic weight (m3).
The rate of service tax is fixed at 6%. The formula for calculating cubic weight is given as L(m)
X W(m) X H(m) /6000. The calculation for parcel delivery charges is as below:
Parcel Delivery Charges = delivery charges per m3 x
distance in kilometers x volumetric weight
The program prompts the user for the input and generates customer bills, as illustrated in the
sample run. The program’s design should use the main function to complete the following tasks:
i. Read data from the keyboard. This function is to use addresses to read all data and place
them in the calling function’s variables.
ii. Calculate and print the subtotal, , including the mathematical formula to calculate parcel
delivery and labour charges.
iii. Calculate and print the discount price on company offers.
3
iv. Calculate and print Tax price based on a constant of 6.0%
v. Calculate and print the net and total price with and without discount and tax, respectively.
vi. Print the company header and measurements.
Sample Input :
Length of Parcel(m) = > 10
Width of Parcel(m) = > 10
Height of Parcel(m) = > 20
Sample Output
Delivery : per m^3 = > 500
Charge
Distance in kilometers (KM) = > 50
Customer discount in percent(%) = > 20
ABC Sdn.Bhd
80, Jln UMS
88400, Kota Kinabalu, Sabah
PARCEL MEASUREMENT
CHARGES
*****************************THE END************************