1-Write a statement which defines an int named constant ASSIGN_PTS which is init
ID: 3561998 • Letter: 1
Question
1-Write a statement which defines an int named constant ASSIGN_PTS which is initialized to 45.
2-Suppose a, b, and c are defined as int variables. Suppose NUM has been defined as an int named constant. Suppose result has been defined as a double variable. Write a statement that assigns to result the sum of a, b, and c divided by NUM. a, b, and c must be added before dividing by NUM. Furthermore, we want the division to be performed as floating point division, so typecast NUM to double.
3-Which C++ Standard Library header file must be included to use the setw() and setprecision() stream manipulators?
4-Let a, b, c, d, w, x, y, z, and result be defined as int variables. Write a statement which calculates aw + bx + cy +dz and assigns the result toresult.
5-Write one statement that configures cout so it will display real numbers in (1) fixed notation, (2) with two digits after the decimal point, and (3) will display values right-justified in a field.
6-Let a be defined as an int variable. Write a statment that send a to cout so it will be displayed in a field of width 5.
7-Let a and b be defined as int variables. Write one cout statement that will send a to cout and displayed in a field of width 5 and send b to cout displayed in a field of width 7.
Explanation / Answer
1-Write a statement which defines an int named constant ASSIGN_PTS which is initialized to 45.
const int ASSIGN_PTS = 45;
2-Suppose a, b, and c are defined as int variables. Suppose NUM has been defined as an int named constant.
Suppose result has been defined as a double variable.
Write a statement that assigns to result the sum of a, b, and c divided by NUM. a, b, and c must be added before dividing by NUM.
Furthermore, we want the division to be performed as floating point division, so typecast NUM to double.
double result = (a+b+c)/static_cast<double> (NUM);
3-Which C++ Standard Library header file must be included to use the setw() and setprecision() stream manipulators?
iomanip
4-Let a, b, c, d, w, x, y, z, and result be defined as int variables. Write a statement which calculates aw + bx + cy +dz and assigns the result toresult.
result = a*w + b*x + c*y +d*z;
5-Write one statement that configures cout so it will display real numbers in (1) fixed notation, (2) with two digits after the decimal point,
and (3) will display values right-justified in a field.
cout << right << fixed << setprecision(2);
6-Let a be defined as an int variable. Write a statment that send a to cout so it will be displayed in a field of width 5.
cout << setw(5) << a ;
7-Let a and b be defined as int variables. Write one cout statement that will send a to cout and displayed in a field of width 5 and send b
to cout displayed in a field of width 7.
cout << setw(5) << a << setw(7) << b ;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.