Documente Academic
Documente Profesional
Documente Cultură
What value will x contain when the sample code above is executed?
Choice 1
1
Choice 2
2[Ans]
Choice 3
3
Choice 4
4
Choice 5
5
------------------------------------
After the sample code above has been executed, what value will the variable x
contain?
Choice 1
4
Choice 2
5
Choice 3
6 [Ans]
Choice 4
7
Choice 5
8
------------------------------------
Referring to the sample code above, what value will the variable counter have when
completed?
Choice 1
0
Choice 2
1
Choice 3
2[Ans]
Choice 4
3
Choice 5
4
int main()
{
for( i = 0; i < 10; increment( i ) )
{
}
Cout<<"i="<<i<<endl;
return 0;
}
What will happen when the program above is compiled and executed?
Choice 1
It will not compile.
Choice 2
It will print out: i=9.
Choice 3
It will print out: i=10.
Choice 4
It will print out: i=11.
Choice 5
It will loop indefinitely.[Ans]
------------------------------------
------------------------------------
With what do you replace the ???? to make the function shown above return the
correct answer?
Choice 1
if (x == 0) return 0;
Choice 2
return 1;
Choice 3
if (x >= 2) return 2;
Choice 4
if (x == 0) return 1;
Choice 5
if (x <= 1) return 1; [Ans]{more probable}
------------------------------------
int main()
{
func();
func();
return 0;
}
------------------------------------
/*question number 41*/
1. syntax error
2. semantic error
3. logic error
4. compile-time error
5. no errors [Ans]
------------------------------------
/*question number 42*/
Which of the following is NOT a valid identifier (i.e. CANNOT be used as a name for
a variable).
1. phone_number
2. EXTRACREDIT
3. DOUBLE
4. my course [Ans]
5. All are invalid
------------------------------------
/*question number 43*/
1. double a = 3.5 + 4;
2. cout << b + c;
3. x + y = total; [Ans]
4. double Main;
5. All of the above.
------------------------------------
/*question number 44*/
Assuming that the user types 14.92 followed by a return, what is the output of the
following code:
int num;
cout << "Enter a number: ";
cin >> num;
cout << num;
1. 0
2. 14 [Ans]
3. 14.92
4. 15
5. None of the above
------------------------------------
/*question number 46*/
int a = 53;
int b = 6;
cout << a / b;
1. 8.833
2. 9
3. 8 [Ans]
4. 5
5. None of the above
------------------------------------
/*question number 47*/
1 1-a
--- + --------
c 1+b
1. 1/c+1-a/1+b
2. 1 / c + (1 - a / 1 + b)
3. (1 / c) + (1 - a / 1 + b)
4. 1 / c + (1 - a) / (1 + b) [Ans]
5. None of the above
------------------------------------
/*question number 48*/
1. 7.0
2. 0
3. 1.0
4. 10.5
5. invalid expression [Ans]
- -----------------------------------
/*question number 49*/
int a = 28;
int b = 19;
int c = 3;
int d = 2;
cout << a % b % c / d;
1. 1.5
2. 1
3. 0.25
4. 0 [Ans]
5. None of the above
------------------------------------
/*question number 50*/
What is the output of the following code?
int a = 9;
int b = 6;
double c = 2.2;
cout << 4.4 + c * (a / b);
1. 7.7
2. 6.6 [Ans]
3. 9.9
4. 11
5. None of the above
------------------------------------
/*question number 51*/
1. 1
2. 9
3. 10 [Ans]
4. 8
5. None of the above
------------------------------------
/*question number 52*/
Given that str = "Snoozing under a tree", what would be the result of the following
statement
1. Sun
2. nun
3. nnd
4. S u [Ans]
5. None of the above
------------------------------------
/*question number 53*/
What does the following output produce? (Note: a dash is representing a space.)
double x = 1.0;
double y = 777.777;
cout << fixed << setprecision(2) << setw(8);
cout << x << "\n";
cout << y << "\n";
1. ----1.00
777.78
2. -------1
777.78
3. ----1.00
--777.78
4. ----1.00
777.777
5. None of the above [Ans]
------------------------------------
/*question number 54*/
Given the format of the if-else structure below, one and only one of the statement
sets inside of the bodies of the if and else will be executed.
if (------)
{
stmt set 1;
}
else
{
stmt set 2;
}
(T/F) (T)
------------------------------------
/*question number 55*/
Given the following code, and that the user entered the string "Goodbye", what
will be the output?
Hello [Ans]
Goodbye
------------------------------------
/*question number 56*/
int x = 1;
int y = 2;
if (x < y)
{
cout << x;
}
cout << y;
1. 1
2. 2
3. x
4. y
5. 12 [Ans]
------------------------------------
/*question number 57*/
int x = 0;
int y = 3;
if (x < 1)
{
cout << "stmt 1 ";
x = y;
}
if (x > 1)
{
cout << "stmt 2 ";
}
else
{
cout << "stmt 3 ";
}
1. stmt 1
2. stmt 2
3. stmt 1 stmt 2 [Ans]
4. stmt 1 stmt 2 stmt 3
5. stmt 1 stmt 3
------------------------------------
/*question number 58*/
double func2(double a)
{
double b = pow(a, a);
cout << b << endl;
// OUTPUT 1
double c = func1(b);
cout << c << endl;
// OUTPUT 2
return b + c;
}
int main()
{
cout << func2(3) + 5 << endl; //
OUTPUT 3
return 0;
}
1. 3
2. 9
3. 27 [Ans]
4. 32
5. None of the above
1. 3
2. 20
3. 27
4. 100 [Ans]
1. 8
2. 41
3. 127
4. 132 [Ans]
5. None of the above