C++ Programming Exercise-2:: Sample Output
C++ Programming Exercise-2:: Sample Output
1. Write a program that contains statements that output the value of five or six variables
that have been declared, but not initialized. Compile and run the program. What is the
output? Explain.
2. Convert each of the following mathematical formulas to a C++ expression:
3. What is the output of the following program lines when embedded in a correct program
that declares all variables to be of type char?
a = 'b';
b = 'c';
c = a;
cout << a << b << c << 'c';
4. What is the output of the following program lines when embedded in a correct program
that declares number to be of type int?
number = (1/3) * 3;
cout << "(1/3) * 3 is equal to " << number;
5. Write a short program that declares and initializes double variables one, two, three,
four, and five to the values 1.000, 1.414, 1.732, 2.000, and 2.236, respectively. Then write
output statements to generate the following legend and table.
Use the tab escape sequence \t to line up the columns. If you are unfamiliar with
the tab character, you should experiment with it while doing this exercise. A tab
works like a mechanical stop on a typewriter. A tab causes output to begin in a
next column, usually a multiple of eight spaces away. Many editors and most
word processors will have adjustable tab stops. Our output does not
The output should be:
N Square Root
1 1.000
2 1.414
3 1.732
4 2.000
5 2.236
6. Write a C++ program to solve the second degree equation
aX2 + bX + c= 0 for any real a,b and c
Sample Output
Enter the values a,b and c with space: 1 -2 1
The value of x is: 1
7. Write a C++ program to transfer inches to centimeters (1 inch= 2.54 centimeters)
Sample Output
Enter the values of inches: 100
The value in centimeter is: 254
8. A serial transmission line can transmit 960 characters a second. Write a
program that will calculate how long it will take to send a file, given the file's
size. Try it on a 400MB (419,430,400 byte) file. Use appropriate units. (A 400MB
file takes days.)
Sample Output
Enter the size of the file: 419430400
The transmission will be completed within: 436906.67 seconds
The transmission will be completed within: 121.36 hours
The transmission will be completed within: 5.06 days