TK1914 Lab Assignment 1 Basic Elements On C++ and Input/Output
TK1914 Lab Assignment 1 Basic Elements On C++ and Input/Output
Write C++ statements that read two values i.e. num1 and num2. Multiplies the value of num1 by 2, adds the value of num2, and then stores the result in newNum. Then write a C++ statement that outputs the value of newNum. Write a program that prompts the user to input the length and width of a rectangle and then prints the rectangles area and perimeter. (Assume that the length and the width are decimal numbers.) Write C++ statements that print the sum, difference, product, quotient, and remainder of two integers that are input interactively. Write C++ statements that read three inputs interactively i.e. a name as a string, a pay rate and wok hour as decimal numbers. Calculate a salary by multiplying the pay rate and the work hour. Assume that the salary is a decimal number. The program should be able to produce the following output, for example, if the values of the name, pay rate and work hour are Ahmad, 12.50 and 45.50, respectively, then the output is: Name: Ahmad Pay rate: RM12.50 Work hour: 45.50 hours Salary: RM568.75 5. Write a C++ statement that prompts the user to input a length and weight expressed in inches and pounds, respectively. Convert the length in inches to centimeter and weight in pounds to kilograms using the following formula: 1 inch = 2.54 centimeters 1 pound = 0.45359 kilograms Then write a C++ statement to instruct the user to key in input and then output the values in centimeters and kilograms. For example: Please enter the length in inch: 20 Please enter the weight in pound: 40 The length in centimeters = 50.8 The weight in kilograms = 18.1436 6. Write a program that prompts the user to input a weekly number of working hours for a period of a month. Then calculate and display the monthly salary based on the following formula: Salary in week 1 = RM20 * number of working hours in week 1 Salary in week 2 = RM30 * number of working hours in week 2 Salary in week 3 = RM50.50 * number of working hours in week 3 Salary in week 4 = RM60.95 * number of working hours in week 4 Monthly salary = salary in week 1 + salary in week 2 + salary in week 3 + salary in week4.
2. 3. 4.