31. The following code segment is syntactically correct:
int number{20};
cout << number << setbase(16) << " " << number
<< setbase(10) << " " << number
<< showpos << " " << number << endl;
T__ F__
32. The following statement wants to determine if ‘count’ is outside the
range of 0 through 100:
if (count < 0 && count > 100)
T__ F__
33. There is a logical error inside this code segment:
if ( gender == 1 )
cout << "Woman" << endl;
else;
cout << "Man" << endl;
T__ F__
34. The following two implementations perform the same operation:
q = x < y ? a+b : x*2;
if( x < y )
q = a + b;
else
q = x*2;
T__ F__
35. What is the value of ‘w’ after this code fragment is executed ?
int x{2}, y{5}, w;
w = x * (x > y ? 1 : 2);
A. 2 B. 4 C. 10 D. none of the above
36. The following code segment prints the values 1 to 10.
int n{1};
while ( n < 10 ) cout << n++ << endl;
T__ F__
37. There is a logical error inside this code segment:
while ( z >= 0 ) sum += z;
T__ F__
38. The following code-segment of ‘main()’ is syntactically correct:
int x{100000};
while( x-- );
T__ F__
39. The following program is logically incorrect:
#include <iostream>
using namespace std;
int main()
{
int count=1, total=0; // loop variable initialized
while (count <= 100)
total += count;
cout << "The sum of the numbers 1-100 is ";
cout << total << endl;
return 0;
}
T__ F__
40. There is an error inside this code segment:
int x{1}, total;
while ( x <= 10 )
{
total += x;
++x;
}
T__ F__
31.
int number{20};
cout << number << setbase(16) << " " << number
<< setbase(10) << " " << number
<< showpos << " " << number << endl;
T
32.
range of 0 through 100:
if (count < 0 && count > 100)
F
Correct declaration
if (count < 0 || count > 100) // Need to use OR(||) because the statement is true any of the statement is true.
33.
if ( gender == 1 )
cout << "Woman" << endl;
else;
cout << "Man" << endl;
F
else; // Else does not end with semicolon
34.
q = x < y ? a+b : x*2;
if( x < y )
q = a + b;
else
q = x*2;
T
35.
int x{2}, y{5}, w;
w = x * (x > y ? 1 : 2);
w = 2 * (2 > 5 ? 1 : 2);
Here 2>5 false so the value is 2
w = 2 * (2);
w = 4
Option B
According to HomeworkLib guidelines i have to solve first four bits only but i solve first. Please do next post for remaining answers.
31. The following code segment is syntactically correct: int number{20}; cout << number <<...
81. The following function call doesn’t agree with its prototype: cout << BoxVolume( 10, 5 ); int BoxVolume(int length = {1}, int width = {1}, int height = {1}); T__ F__ 82. The following function is implemented to swap in memory the argument-values passed to it: void swap(int a, int b) { int temp; temp = a; a = b; b = temp; ...
41. Executing the "continue" statement from within a loop causes control to go A. to the next line of code B. out of the loop C. to the beginning of the loop D. to check the loop condition for repeating the loop E. none of the above 42. The 'default' statement inside a 'switch()' is optional. T__ F__ 43. The following 'switch' implementation is legal: int i = 2; ...
61. The following program is accepted by the compiler: int sum( int x, int y ) { int result; result = x + y; } T__ F__ 62. The following implementation is accepted by the compiler: void product() { int a; int b; int c; int result; cout << "Enter three integers: "; cin >> a >> b >> c; result = a * b * c; ...
12. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; *p = 35; *q = 98; *p = *q; cout << x << " " << y << endl; cout << *p << " " << *q << endl; 13. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; x = 35; y = 46; p...
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;
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
what is the output of the following code segment? C++ g. int arr[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) arr[i][j] =i*4 + j; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) cout << arr[i][j] << " "; h. int next(int & x) { x= x + 1; return (x + 1); int main() { int y = 10;...
howthe output of the following 4 program segments (a) const int SIZE=8; int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8}; int index; index=0; res = values[index]; for (int j=1; j<SIZE; j++) { if (values[j] > res) { res = values[j]; index = j; cout << index << res << endl; } } cout <<...
What is the output of the following program segment? int count = 5; while(--count > 0) cout << count << " "; cout << endl;
20) What is the output of the following segment of C code: int avg(int n, int* a); int main () { int array[4]={1,0,6,9}; printf("%d", avg(4, array)+ 1); system("pause"); return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...