Lab 3 Introduction to PASS, and Exercises on Operators and Basic I/O

advertisement
Lab 3
Introduction to PASS, and Exercises on Operators and Basic
I/O
2. Exercises on Operators and Basic
I/O
Q1a.
 Download area.cpp file from the course website.
 There are syntax/logical errors in this area.cpp file,
please correct them.
3
Program reads the width and height of a rectangle.
Is the program easy to
understand? Why?
The program computes and output the area of the rectangle.
2. Exercises on Operators and Basic
I/O
Q1b.
 Revise program to print notes for the input and output of
the program
 Test your program using PASS
5
2. Exercises on Operators and Basic
I/O
Q1c: Improve the programming style of the program
 More meaningful variable name to reflect the purpose of
the variable
 Indentation (use the tab character to indent)
 Add comments;
6
2. Exercises on Operators and Basic
I/O
Q2a: Body Mass Index (BMI)
 Read the weight and height of a person
 Calculate and print the Body Mass Index (BMI)
 Test your program using PASS
7
2. Exercises on Operators and Basic
I/O
 - Consider the data type needed, int or double?
 - To print to 2 decimal places, you may use
cout<<setprecision(2).
 - To use setprecision(), you need #include
<iomanip>
8
2. Exercises on Operators and Basic
I/O
Q2b: Body Mass Index (BMI) in pounds
 1 kg = 2.21 pounds
 Test your program using PASS
9
2. Exercises on Operators and Basic
I/O
Q3: Write a program to converts the input value to
Minutes and Seconds
 Read in the number of seconds
 Converts it to minutes and seconds.
 Test your program using PASS
10
2. Exercises on Operators and Basic
I/O
Q4: Write a program to converts the input value to Hours,
Minutes and Seconds
 Problem in Q3
 60 minutes equal to 1 hour.
 Test your program using PASS
11
Download