Professional Documents
Culture Documents
College of Science
Department of Computer Science
COMP2002, Spring 2012
Week 4 Lab Exercises
Exercise 1 (suggested time 10 minutes): Create a new project for Lab3 and add the following C++ code:
#include <iostream>
int main ()
{
double a, b, c;
a = 3.1415926534;
b = 2006.0;
c = 1.0e-10;
cout << a << '\t' << b << '\t' << c << endl;
cout << fixed << a << '\t' << b << '\t' << c << endl;
cout << scientific << a << '\t' << b << '\t' << c << endl;
return 0;
}
Observe the differences in the format of the numbers using different output manipulators.
Exercise 2 (suggested time 15 minutes): Modify the code to get the output as shown below.
Write, compile, link and execute a C++ program to calculate and display the average of 4 real numbers
given by the user. The output should be formatted as shown below.
where xxxxx.xx represents a field of width 8 including 3 digits to the right of the decimal point.
Exercise 4:
Write, compile, link and execute a C++ program to calculate and display the natural logarithm deviation
of 4 real numbers given by the user. The output should be formatted as shown below.
The natural logarithm deviation of n numbers is given by:
a) Using this formula write a C++ program that calculates and displays the natural logarithm deviation
of 4 real numbers given by the user. The result should be displayed as shown below.
where xx.xxxx represents a field of width 8 including 4 digits to the right of the decimal point.