0 valutazioniIl 0% ha trovato utile questo documento (0 voti)
53 visualizzazioni3 pagine
The document describes a C programming lab assignment involving selection structures like if/else statements and switch cases. It provides 4 questions as examples, including programs to calculate commission based on sales amount, parking fees based on hours, determining education level from years of schooling, and calculating different shapes' areas based on user selection and input values.
The document describes a C programming lab assignment involving selection structures like if/else statements and switch cases. It provides 4 questions as examples, including programs to calculate commission based on sales amount, parking fees based on hours, determining education level from years of schooling, and calculating different shapes' areas based on user selection and input values.
The document describes a C programming lab assignment involving selection structures like if/else statements and switch cases. It provides 4 questions as examples, including programs to calculate commission based on sales amount, parking fees based on hours, determining education level from years of schooling, and calculating different shapes' areas based on user selection and input values.
Design a program to compute the commission payable to a sales person base on the following scheme. Sales below RM100 will entitle 20% commission. Sales of RM100~RM500 will entitle 30%. Sales above RM500 entitle 40% commission. For example, if the sales if RM50, then the commission is RM10. If the sales are RM300, then the commission is RM90 and if the sales are RM600, the commission is RM150. Based on the algorithm below, write the full program.
Pseudocode
begin print Enter sales: read sales if (sales < 100) rate = 0.2 else if (sales <=500) rate. = 0.3 else rate = 0.4 end_if comm = rate x sales print comm end
Flowchart
begin print Enter sales: read sales sales < 100 sales <= 500 comm = rate x sales print comm
end rate = 0.2 rate = 0.3 rate = 0.4 y y n n C Programming Lab Universiti Tenaga Nasional
Question 1
Design a program to compute the car parking fee base on these rates: first 2 hour, RM1 per hour, the following hours is RM2 per hour. Design the program using pseudo codes. Example, parking fee of 4 hours is (RM1 x 2) + (RM2 x 2) = RM6
Question 2
Write a multiple-alternative if statement to display a message indicating the educational level of a student based on the students number of years of schooling. Use the table below. Print a message to indicate invalid data as well.
Number of Years Educational Level 0 None 1 5 Elementary 6 8 Middle school 9 12 High School More than 12 College
Question 3
Write a program that will computes the tax based on the tax table shown below:
Salary range (RM) Base tax (RM) Percentage of excess 0.00-14999 0.00 15 15000 - 29999 2250 18 30000 - 49999 5400 22 50000 79999 11000 27 80000 150000 21600 33
The user needs to enter his salary for a year and the program will compute the tax.
Formula: tax = (salary lowest range of the salary) * percentage of excess + base tax
For example: if a users salary is 15700, the tax that he/she needs to pay is
tax = (15700 15000) * 0.18 + 2250 tax = 2367
C Programming Lab Universiti Tenaga Nasional
Question 4
Write a program that will do task according to users selection based on the table below. For example if the user enter 1, the user will be asked to enter an input to calculate the area of a circle. You may want to add a menu to help the user to understand your program. Use switch.
Selection Inputs Formula Output 1 radius pi * radius * radius Area of a circle 2 width, length width * length Area of a rectangle 3 length length * length Area of a square 4 length ((3 * 3) / 2) * length * length Area of a hexagon 5 height, base * height * base Area of a triangle