Please help with c++ questions T OR F 1. In C++, the body of a do-while loop is
ID: 666256 • Letter: P
Question
Please help with c++ questions
T OR F
1. In C++, the body of a do-while loop is always guaranteed to run atleast once.
2. One difference between a declared variable and a declared constant is that a variable’s value can vary at run-time, but a declared constant’s value cannot be changed after it is initialized.
3. A function may accept either pass-by-reference or pass-by-value parameters, but not both in the same function.
4. In C++, when int variables are left uninitialized, their initial value will not equal zero.
5. When working with floating-point numerical values, programmers must use care because floating-point numerical representations are always inexact.
6. When working with an if statement, an else clause is optional.
7. The logical expression: ( x <= y ) executes the same as the logical expression: ( x < y && x ==y )
8. When evaluating a complex expression that lack parenthesis such as
x = a + b - c * d / e + f;
C++ will always calculate the answer moving from left to right computing the answer as if the user entered
x = (((((a + b) - c) * d) / e) + f);
MC
1. Pam the Programmer wants to repetitively run a few lines of code as long as some condition remains true. In addition, she wants to ensure that these lines of code are never run unless that condition holds true. What kind of statement should she use?
a. an assignment statement
b. an if statement
c. None of the choices listed are correct
d. a while loop
2. Commenting your C++ code is very important because
Select one:
a. very often, a programming project involves many individuals who will want to understand how your code works, even though you were its sole author
b. many years from now, it might need to be maintained by someone else who will not know what you meant your code to do
c. a few days after you first write it, you might need to make changes and will have lost your train of thought unless you explicitly state what you are trying to do
d. All of the choices listed are correct
3. In the computation: a = b * c + f / g;
C++ will calculate the answer by performing
Select one:
a. the multiplication and division first, followed by the addition and subtraction
b. the subtraction and addition first, followed by the multiplication and division
c. the division and subtraction first, followed by the multiplication and addition
d. the addition and division first, followed by the multiplication and subtraction
4. When using a return statement, the parenthesis around the value being returned to the calling program are
Select one:
a. required only in certain circumstances
b. never allowed
c. optional
d. required
5. Consider the expression: &&( false !( true || false )
Select one:
a. Due to syntax errors, this expression cannot be compiled successfully
b. Due to run-time errors, this expression cannot be evaluated
c. At run-time, this expression evaluates to the value false
d. At run-time, this expression evaluates to the value true
6. Each statement in C++ ends with a
Select one:
a. semicolon (that is a ;) and only one statement can be present on a single textual line of code
b. semicolon (that is a ;) and more than one statement can be present on a single textual line of code
c. pound sign (that is a #) and more than one statement can be present on a single textual line of code
d. new line and only one statement can be present on a single textual line of code
7. Which statement does a program use to change the value of a variable at run-time?
Select one:
a. An assignment statement
b. A #include statement
c. A while statement
d. An if statement
Explanation / Answer
Answers
T OR F
1. In C++, the body of a do-while loop is always guaranteed to run atleast once. [True]
Explanation: do while loop is post test conditional. So that first it enters to loop, later it checks the condition.
2. One difference between a declared variable and a declared constant is that a variable’s value can vary at run-time, but a declared constant’s value cannot be changed after it is initialized. [True]
Explanation: Variable value changes at any time. But named constant is fixed, value cannot be changed
3. A function may accept either pass-by-reference or pass-by-value parameters, but not both in the same function.[False]
Explanation:
C++ provides function overloading that same function can be defined by pass-by-reference and pass-by-value. Based on the calling parameter function is passed that associated function is called.
4. In C++, when int variables are left uninitialized, their initial value will not equal zero. [True]
Answer:
When value is not initialized to variable of integer, then default it takes garbage/unknown value, which is not equal to 0
5. When working with floating-point numerical values, programmers must use care because floating-point numerical representations are always inexact. [True]
Answer:
Floating-point values are real type data, which has number in fractions. So during comparisons programmer must careful
6. When working with an if statement, an else clause is optional. [True]
Answer:
If can be written without else part. This kind of condition is one-way condition
7. The logical expression: ( x <= y ) executes the same as the logical expression: ( x < y && x ==y ) [False]
Answer:
The condition <= is (< 'or' =) but second logical operation is having 'and'.
8. When evaluating a complex expression that lack parenthesis such as
x = a + b - c * d / e + f;
C++ will always calculate the answer moving from left to right computing the answer as if the user entered [True]
x = (((((a + b) - c) * d) / e) + f);
Answer:
Using precedence operators '( )' evaluation is left-to-right only.
MC
1. Pam the Programmer wants to repetitively run a few lines of code as long as some condition remains true. In addition, she wants to ensure that these lines of code are never run unless that condition holds true. What kind of statement should she use?
a. an assignment statement
b. an if statement
c. None of the choices listed are correct
d. a while loop
Answer: b – if statement
2. Commenting your C++ code is very important because
Select one:
a. very often, a programming project involves many individuals who will want to understand how your code works, even though you were its sole author
b. many years from now, it might need to be maintained by someone else who will not know what you meant your code to do
c. a few days after you first write it, you might need to make changes and will have lost your train of thought unless you explicitly state what you are trying to do
d. All of the choices listed are correct
Answer: d – All of them correct
3. In the computation: a = b * c + f / g;
C++ will calculate the answer by performing
Select one:
a. the multiplication and division first, followed by the addition and subtraction
b. the subtraction and addition first, followed by the multiplication and division
c. the division and subtraction first, followed by the multiplication and addition
d. the addition and division first, followed by the multiplication and subtraction
Answer:(a)
4. When using a return statement, the parenthesis around the value being returned to the calling program are
Select one:
a. required only in certain circumstances
b. never allowed
c. optional
d. required
Answer: a
5. Consider the expression: &&( false !( true || false )
Select one:
a. Due to syntax errors, this expression cannot be compiled successfully
b. Due to run-time errors, this expression cannot be evaluated
c. At run-time, this expression evaluates to the value false
d. At run-time, this expression evaluates to the value true
Answer: a
6. Each statement in C++ ends with a
Select one: Answer : b
a. semicolon (that is a ;) and only one statement can be present on a single textual line of code
b. semicolon (that is a ;) and more than one statement can be present on a single textual line of code
c. pound sign (that is a #) and more than one statement can be present on a single textual line of code
d. new line and only one statement can be present on a single textual line of code
7. Which statement does a program use to change the value of a variable at run-time?
Select one: Answer : a
a. An assignment statement
b. A #include statement
c. A while statement
d. An if statement
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.