Lab 3
The purpose of this lab is to understand how to
work with
floating point numbers.
When you finish this lab you should:
- Print out a floating point number in any format you wish.
- Understand coercion and type conversion from integers.
Please do the following:
- Create the outline of a program (program shell)
- Put your name and lab3 in the comments, others will be added later.
- Declare floats x,y,z;
- Declare int a;
- set x to 3.141592653
- Make 5 copies of this line
cout << setw(10) << setprecision(10) << x << endl;
- Produce the following chart:
PI =
3.141592653
3.1415926
3.14159
3.141
3.1
- Assign a value of 4.51 to y
- Assign a value of 5.49 to z
- What is the effect of the following? Explain in your comments.
cout << y << " + .5 = " << int(y+.5) << endl;
cout << z << " + .5 = " << int(z+.5) << endl;
- Email a copy of the C code to me.