2. What is the output of the following code fragment?
n = 1;
while (n <= 5)
{
n++;
cout << n << ' ';
a.1 2 3 4 5
b. 1 2 3 4
c. 1 1 1 forever
d. 2 3 4 5
e. 2 3 4 5 6
3. What is the termination condition for the following While loop?
while (beta
> 0 && beta < 10)
{
cout << beta << endl;
cin >> beta;
}
a. beta > 0 && beta < 10
b. beta >= 0 && beta <= 10
c. beta < 0 || beta > 10
d. beta <= 0 || beta >= 10
4. Loop ____________________ is the moment that the flow of control reaches the first statement inside the loop body.
5. True or False? In testing a loop, one tries to devise data sets that leave the files in improper states that violate either the loop postcondition (an assertion that must be true immediately after the loop exit) or the postcondition of the module containing the loop.
6. These three common programming tasks _________________ __________________ _____________________ are often performed in a loop.
7. Given the input data
25 10 6 -1
what is the output of the following code fragment? (All variables are of type int.)
sum =
0;
cin >> number;
while (number != -1)
{
cin >> number;
sum = sum + number;
}
cout << sum << endl;
a. 15
b. 41
c. 40
d. 16
e. no output--this is an infinite loop
8. A(n) ____________________ is a counter variable that is incremented each time a particular event occurs.
10. A(n) ____________________-controlled loop is an event-controlled loop whose event is the attempt to read past the end of an input file.
Answer 2: 1 2 3 4 5
as n is starting from 1 to <=5
Answer 3:D
if beta crosses 10 or comes down below 0 than it will terminate
Answer 4:
initiliazation
Answer 5:True
Answer 6: matrix operations,searching and sorting
Answer 7: 40
as it adds 25+10+6
also it adds -1 later loop break
Answer 8:iteration counter
Answer 10:event
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
2. What is the output of the following code fragment? n = 1; while (n <=...
A. What is the output of the following C++ code fragment? (all variables are of type int) int count-1; int y-100; while (count 3) y=y-1 ; count+t cout << y << endl; cout<< count <<endl What is the value of x after control leaves the following while loop? (all variables are of type int) B. int x0 while (x < 20) sum- sum+x cout << sum<< endl;
Class: C++ Final Exam Dates Multiple Choice Identify the choice thar best completes the statement or answer the question N 1. In s tructures, the computer repeats particular statements a certain number of times depending on some condition(s) a. looping C. selection b. branching d. sequence 2. What is the output of the following CH code? count = 1; num - 25; while (count < 25) numnum - 1: count++; cout << count << " " << num << endl;...
What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) 1. for (int j = 25; j > 16; j -= 3) cout << setw(5) << j; Answer: 2. int sum = 0; for (int k = -2; k <= 2; k++) sum = sum +...
Suppose that the input is 0 5 6 4 9 8 -1.What is the output of the following code? int num = 0; int sum; cin >> sum; while (num != -1) { cin >> num; sum = sum + 2 * static_cast<int>(sqrt(num)); } cout << "Sum = " << sum << endl;
What does the following nested loop structure output? count = 1; while (count <= 11) {innerCount = 1 while (innerCount <= (12 - count)/2) {cout << " "; innerCount++;} innerCount = 1; while (innerCount = 1; while (innerCount <= count) {cout << "0"; innerCount++;} cout << endl; count++;} What does the following nested loop structure output? count = 1; while (count <= 10) {innerCount = 1; while (innerCount <= 10) {cout << setw(5) << count * innerCount; innerCount++;} cout <<...
3) What are the final values of a, b, c in the following code fragment (1.5 point): int a = 6 , b = 127 , c; c = ( ++a ) + ( b -- ); Answer: 4) What are the final values of a, b, c in the following code fragment (1.5 point): int a = 6 , b = 127 , c; c = (a++) + ( -- b); Answer: 5) What is displayed by this poorly...
C++ Program What is the output of the following code fragment?(beta is of type int.) beta = 5; do { switch (beta) { case 1: cout <<'R'; break; case 2: cout case 4: cout << 'O'; break; case 5: cout << 'L'; } beta--; }while (beta>1); cout <<'X';
18 C++ 1. What is the output of the following program segment? int y-22: while ((y 3) != 0) cout << y<< "": y=y-2; The output is 2. Suppose that the input is 100, 20,-8, 50, 20. What is the output of the following C++ code? int sum0 int num: int j cin >> num: if (num < 0) continue зит зит + num; cout<< sum << endl; The output is
How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0, b = 1, c; if (n <= 1) return n; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } int fibonacciRecursive(int n) { if (n <= 1) { return n; } return fibonacciRecursive(n-1) + fibonacciRecursive(n-2); } int main() { int n;...
12) 8 pts. Find the errors in the following code fragment and correct them. #i nclude <iostream> using namespace std; double fudge (double s) f return s 2.3; int mainO cout >> "Your original estimate" double estimate; cin >> estimate; cout << endl; for (int 1 = 0;1c3;i++); cout << "EStimate' < fudge(estimate) <<endl Hint: There are 4 syntax errors. There is one error that is syntactically correct but causes the output to not be what you would expect. Once...