0% found this document useful (0 votes)
228 views

C++ Programming Exercise-2:: Sample Output

1. The output would be undefined values since the variables were not initialized. 2. Formulas are converted to C++ expressions using standard operators like +, -, *, /. 3. The output would be "baccc" since variables a, b, and c were assigned character values and printed in order. 4. The output would be "(1/3) * 3 is equal to 1" since integer division truncates the decimal portion of 1/3. 5. A short program is written to declare double variables, initialize them to square root values, and output a legend and table formatting the values with a tab to align the columns.

Uploaded by

Munir Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
228 views

C++ Programming Exercise-2:: Sample Output

1. The output would be undefined values since the variables were not initialized. 2. Formulas are converted to C++ expressions using standard operators like +, -, *, /. 3. The output would be "baccc" since variables a, b, and c were assigned character values and printed in order. 4. The output would be "(1/3) * 3 is equal to 1" since integer division truncates the decimal portion of 1/3. 5. A short program is written to declare double variables, initialize them to square root values, and output a legend and table formatting the values with a tab to align the columns.

Uploaded by

Munir Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C++ Programming Exercise-2:

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

9. Write the output of the following C++ program


int m = 66, n;
n = ++m;
cout << "m = " << m << ", n = " << n << endl;
n = m++;
cout << "m = " << m << ", n = " << n << endl;
cout << "m = " << m++ << endl;
cout << "m = " << m << endl;
cout << "m = " << ++m << endl;
10. What statements should you include in your program to ensure that, when a
number of type double is output, it will be output in ordinary notation with three
digits after the decimal point?

March 22, 2021


HiLCoE
Problem Solving with Computer Programming I

You might also like