0% found this document useful (0 votes)
30 views1 page

TK1914 Lab Assignment 1 Basic Elements On C++ and Input/Output

The document provides examples of C++ code to: 1) Read and perform calculations on two input values and output the result 2) Prompt for rectangle dimensions and output its area and perimeter 3) Read two integers, perform calculations, and output results 4) Read a name, pay rate, work hours, calculate salary, and output details 5) Prompt for length and weight inputs, convert units, and output converted values 6) Prompt for weekly work hours over a month, calculate weekly and monthly salaries, and output totals

Uploaded by

farrin92
Copyright
© Attribution Non-Commercial (BY-NC)
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)
30 views1 page

TK1914 Lab Assignment 1 Basic Elements On C++ and Input/Output

The document provides examples of C++ code to: 1) Read and perform calculations on two input values and output the result 2) Prompt for rectangle dimensions and output its area and perimeter 3) Read two integers, perform calculations, and output results 4) Read a name, pay rate, work hours, calculate salary, and output details 5) Prompt for length and weight inputs, convert units, and output converted values 6) Prompt for weekly work hours over a month, calculate weekly and monthly salaries, and output totals

Uploaded by

farrin92
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 1

TK1914 Lab Assignment 1 Basic Elements on C++ and Input/Output 1.

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.

You might also like