Description
The following questions are true/false and multiple choice. PLEASE HELP!
1. Every C++ program must have:
A. cout statement B. function main
C. #include statement D. All of the above
2. The following data : 72 'A' "Hellow" 2.87
are examples of
A. variables B. literals
C. strings D. None of the above
3. int x;
int y = 4;
long z = 7;
Which statement forces the compiler to perform automatic
promotion?
A. z = z + y B. x = y + (int)z;
C. x = (int)z; D. None of the above
4. What is the error ?
int schedule( char activity )
{
int i, activity;
float time;
// code
}
A. This is a function call and not a function definition.
B. No error.
C. Variable activity cannot be re-declared.
D. Missing semicolon.
5. What is printed by the following program segment ?
int x;
x = 4 * (2 + 5)/9 + 3;
cout << "The result is " << x;
A. The result is 3. B. The result is 6.
C. The result is 5. D. The result is 4.
6. cout << 'A';
What is the displayed result of the above statement?
A. 'A' B. A compiler error C. 65 D. A E. 1
7. int x;
int y;
const int z = 0;
Which statement will cause a compile error?
A. x = y = z; B. x = z = y; C. x = y = 'A'; D. x = y = 10000;
8. int x = 4;
int y;
y = x++ + 1;
What is the value of variable y after the above statement executes?
A. 4 B. 5 C. 6 D. 7 E. None of the above
9. int x = 4;
int y;
y = --x + 1;
What is the value of variable y after the above statement executes?
A. 4 B. 5 C. 6 D. 7 E. None of the above
10. int x = 4;
int y;
y = ++(x + 1);
What is the result of an attempt to compile and run the
above statements?
A. 4 B. 5 C. 6 D. 7 E. A compile error
11. int x = 11;
double y;
y = (double)x / 3;
What is the value of variable y after the above statement executes?
A. 3 B. 3.66667 C. 4 D. None of the above
12. int x = 11;
int y;
y = x % 3;
What is the value of variable y after the above statement executes?
A. 3 B.2.2 C. 2 D. 3.33 E. None of the above
13. int x;
main()
{
int y;
}
What is true regarding the scope of x and y ?
A. x is local; y is global B. x and y are both local
C. x and y are both static D. x is global; y is local
14. Assuming x starts with the value 10, what will the following
code fragment print out ?
cout << x-- << ' ';
cout << ++x;
A. 9 10 B. 10 10 C. 10 9 D. none of the above
15. 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
16. Overloaded functions
A. are a group of functions with the same name and same
number of arguments.
B. are a group of functions with the same name and
different parameter types.
C. make life easier for the programmer.
D. none of the above.
17. The following statements, using manipulators fixedpoint and showpoint:
double half = 20.0;
cout << fixedpoint << showpoint << half << endl;
is syntactically correct.
T__ F__
18. 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__
19. x != y is the same as (x >y || x<y)
T__ F__
20. y < x is the same as x >= y
T__ F__
21. The following statement wants to determine if count is outside the
range of 0 through 100:
if (count < 0 && count > 100)
T__ F__
22. It is correct to write x%y if either x or y is float.
T__ F__
23. One limitation of the for loop is that only one variable may be
initialized in the initialization expression.
T__ F__
24. How many times is a "do while" loop executed ?
A. once B. always skipped C. forever
D. at least once E. none of the above
25. 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
26. In C++ you must declare all variables only at the beginning
of the function.
T__ F__
27. In C++ cin and cout are built into C++ language as keywords.
T__ F__
28. The following lines of code
int i = 10;
cout << setw(6) << i << i << endl;
display: 1010
T__ F__
29. The following lines of code
double d = 7.0;
cout << d << endl;
display: 7.0
T__ F__
30. The following function prototypes
int increment(char);
int increment(int);
are not accepted in C++ because they have the same name.
T__ F__
31. Parameter names in a prototype are optional.
T__ F__
32. The following is a function prototype:
CalcTotal();
T__ F__
33. If a C++ program has two component functions, main() and
mistery(), it is possible that mistery() calls main().
T__ F__
34. The parameter must have the same name with the argument.
T__ F__
35. Parameters are declared and initialized on the function header.
T__ F__
36. The following declaration is accepted by the compiler:
int return;
T__ F__
37. The following declaration is not accepted by the compiler:
int weight = 4,000;
T__ F__
38. Changes to a function parameter always affect the original
argument as well.
T___ F__
39. The following function prototypes are accepted by compiler:
int GetValue();
double GetValue();
T___ F__
40. The following implementation is correct:
double average (int value1, int value2, int value3)
{
double average;
average = value1 + value2 + value3 / 3;
}
T___ F__
41. This program will not compile:
int main()
{
float This_One = 2;
float That_One;
That_one = 2 * This_one;
}
T__ F__
42. This program will not compile:
main()
{
double constant_1 = 2; /* Program constant
double variable_1; /* Program variable.
variable_1 = constant_1 + constant_1;
}
T__ F__
43. There is no logical error inside this code segment:
if ( gender == 1 )
cout << "Woman" << endl;
else;
cout << "Man" << endl;
T__ F__
44. There is no logical error inside this code segment:
while ( z >= 0 )
sum += z;
T__ F__
45. There is an error inside this code segment:
int x = 1, total;
while ( x <= 10 )
{
total += x;
++x;
}
T__ F__
46. The following program is syntactically correct
#include iostream
using namespace std;
int main ()
{
int a, b, c
a = 3; b = 4; c = a + b;
cout << "The value of c is " << c;
return 0;
}
T__ F__
47. The following program is syntactically incorrect:
#include <iostream>
using namespace std;
int main ()
{
int a, b, c
a = 3; b = 4; c = a + b;
cout << "The value of c is " < c;
return 0;
}
T__ F__
48. The following program is syntactically correct:
for ( int x = 1; x <= 20; ++x )
{
if ( x % 5 == 0 )
cout << x << endl;
else
cout << x << '\t';
}
T__ F__
49. The following program is logically correct:
switch ( n )
{
case 1:
cout << "The number is 1" << endl;
case 2:
cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}
T__ F__
50. The following code prints the values 1 to 10.
n = 1;
while ( n < 10 )
cout << n++ << endl;
T___ F__
51. The following code is correct:
for ( x = 100, x >= 1, ++x )
cout << x << endl;
T___ F__
52. The following program is syntactically correct:
int sum( int x, int y )
{
int result;
result = x + y;
}
T___ F__
53. The following program is syntactically correct:
void product()
{
int a; int b; int c; int result;
cout << "Enter three integers: ";
cin >> a >> b >> c;
result = a * b * c;
cout << "Result is " << result;
return result;
}
T___ F__
54. The following program has no error:
using namespace std;
int main ()
{
double number1, number2, sum;
cout << "Enter a number: ";
cin >> number1;
cout << "Enter another number: ";
cin >> number2;
sum = number1 + number2;
cout << "The sum of the two numbers is " << sum;
return 0;
}
T___ F__
55. The following program has no error:
#include <iostream>
using namespace std;
int main ()
{
double number1, number2, sum;
cout << "Enter a number: ";
cin << number1;
cout << "Enter another number: ";
cin >> number2;
sum = number1 + number2;
cout << "The sum of the two numbers is " << sum;
return 0;
}
T___ F__
56. The following program is syntactically correct:
#include <iostream>
using namespace std;
int main ()
{
double number1, number2, sum;
cout << "Enter a number: ";
cin >> number1;
cout << "Enter another number: ";
cin >> number2;
number1 + number2 = sum;
cout << "The sum of the two numbers is " << sum;
return 0;
}
T___ F__
57. The following program is syntactically correct:
#include <iostream>
using namespace std;
int main ()
{
double number1, number2, sum;
cout << "Enter a number: ";
cin >> number1;
cout << "Enter another number: ";
cin >> number2;
sum = number1 + number2;
cout "The sum of the two numbers is " << sum;
}
T___ F__
58. The following program is syntactically correct:
#include <iostream>
using namespace std;
void main ()
{
const number1, number2, product;
cout << "Enter two numbers and I will multiply\n";
cout << "them for you.\n";
cin >> number1 >> number2;
product = number1 * number2;
cout << product;
}
T___ F__
59. There is something compiler does not like in this code:
#include <iostream>;
using namespace std;
void main ()
{
int number1, number2, product;
cout << "Enter two numbers and I will multiply\n";
cout << "them for you.\n";
cin >> number1 >> number2;
product = number1 * number2;
cout << product;
}
T__ F__
60. The following program is syntactically correct:
#include <iostream>
using namespace std;
void main ()
{
int number1, number2, product;
cout << "Enter two numbers and I will multiply\n";
cout << "them for you.\n";
cin >> number1 >> number2;
product = number1 * number2;
cout << product;
return 0;
}
T__ F__
61. The following program is syntactically correct:
#include <iostream>
using namespace std;
int main ()
{
int number1, product;
cout << "Enter two numbers and I will multiply\n";
cout << "them for you.\n";
cin >> number1 >> number2;
product = number1 * number2;
cout << product;
return 0;
}
T__ F__
62. The following program is correct:
#include <iostream>
using namespace std;
int main()
{
int numCount, total;
double average;
cout << "How many numbers do you want to average ? ";
cin >> numCount;
for (int count = 0; count < numCount; count++)
{
int num;
cout << "Enter a number: ";
cin >> num;
total += num;
count++;
}
average = total / numCount;
cout << "The average is << average << endl;
return 0;
}
T__ F__
63. The following program is logically correct:
#include <iostream>
using namespace std;
int main()
{
int count=1, total=0;
while (count <= 100)
total += count;
cout << "The sum of the numbers 1-100 is ";
cout << total << endl;
return 0;
}
T__ F__
64. What value does this program display?
void inc( int x );
void main()
{
int x = 1;
inc( x );
cout << x;
}
void inc( int x )
{
x++;
}
A. -1 B. 0 C. 1 D. 2
65. Class-objects contain only data.
T__ F__
66. The purpose of information hiding is to keep the data
members public.
T__ F__
67. Class members may be all private.
T__ F__
68. private keyword must be always used to declare private members.
T__ F__
69. A member function is called to act on a specific object.
T__ F__
70. If three objects of a class are defined, how many copies
of that class data are stored in memory ?
And how many copies of its member functions ?
A. 3 3 B. 1 1 C. 1 3 D. 3 1
71. Data or functions designated private are accessible
A. to any function in the program.
B. to private member-functions of that class only
C. only if you know the password
D. to all member-functions of that class
72. A constructor has a header syntactically implemented like for
any other function in C++.
T__ F__
73. There is always at least one constructor part of the class.
T__ F__
74. Like any C++ function, a constructor may be overloaded.
T__ F__
75. A constructor can call other member functions of the class.
T__ F__
76. Attempting to initialize a non-static data member of a class
explicitly in the class definition is a syntax error.
T__ F__
77. Class members specified as private are accessible only to
member functions of the class and friends of the class.
T__ F__
78. You cannot use the scope-resolution-operator :: in main().
T__ F__
79. Defining as const a member function that modifies a data member
of an object is a compilation error.
T__ F__
80. The prototypes for friend functions must appear in the class
definition.
T__ F__
81. You can declare as const all of a class's member functions.
T__ F__
82. You can declare an object as const.
T__ F__
83. The following class implementation is syntactically correct:
class Time
{
public:
// function prototypes
private:
int hour = 0;
int minute = 0;
int second = 0;
};
T__ F__
84. The following class definition is syntactically correct:
class Circle:
{
private
double centerX;
double centerY;
double radius;
public
SetCenter(double,double);
SetRadius(double);
}
T__ F__
85. Objects may be passed as function arguments.
T__ F__
