Preparation for Final Exam MCQ Quiz BIG - Попытка 1
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10
Question91
Баллов: 1
What should you do to free the memory after running this code?
char *a; a = new char[20];
Выберите один ответ.
a. I don't know | ||
b. delete a; | ||
c. delete [] a; | ||
d. delete a[]; | ||
e. no of these |
Question92
Баллов: 1
All variables must be given a type when they are declared.
Ответ:
True False
Question93
Баллов: 1
Write one or more statements that perform the following task for and array called “fractions”. Print all the array elements using a for statement. Define the integer variable i as a control variable for the loop.
Выберите один ответ.
a. for ( i = 0; < arraySize; i++ ) cout << "fractions[" < i << "] = " << fractions[ i ] << endl; | ||
b. for ( int i = 0; < arraySize; i++ ) cout << "fractions[" < arraySize << "] = " << fractions[arraySize ] << endl; | ||
c. no ideas | ||
d. for ( int i = 0; < arraySize; i++ ) cout << "fractions[" < i << "] = " << fractions[ i ] << endl; |
Question94
Баллов: 1
Storage-class specifier is a recommendation to the compiler to store a variable in one of the computer's registers.
Question95
Баллов: 1
In C++, it is possible to have various functions with the same name that operate on different types or numbers of arguments. This is called function ________.
Выберите один ответ.
a. prototype | ||
b. copy | ||
c. duplicate | ||
d. overloading | ||
e. not sure |
Question96
Баллов: 1
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
char str[] = "de_dust";
for (int i=strlen(str)-1; i>=0; i--)
cout << str[i];
cout << endl;
return 0;
}
Выберите один ответ.
a. sud_e | ||
b. sud_ed | ||
c. de_dust | ||
d. tsud_ed | ||
e. tsud_e |
Question97
Баллов: 1
Which of the following accesses a variable in structure b?
Выберите один ответ.
a. b-var; | ||
b. b->var; | ||
c. b>var; | ||
d. b.var; | ||
e. b>>var |
Question98
Баллов: 1
If n=3, what will be the result of:
switch
{
case '3':
cout << "wow \n";
break;
case 3:
cout << "bab \n";
break;
default:
cout << "heh \n";
break;
}
Выберите один ответ.
a. Compiler error | ||
b. heh | ||
c. wow | ||
d. Undefined behaviour | ||
e. bab |
Question99
Баллов: 1
Assuming that nPtr points to the beginning of array numbers (the starting address of the array is at location 1002500 in memory), what address is referenced by nPtr + 8?
Выберите один ответ.
a. The same as nPtr | ||
b. NULL | ||
c. The address is 1002500 + 8 * 8 = 1002564 |
Question100
Баллов: 1
Find the error(s) in the following code segment:
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;
}
Выберите один ответ.
a. switch ( n ) { case 1: cout << "The number is 1" << endl; break; case 2: cout << "The number is 2" << endl; break; } | ||
b. switch ( n ) { case 1: cout << "The number is 1" << endl; break; case 2: cout << "The number is 2" << endl; break; default: cout << "The number is not 1 or 2" << endl; break; } | ||
c. switch ( n ) { case 1: cout << "The number is 1" << endl; case 2: cout << "The number is 2" << endl; default: cout << "The number is not 1 or 2" << endl; } |
Midterm II
Review of attempt 1
Close this window
Started on | Tuesday, 7 December 2010, 05:37 PM |
Completed on | Tuesday, 7 December 2010, 06:27 PM |
Time taken | 50 mins |
Marks | 29/40 |
Grade | 72.5 out of a maximum of 100 (73%) |
Question 1
Marks: 1
Use a stream manipulator such that, when integer values are output, the integer base for octal and hexadecimal values is displayed.
Choose one answer.
a. cout << &showbase; | ||
b. cout << showbase; | ||
c. cout << Hshowbase; |
Incorrect
Marks for this submission: 0/1.
Question 2
Marks: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int n = 1;
while (n<5)
cout << ++n;
return 0;
}
Choose one answer.
a. 234 | ||
b. 12345 | ||
c. 1234 | ||
d. 123456 | ||
e. 2345 |
Incorrect
Marks for this submission: 0/1.
Question 3
Marks: 1
Each parameter in a function header should specify both a and a .
Correct
Marks for this submission: 1/1.
Question 4
Marks: 1
What value gets printed by the program?
#include <iostream>
int foo(int x, int y) { return x+y;}
double foo(double x, double y) { return x+y; }
int main(int argc, char** argv)
{
double (*ptr)(int, int);
ptr = foo;
std::cout << ptr(3,8) << std::endl;
return 0;
}
Choose one answer.
a. 11 | ||
b. 8 | ||
c. ill-formed | ||
d. 3 |
Correct
Marks for this submission: 1/1.
Question 5
Marks: 1
If ASCII code of 'd' is 100, what is the ASCII code of 'a'?
Choose one answer.
a. 103 | ||
b. 65 | ||
c. 68 | ||
d. 97 | ||
e. 96 |
Correct
Marks for this submission: 1/1.
Question 6
Marks: 1
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
int *x = newint[10];
for (int i=0; i<10; i++)
x[i] = i+5;
int *y = x;
y++;
cout << *(y+1)/2 << endl;
return 0;
}
Choose one answer.
a. 2 | ||
b. 3 | ||
c. 3.5 | ||
d. 7 | ||
e. 4 |
Correct
Marks for this submission: 1/1.
Question 7
Marks: 1
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
char *a = "matador";
cout << "hello " << a[0] << a[5] << a[2] << a[5];
return 0;
}
Choose one answer.
a. hello | ||
b. hello matadorortadoror | ||
c. moto hello | ||
d. hello matador | ||
e. hello moto |
Correct
Marks for this submission: 1/1.
Question 8
Marks: 1
What value gets printed by the program?
#include <iostream>
int foo(int x, int y)
{
return x+y;
}
int foo(const int x, const int y)
{
return x+y+1;
}
int main(int argc, char** argv)
{
const int x = 3;
const int y = 2;
std::cout << foo(x,y) << std::endl;
return 0;
}
Choose one answer.
a. 6 | ||
b. 3 | ||
c. ill-formed | ||
d. 5 | ||
e. undefined |
Correct
Marks for this submission: 1/1.
Question 9
Marks: 1
Write a C++ statement or a set of C++ statements to print the value 333.546372 in a field width of 15 characters with precisions of 1, 2 and 3. Print each number on the same line. Left-justify each number in its field.
Choose one answer.
a. cout << fixed << left << setprecision( 1 ) << 333.546372; << setprecision( 2 ) << 333.546372; << setprecision( 3 ) << 333.546372; << endl; | ||
b. cout << fixed << left << setprecision( 1 ) << setw( 15 ) << 333.546372 << setprecision( 2 ) << setw( 15 ) << 333.546372 << setprecision( 3 ) << setw( 15 ) << 333.546372 << endl; | ||
c. cout << fixed << left << setw( 15 ) << 333.546372 << setw( 15 ) << 333.546372 << setw( 15 ) << 333.546372 << endl; | ||
d. cin << fixed << left << setprecision( 1 ) << setw( 15 ) << 333.546372 << setprecision( 2 ) << setw( 15 ) << 333.546372 << setprecision( 3 ) << setw( 15 ) << 333.546372 << endl; |
Correct
Marks for this submission: 1/1.
Question 10
Marks: 1
Which follows the case statement?
Choose one answer.
a. :: | ||
b. - | ||
c. A newline | ||
d. ; | ||
e. : |
Incorrect
Marks for this submission: 0/1.
Question 11
Marks: 1
The of an identifier is the portion of the program in which the identifier can be used.
Correct
Marks for this submission: 1/1.
Question 12
Marks: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// assign array element 2 (the value 3) to number
number = *zPtr[ 2 ];
Choose one answer.
a. number = &zPtr[ 2 ]; | ||
b. number = zPtr[ 2 ]; | ||
c. number = *zPtr( 2 ); |
Correct
Marks for this submission: 1/1.
Question 13
Marks: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
++zPtr;
Choose one answer.
a. zPtr = z; ++zPtr; | ||
b. no errors | ||
c. zPtr++; |
Correct
Marks for this submission: 1/1.
Question 14
Marks: 1
A pointer that is declared to be of type void * can be dereferenced
Answer:
True False
Correct
Marks for this submission: 1/1.
Question 15
Marks: 1
Find the error in the following program segment:
int sum( int x, int y )
{
int result;
result = x + y;
}
Choose one answer.
a. not sure | ||
b. int sum( int x, int y ) { return x + y; } | ||
c. all variants are correct | ||
d. int sum( int x, int y ) { result x + y; } | ||
e. result sum( int x, int y ) { int result; result = x + y; } |
Correct
Marks for this submission: 1/1.
Question 16
Marks: 1
If the variable number is not equal to 7, print "The variable number is not equal to 7"
Choose one answer.
a. if ( number = 7 ) std::cout << "The variable number is not equal to 7\n"; | ||
b. if ( number == 7 ) std::cout << "The variable number is not equal to 7\n"; | ||
c. if ( number != 7 ) std::cout << "The variable number is not equal to 7\n"; | ||
d. if ( number < > 7 ) std::cout << "The variable number is not equal to 7\n"; | ||
e. if ( number >< 7 ) std::cout << "The variable number is not equal to 7\n"; |
Correct
Marks for this submission: 1/1.
Question 17
Marks: 1
The statement in a called function passes the value of an expression back to the calling function
Correct
Marks for this submission: 1/1.
Question 18
Marks: 1
If the variable number is not equal to 7, print "The variable number is not equal to 7".
Choose one answer.
a. if ( number >< 7 ) std::cout << "The variable number is not equal to 7\n"; | ||
b. if ( number == 7 ) std::cout << "The variable number is not equal to 7\n"; | ||
c. if ( number != 7 ) std::cout << "The variable number is not equal to 7\n"; | ||
d. if ( number = 7 ) std::cout << "The variable number is not equal to 7\n"; | ||
e. if ( number < > 7 ) std::cout << "The variable number is not equal to 7\n"; |
Correct
Marks for this submission: 1/1.
Question 19
Marks: 1
The address operator & can be applied only to constants and to expressions
Answer:
True False
Correct
Marks for this submission: 1/1.
Question 20
Marks: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int n = 1;
while (n<=5)
cout << n++;
return 0;
}
Choose one answer.
a. 123456 | ||
b. 1234 | ||
c. 234 | ||
d. 12345 | ||
e. 2345 |
Incorrect
Marks for this submission: 0/1.
Question 21
Marks: 1
Which functions will every class contain?
Choose one answer.
a. Destructor | ||
b. friend function | ||
c. None | ||
d. Both a constructor and a destructor | ||
e. Constructor |
Incorrect
Marks for this submission: 0/1.
Question 22
Marks: 1
The stream manipulators ___________, __________ and ___________ specify that integers should be displayed in octal, hexadecimal and decimal formats, respectively
Choose one answer.
a. oct, hex and dec | ||
b. O, H and D | ||
c. octi, hexi and deci |
Correct
Marks for this submission: 1/1.
Question 23
Marks: 1
If there are fewer initializers in an initializer list than the number of elements in the array, the remaining elements are initialized to the last value in the initializer list
Choose one answer.
a. true | ||
b. it depends on compilator | ||
c. it depends of the type of an array | ||
d. false |
Correct
Marks for this submission: 1/1.
Question 24
Marks: 1
Is the following piece of code valid?
#include <iostream>
using namespace std;
int main(){
int *steve;
steve = &steve;
return 0;
}
Answer:
True False
Incorrect
Marks for this submission: 0/1.
Question 25
Marks: 1
What will be the result of: cout << (5 << 3); ?
Choose one answer.
a. Compiler error | ||
b. I don t know | ||
c. 35 | ||
d. 40 | ||
e. 53 |
Incorrect
Marks for this submission: 0/1.
Question 26
Marks: 1
Repeating a set of instructions a specific number of times is called repetition.
Correct
Marks for this submission: 1/1.
Question 27
Marks: 1
Find the error(s) in the following and correct it (them).
Assume the following prototype is declared in class Employee:
int Employee( const char *, const char * );
Choose one answer.
a. Employee( const char , const char ); | ||
b. Employee( const char *, const char * ); | ||
c. int Employee( const char *, const char * ); |
Incorrect
Marks for this submission: 0/1.
Question 28
Marks: 1
A variable declared outside any block or function is a variable.
Correct
Marks for this submission: 1/1.
Question 29
Marks: 1
Which of the statements creates a dynamic array of type double and size n?
Choose one answer.
a. double arr = new double[n]; | ||
b. double arr[n]; | ||
c. double *arr = new double[n]; | ||
d. int arr = new int[n]; | ||
e. float *arr = new float[n]; |
Correct
Marks for this submission: 1/1.
Question 30
Marks: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int a = 17;
if (a<10) {
cout << "A";
}
if (a%17==0) {
cout << "B";
} else {
cout << "C";
}
cout << endl;
return 0;
}
Choose one answer.
a. C | ||
b. A | ||
c. AB | ||
d. AC | ||
e. B |
Correct
Marks for this submission: 1/1.
Question 31
Marks: 1
Which of the following accesses a variable in structure b?
Choose one answer.
a. b>>var | ||
b. b-var; | ||
c. b.var; | ||
d. b->var; | ||
e. b>var; |
Correct
Marks for this submission: 1/1.
Question 32
Marks: 1
What value does foo print out?
#include <iostream>
const int SIZE = 5;
struct tester
{
void foo()
{
std::cout << SIZE << std::endl;
}
enum
{
SIZE = 3
};
};
int main(int argc, char** argv)
{
tester t;
t.foo();
return 0;
}
Choose one answer.
a. code is incorrect | ||
b. 3 | ||
c. 8 | ||
d. 5 | ||
e. undefined |
Correct
Marks for this submission: 1/1.
Question 33
Marks: 1
Identify and correct the errors in the following code:
while ( c <= 5 )
{
product *= c;
c++;
Choose one answer.
a. while ( c <= 5 ) { product *= c; c++; } | ||
b. while ( c <= 5 ) { product *= c; c++ } | ||
c. while ( c <= 5 ); { product *= c; c++; |
Correct
Marks for this submission: 1/1.
Question 34
Marks: 1
Every function's body is delimited by left and right braces ({ and }).
Answer:
True False
Incorrect
Marks for this submission: 0/1.
Question 35
Marks: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int a = 17;
if (a>10) {
cout << "A";
}
if (a%17==0) {
cout << "B";
} else {
cout << "C";
}
cout << endl;
return 0;
}
Choose one answer.
a. B | ||
b. AB | ||
c. C | ||
d. AC | ||
e. A |
Incorrect
Marks for this submission: 0/1.
Question 36
Marks: 1
Which of the variable definitions below, which ones have external linkage and can be accessed from another translation unit?
int w = 1;
static int x = 2;
const int y = 3;
extern const int z = 4;
int main(int argc, char** argv)
{
return 0;
}
Choose one answer.
a. y and z | ||
b. w, y and z | ||
c. none | ||
d. w, x, y and z | ||
e. w and z |
Incorrect
Marks for this submission: 0/1.
Question 37
Marks: 1
Find the error(s) in the following code segment:
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;
}
Choose one answer.
a. switch ( n ) { case 1: cout << "The number is 1" << endl; case 2: cout << "The number is 2" << endl; default: cout << "The number is not 1 or 2" << endl; } | ||
b. switch ( n ) { case 1: cout << "The number is 1" << endl; break; case 2: cout << "The number is 2" << endl; break; default: cout << "The number is not 1 or 2" << endl; break; } | ||
c. switch ( n ) { case 1: cout << "The number is 1" << endl; break; case 2: cout << "The number is 2" << endl; break; } |
Correct
Marks for this submission: 1/1.
Question 38
Marks: 1
When does the code block following while(x<100) execute?
Choose one answer.
a. While it wishes | ||
b. When x is equal to one hundred | ||
c. Infinite loop | ||
d. When x is less than one hundred | ||
e. When x is greater than one hundred |
Correct
Marks for this submission: 1/1.
Question 39
Marks: 1
Which of the following is a properly defined struct?
Choose one answer.
a. struct a_struct int a; | ||
b. struct a_struct {int a;} | ||
c. struct {int a;} | ||
d. struct a_struct {int a;}; | ||
e. Struct a_struct {int a;}; |
Correct
Marks for this submission: 1/1.
Question 40
Marks: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int a = 1;
do {
cout << a;
a+=2;
} while (a<=5);
return 0;
}
Choose one answer.
a. 13 | ||
b. 124 | ||
c. 12345 | ||
d. 135 | ||
e. 1234 |
Correct
Marks for this submission: 1/1.
Close this window
Midterm II
Review of attempt 1
Close this window
Started on | Tuesday, 7 December 2010, 05:38 PM |
Completed on | Tuesday, 7 December 2010, 06:28 PM |
Time taken | 50 mins 1 sec |
Marks | 12.67/40 |
Grade | 31.67 out of a maximum of 100 (32%) |
Question 1
Marks: 1
What is required to avoid falling through from one case to the next?
Choose one answer.
a. end; | ||
b. A semicolon. | ||
c. break; | ||
d. Stop; | ||
e. continue; |
Incorrect
Marks for this submission: 0/1.
Question 2
Marks: 1
Find the error in the following program segment:
int sum( int n )
{
if ( n == 0 )
return 0;
else
n + sum( n - 1 );
}
Choose one answer.
a. All variants are correct | ||
b. not sure | ||
c. int sum( int n ) { if ( n == 0 ) return 0; else return n + sum( n - 1 ); } | ||
d. int sum( int n ) { if ( n == 0 ) result 0; else result n + sum( n - 1 ); } | ||
e. int sum( int n ) { if ( n == 0 ) return=0; else return=n + sum( n - 1 ); } |
Incorrect
Marks for this submission: 0/1.
Question 3
Marks: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// use pointer to get first value of array
number = zPtr;
Choose one answer.
a. no errors | ||
b. number = &zPtr; | ||
c. number = *zPtr; |
Incorrect
Marks for this submission: 0/1.
Question 4
Marks: 1
What should get printed in the program below?
#include <iostream>
using namespace std;
class foo{
public:
foo() : z(x+1), y(2), x(3)
{
cout << "z: " << z << endl;
}
private:
int x;
int y;
int z;
};
int main(int argc, char** argv){
foo f;
return 0;
}
Choose one answer.
a. 2 | ||
b. 4 | ||
c. 1 | ||
d. 3 |
Correct
Marks for this submission: 1/1.
Question 5
Marks: 1
What does the program below output?
#include<iostream>
usingnamespace std;
int main() {
int a[6] = {3,5,1,6,8,2};
int idx = 0;
for (int i=0; i<6; i++)
if (a[idx]<a[i])
idx = i;
cout << a[idx] << endl;
return 0;
}
Choose one answer.
a. 8 | ||
b. 1440 | ||
c. 25 | ||
d. None of the given answers. | ||
e. 1 |
Incorrect
Marks for this submission: 0/1.
Question 6
Marks: 1
A selection sort application would take approximately ________ times as long to run on a 128-element vector as on a 32-element vector.
Choose one answer.
a. 16, because an O(n2) algorithm takes 16 times as long to sort four times as much information | ||
b. 32, because an O(n2) algorithm takes 32 times as long to sort four times as much information |
Incorrect
Marks for this submission: 0/1.
Question 7
Marks: 1
Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
++z;
Choose one answer.
a. ++*z; | ||
b. ++&z; | ||
c. ++z[4]; |
Incorrect
Marks for this submission: 0/1.
Question 8
Marks: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int a = 17;
if (a>10) {
cout << "A";
}
if (a%10==0) {
cout << "B";
} else {
cout << "C";
}
cout << endl;
return 0;
}
Choose one answer.
a. A | ||
b. AC | ||
c. B | ||
d. AB | ||
e. C |
Incorrect
Marks for this submission: 0/1.
Question 9
Marks: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int a = 10;
for (a=1; a<81; a*=3)
cout << a << " ";
cout << endl;
return 0;
}
Choose one answer.
a. 1 3 9 27 81 | ||
b. 1 3 6 9 12 | ||
c. 1 3 27 81 | ||
d. 10 30 | ||
e. 1 3 9 27 |
Incorrect
Marks for this submission: 0/1.
Question 10
Marks: 1
What will be output?
#include <iostream>
using namespace std;
void function1(int *a){
cout << *(a + 1) << " " << *(a + 9);
}
int main() {
int arr[] = {9,8,7,6,5,4,3,2,1,0};
function1(arr);
return 0;
}
Choose one answer.
a. 9 1 | ||
b. 8 1 | ||
c. 8 0 | ||
d. 9 2 |
Incorrect
Marks for this submission: 0/1.
Question 11
Marks: 1
If there are fewer initializers in an initializer list than the number of elements in the array, the remaining elements are initialized to the last value in the initializer list
Choose one answer.
a. false | ||
b. it depends of the type of an array | ||
c. it depends on compilator | ||
d. true |
Incorrect
Marks for this submission: 0/1.
Question 12
Marks: 1
The modulus operator (%) can be used only with integer operands.
Answer:
True False
Correct
Marks for this submission: 1/1.
Question 13
Marks: 1
Why would you want to use inline functions?
Choose one answer.
a. To decrease the size of the resulting program | ||
b. To remove unnecessary functions | ||
c. To make your code more clear | ||
d. To increase the speed of the resulting program | ||
e. To simplify the source code file |
Correct
Marks for this submission: 1/1.
Question 14
Marks: 1
Find four different C++ statements that each add 1 to integer variable x:
Choose at least one answer.