- •What variable is?
- •When it is not known in advance how many times a set of statements will be repeated, a(n)_________value can be used to terminate the repetition
- •What is the difference between a local variable and a data member?
- •When used, the _________ stream manipulator causes positive numbers to display with a plus sign.
- •In one statement, assign the sum of the current value of X and y to z and postincrement the value of X
- •Function ________ is used to produce random numbers
- •Function ________ is used to set the random number seed to randomize a program
- •For a local variable in a function to retain its value between calls to the function, it must be declared with the ________ storage-class specifier
- •Find the error in the following program segment and correct the error: #include ;
- •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 * );
- •Iostream.H
- •Int c, thisIsAVariable, q76354, number;
- •If…else
- •Infinite loop, z must be decremented so that it eventually becomes less than 0.
- •Int smallest( int X, int y, int z)
- •Void instructions( void )
- •Int g( void)
- •Int h( void ) {
- •Void f ( double a)
- •Void product( void )
- •Int result;
- •Int table[ arraySize ][ arraySize];
- •0, Null, an address
- •Void exchange( double *X, double *y )
- •Int evaluate( int X, int (*poly)( int ))
- •Int hour;
- •Int minute;
- •Int second;
- •Initialized
- •Is not allowed to access any non-static member of the class.
- •Istream
- •What variable is?
- •When it is not known in advance how many times a set of statements will be repeated, a(n)_________value can be used to terminate the repetition
- •What is the difference between a local variable and a data member?
- •When used, the _________ stream manipulator causes positive numbers to display with a plus sign.
- •In one statement, assign the sum of the current value of X and y to z and postincrement the value of X
- •Function ________ is used to produce random numbers
- •Function ________ is used to set the random number seed to randomize a program
- •For a local variable in a function to retain its value between calls to the function, it must be declared with the ________ storage-class specifier
- •Find the error in the following program segment and correct the error: #include ;
- •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 * );
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
- •Preparation for Final Exam mcq Quiz big - Попытка 1
Pointers of different types can never be assigned to one another without a cast operation
false
Write single C++ statements that input integer variable x with cin and >>
cin>>x;
Write single C++ statements that input integer variable y with cin and >>.
cin >> y;
Write single C++ statements that postincrement variable i by 1
i++;
Write single C++ statements that determine whether i is less than or equal to y
if (i<=y)
Write single C++ statements that output integer variable power with cout and <<
cout << power << endl;
What is wrong with the following while repetition statement? while ( z >= 0 ) sum += z;
The value of the variable z is never changed in the while statement. Therefore, if the loop continuation condition (z >= 0) is initially true, an infinite loop is created. To prevent the infinite loop, z must be decremented so that it eventually becomes less than 0.
Write a C++ statement or a set of C++ statements to sum the odd integers between 1 and 99 using a for statement. Assume the integer variables sum and count have been declared
sum = 0; for ( count = 1; count <= 99; count += 2 ) sum += count;
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.
cout << fixed << left << setprecision( 1 ) << setw( 15 ) << 333.546372 << setprecision( 2 ) << setw( 15 ) << 333.546372 << setprecision( 3 ) << setw( 15 ) << 333.546372 << endl;
Write a C++ statement or a set of C++ statements to calculate the value of 2.5 raised to the power 3 using function pow. Print the result with a precision of 2 in a field width of 10 positions
cout << fixed << setprecision( 2 ) << setw( 10 ) << pow( 2.5, 3 ) << endl;
Write a C++ statement or a set of C++ statements to print the integers from 1 to 20 using a while loop and the counter variable x. Assume that the variable x has been declared, but not initialized. Print only 5 integers per line. [Hint: Use the calculation x % 5. When the value of this is 0, print a newline character; otherwise, print a tab character.]
x = 1; while ( x <= 20 ) { cout << x; if ( x % 5 == 0 ) cout << endl; else cout << '\t'; x++; }
What variable is?
named part in a memory
Write four different C++ statements that each add 1 to integer variable x
x =+ 1; x += 1; ++x; x++;
When it is not known in advance how many times a set of statements will be repeated, a(n)_________value can be used to terminate the repetition
Sentinel, signal, flag or dummy
What is the difference between a local variable and a data member?
A local variable is declared in the body of a function and can be used only from the point at which it is declared to the immediately following closing brace. A data member is declared in a class definition, but not in the body of any of the class's member functions. Every object (instance) of a class has a separate copy of the class's data members. Also, data members are accessible to all member functions of the class.
When a member function is defined outside the class definition, the function header must include the class name and the _________, followed by the function name to "tie" the member function to the class definition
binary scope resolution operator (::)
When each object of a class maintains its own copy of an attribute, the variable that represents the attribute is also known as a(n) _________.
data member
What statement is used to make decisions:
if
Write a declaration for the following: Integer count that should be maintained in a register. Initialize count to 0.
register int count = 0;
Write a declaration for the following: Double-precision, floating-point variable lastVal that is to retain its value between calls to the function in which it is defined.
static double lastVal;
Why would a function prototype contain a parameter type declaration such as double &?
This creates a reference parameter of type "reference to double" that enables the function to modify the original variable in the calling function
Write one or more statements that perform the following task for and array called “fractions”. Define a constant variable arraySize initialized to 10.
const int arraySize = 10;
Write one or more statements that perform the following task for and array called “fractions”. Declare an array with arraySize elements of type double, and initialize the elements to 0.
double fractions[ arraySize ] = { 0.0};
Write one or more statements that perform the following task for and array called “fractions”. Name the fourth element of the array
fractions[ 3 ]
Write one or more statements that perform the following task for and array called “fractions”. Refer to array element 4
fractions[ 4 ]
Write one or more statements that perform the following task for and array called “fractions”. Assign the value 1.667 to array element 9
fractions[ 9 ] = 1.667;
Write one or more statements that perform the following task for and array called “fractions”. Assign the value 3.333 to the seventh element of the array
fractions[ 6 ] = 3.333;
Write one or more statements that perform the following task for and array called “fractions”. Print array elements 6 and 9 with two digits of precision to the right of the decimal point.
cout << fixed << setprecision ( 2 ); cout << fractions[ 6 ] < < ' ' fractions[ 9 ] << endl;
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.
for ( int i = 0; < arraySize; i++ ) cout << "fractions[" < i << "] = " << fractions[ i ] << endl;
Write a program segment to print the values of each element of array table in tabular format with 3 rows and 3 columns. Assume that the array was initialized with the declaration int table[ arraySize ][ arraySize ] = { { 1, 8 }, { 2, 4, 6 }, { 5 } }; and the integer variables i and j are declared as control variables.
cout << " [0] [1] [2]" << endl; for ( int i = 0; i < arraySize; i++ ) { cout << '[' << i << "] "; for ( int j = 0; j < arraySize; j++ ) cout << setw( 3 ) << table[ i ][ j ] << " "; cout << endl;
Write two separate statements that each assign the starting address of array numbers to the pointer variable nPtr.
nPtr = numbers; nPtr = &numbers[ 0 ];
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Declare the variable fPtr to be a pointer to an object of type double.
double *fPtr;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the value of the object pointed to by fPtr.
cout << "The value of *fPtr is " << *fPtr << endl;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign the value of the object pointed to by fPtr to variable number2.
number2 = *fPtr;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the value of number2.
cout << "The value of number2 is " << number2 << endl;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the address of number1.
cout << "The address of number1 is " << &number1 << endl;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the address stored in fPtr.
cout << "The address stored in fPtr is " << fPtr << endl;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Copy the string stored in array s2 into array s1.
strcpy( s1, s2 );
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Compare the string in s1 with the string in s2, and print the result.
cout << "strcmp(s1, s2) = " << strcmp( s1, s2 ) << endl;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Append the first 10 characters from the string in s2 to the string in s1.
strncat( s1, s2, 10 );
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Determine the length of the string in s1, and print the result.
cout << "strlen(s1) = " << strlen( s1 ) << endl;
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign to ptr the location of the first token in s2. The tokens delimiters are commas (,).
ptr = strtok( s2, ",");
Write the function header for a function called exchange that takes two pointers to double-precision, floating-point numbers x and y as parameters and does not return a value
void exchange( double *x, double *y )
Write the function header for a function called evaluate that returns an integer and that takes as parameters integer x and a pointer to function poly. Function poly takes an integer parameter and returns an integer.
int evaluate( int x, int (*poly)( int ))
Write two statements that each initialize character array vowel with the string of vowels, "AEIOU".
char vowel[] = "AEIOU"; char vowel[] = { 'A', 'E', 'I', 'O', 'U', '\0' };
What (if anything) prints when the following statement is performed?Assume the following variable declarations: char s1[ 50 ] = "jack"; char s2[ 50 ] = "jill"; char s3[ 50 ]; cout << strcpy( s3, s2 ) << endl;
jill
What (if anything) prints when the following statement is performed?Assume the following variable declarations: char s1[ 50 ] = "jack"; char s2[ 50 ] = "jill"; char s3[ 50 ]; cout << strcat( strcat( strcpy( s3, s1 ), " and " ), s2 ) << endl;
jack and jill
What (if anything) prints when the following statement is performed?Assume the following variable declarations: char s1[ 50 ] = "jack"; char s2[ 50 ] = "jill"; char s3[ 50 ]; cout << strlen( s1 ) + strlen( s2 ) << endl;
8
What (if anything) prints when the following statement is performed?Assume the following variable declarations: char s1[ 50 ] = "jack"; char s2[ 50 ] = "jill"; char s3[ 50 ]; cout << strlen( s3 ) << endl;
13
When used, the _________ stream manipulator causes positive numbers to display with a plus sign.
showpos
Identify and correct the errors in the following code: while ( c <= 5 ) { product *= c; c++;
while ( c <= 5 ) { product *= c; c++; }
Identify and correct the errors in the following code: if ( gender == 1 ) cout << "Woman" << endl; else; cout << "Man" << endl;
if ( gender == 1 ) cout << "Woman" << endl; else cout << "Man" << endl;
Identify and correct the errors in the following code: cin << value;
cin >> value;
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 ________.
overloading
In one statement, assign the sum of the current value of X and y to z and postincrement the value of X
z = x++ + y;
Identify and correct the errors in the following statement (assume that the statement using std::cout; is used): if ( c => 7 ) cout << "c is equal to or greater than 7\n";
if ( c >= 7 ) cout << "c is equal to or greater than 7\n";
Identify and correct the errors in the following statement (assume that the statement using std::cout; is used): if ( c < 7 ); cout << "c is less than 7\n";
if ( c < 7 ) cout << "c is less than 7\n";
If the variable number is not equal to 7, print "The variable number is not equal to 7"
if ( number != 7 ) std::cout << "The variable number is not equal to 7\n";
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
false
It is an error if an initializer list contains more initializers than there are elements in the array
true
If a member initializer is not provided for a member object of a class, the object's __________ is called
default constructor
Input/output in C++ occurs as ____________ of bytes
streams
Input operations are supported by class __________.
istream
Input with the stream extraction operator >> always skips leading white-space characters in the input stream, by default
true
If a nonrecoverable error occurs during a stream operation, the bad member function will return TRue
true
If the file-position pointer points to a location in a sequential file other than the beginning of the file, the file must be closed and reopened to read from the beginning of the file
false
The default case is required in the switch selection statement
false
The break statement is required in the default case of a switch selection statement to exit the switch properly
false
The expression ( x > y && a < b ) is true if either the expression x > y is true or the expression a < b is true
false
The ________ statement in a called function passes the value of an expression back to the calling function
return
The keyword ________ is used in a function header to indicate that a function does not return a value or to indicate that a function contains no parameters
void
The ________ of an identifier is the portion of the program in which the identifier can be used
scope
The three ways to return control from a called function to a caller are ________, ________ and ________.
return, return expression or encounter the closing right brace of a function.
The storage-class specifiers are mutable, ________, ________, ________ and ________.
auto, register, extern, static
The six possible scopes of an identifier are ________, ________, ________, ________, ________ and ________.
function scope, file scope, block scope, function-prototype scope, class scope, namespace scope
The ________ enables access to a global variable with the same name as a variable in the current scope
unary scope resolution operator (::)
The_________selection statement is used to execute one action when a condition is true or a different action when that condition is false.
if…else
The types of arguments in a function call must match the types of the corresponding parameters in the function prototype's parameter list
true
The source-code file and any other files that use a class can include the class's header file via an _________ preprocessor directive
#include
The arithmetic operators *, /, %, + and all have the same level of precedence
false
The modulus operator (%) can be used only with integer operands
true
The escape sequence \n, when output with cout and the stream insertion operator, causes the cursor to position to the beginning of the next line on the screen
true
The ________ qualifier is used to declare read-only variables
const
The elements of an array are related by the fact that they have the same ________ and ___________.
name, type
The number used to refer to a particular element of an array is called its ________.
subscript (or index)
The process of placing the elements of an array in order is called ________ the array
sorting
The process of determining if an array contains a particular key value is called _________ the array
searching
the error in the following program segment and correct the error: Assume that int a[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } }; a[ 1, 1 ] = 5;
a[ 1, 1 ] = 5;
The three values that can be used to initialize a pointer are_____________,__________ and___________.
0, NULL, an address
The only integer that can be assigned directly to a pointer is_____________.
0
The address operator & can be applied only to constants and to expressions
false
The __________ operator dynamically allocates memory for an object of a specified type and returns a __________ to that type.
new, pointer
The keyword __________ specifies that an object or variable is not modifiable after it is initialized
const
The __________ operator reclaims memory previously allocated by new.
delete
The stream manipulators that format justification are_________, _________ and _______.
left, right and internal
The ostream member function ___________ is used to perform unformatted output
write
The symbol for the stream insertion operator is ____________.
<<
The four objects that correspond to the standard devices on the system include _________, _________, __________ and ___________.
cin, cout, cerr and clog
The symbol for the stream extraction operator is __________
>>
The stream manipulators ___________, __________ and ___________ specify that integers should be displayed in octal, hexadecimal and decimal formats, respectively
oct, hex and dec
The stream member function flags with a long argument sets the flags state variable to its argument and returns its previous value.
false
The stream extraction operator >> can be overloaded with an operator function that takes an istream reference and a reference to a user-defined type as arguments and returns an istream reference.
true
The stream insertion operator << can be overloaded with an operator function that takes an istream reference and a reference to a user-defined type as arguments and returns an istream reference
false
The stream member function rdstate returns the current state of the stream
true
The cout stream normally is connected to the display screen
true
The stream member function good returns TRUE if the bad, fail and eof member functions all return false
true
The cin stream normally is connected to the display screen
false
The ostream member function put outputs the specified number of characters
false
The stream manipulators dec, oct and hex affect only the next integer output operation
false
The programmer must create the cin, cout, cerr and clog objects explicitly
false
The ostream member function write can write to standard-output stream cout
true
The efficiency of merge sort is ______
O(n log n).
Variables declared in a block or in the parameter list of a function are assumed to be of storage class ________ unless specified otherwise
auto
Variables declared in the body of a particular member function are known as data members and can be used in all member functions of the class
false
Find the error(s) in the following code segment: x = 1; while ( x <= 10 ); x++; }
x = 1; while ( x <= 10 ) x++; }
Find the error(s) in the following code segment: for ( y = .1; y != 1.0; y += .1 ) cout << y << endl;
for ( y = 1; y != 10; y++ ) cout << ( static_cast< double >( y ) / 10 ) << endl;
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; }
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; }
Find the error(s) in the following code segment. The following code should print the values 1 to 10: n = 1; while ( n < 10 ) cout << n++ << endl;
n = 1; while ( n < 11 ) cout << n++ << endl;
Function ________ is used to produce random numbers
rand()
Function ________ is used to set the random number seed to randomize a program
srand()
For a local variable in a function to retain its value between calls to the function, it must be declared with the ________ storage-class specifier
static
Find the error in the following program segment: int g( void) { cout << "Inside function g" << endl; int h( void ) { cout << "Inside function h" << endl; } }
int g( void) { cout << "Inside function g" << endl; } int h( void ) { cout << "Inside function h" << endl; }
Find the error in the following program segment: int sum( int x, int y ) { int result; result = x + y; }
int sum( int x, int y ) { return x + y; }
Find the error in the following program segment: int sum( int n ) { if ( n == 0 ) return 0; else n + sum( n - 1 ); }
int sum( int n ) { if ( n == 0 ) return 0; else return n + sum( n - 1 ); }
Find the error in the following program segment void f ( double a); { float a; cout << a << endl; }
void f ( double a) { cout << a << endl; }
Find the error in the following program segment: void product( void ) { 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; }
void product( void ) { int a; int b; int c; int result; cout << "Enter three integers: "; cin >> a >> b >> c; result = a * b * c; cout << "Result is " << result; }
Find the error in the following program segment and correct the error: #include ;
#include
Find the error in the following program segment and correct the error: arraySize = 10; // arraySize was declared const
const int arraySize=10;
Find the error in the following program segment and correct the error: Assume that int b[ 10 ] = { 0 }; for ( int i = 0; <= 10; i++ ) b[ i ] = 1;
for ( int i = 0; <= 9; i++ ) b[ i ] = 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; zPtr = z;
++zPtr;
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;
number = *zPtr;
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 ];
number = zPtr[ 2 ];
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 }; // print entire array z for ( int i = 0; i <= 5; i++ ) cout << zPtr[ i ] << endl;
for ( int i = 0; i < 5; i++ ) cout << zPtr[ i ] << endl;
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 the value pointed to by sPtr to number number = *sPtr;
number = *static_cast< int * >( sPtr );
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;
++z[4];
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 }; char s[ 10 ]; cout << strncpy( s, "hello", 5 ) << endl;
cout << strncpy( s, "hello", 6 ) << endl;
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 }; char s[ 12 ]; strcpy( s, "Welcome Home");
char s[ 13 ]; strcpy( s, "Welcome Home");
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 }; if ( strcmp( string1, string2 ) ) cout << "The strings are equal" << endl;
if ( strcmp( string1, string2 ) == 0) cout << "The strings are equal" << endl;
Find the error(s) in the following and correct it (them). Assume the following prototype is declared in class Time: void ~Time( int );
~Time( );
Find the error(s) in the following and correct it (them). The following is a partial definition of class Time: class Time { public: // function prototypes private: int hour = 0; int minute = 0; int second = 0; }; // end class Time
class Time { public: // function prototypes Time (int my_hour, int my_minute, int my_second) { hour=my_hour; minute=my_minute; second=my_second; } private: int hour; int minute; int second; }; // end class Time
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 * );
Employee( const char *, const char * );
Find the errors in the following class and explain how to correct them: class Example { public: Example( int y = 10 ) : data( y ) { // empty body } // end Example constructor int getIncrementedData() const { return data++; } // end function getIncrementedData static int getCount() { cout << "Data is " << data << endl; return count; } // end function getCount private: int data; static int count; }; // end class Example
Error: The class definition for Example has two errors. The first occurs in function getIncrementedData. The function is declared const, but it modifies the object. Correction: To correct the first error, remove the const keyword from the definition of getIncrementedData. Error: The second error occurs in function getCount. This function is declared static, so it is not allowed to access any non-static member of the class. Correction: To correct the second error, remove the output line from the getCount definition.
Explain the purpose of a function parameter. What is the difference between a parameter and an argument?
A parameter represents additional information that a function requires to perform its task. Each parameter required by a function is specified in the function header. An argument is the value supplied in the function call. When the function is called, the argument value is passed into the function parameter so that the function can perform its task
Every function's body is delimited by left and right braces ({ and }).
true
Empty parentheses following a function name in a function prototype indicate that the function does not require any parameters to perform its task
true
Each parameter in a function header should specify both a(n) _________ and a(n) _________.
type, name
Every class definition contains keyword _________ followed immediately by the class's name
class
Every C++ statement ends with a(n):
semicolon
Every C++ program begins execution at the function
main
Keyword public is a(n) _________.
access specifier
Give the function header for the following function. Function hypotenuse that takes two double-precision, floating-point arguments, side1 and side2, and returns a double-precision, floating-point result.
double hypotenuse( double side1, double side2)
Give the function header for the following function. Function smallest that takes three integers, x, y and z, and returns an integer.
int smallest( int x, int y, int z)
Give the function header for the following function. Function instructions that does not receive any arguments and does not return a value. [Note: Such functions are commonly used to display instructions to a user.]
void instructions( void )
Give the function header for the following function. Function intToDouble that takes an integer argument, number, and returns a double-precision, floating-point result.
double intToDouble( int number)
Lists and tables of values can be stored in __________ or __________.
arrays, vectors
Use a for statement to print the elements of array numbers using array subscript notation. Print each number with one position of precision to the right of the decimal point:
cout << fixed << showpoint << setprecision( 1 ); for ( int i = 0; i < SIZE; i++ ) cout << numbers[ i ] <<' ';
Use a for statement to print the elements of array numbers using pointer/offset notation with pointer nPtr
cout << fixed << showpoint << setprecision( 1 ); for ( int j = 0; j < SIZE; j++ ) cout << *( nPtr + j ) << ' ';
Use a for statement to print the elements of array numbers using pointer/offset notation with the array name as the pointer
cout << fixed << showpoint << setprecision( 1 ); for ( int k = 0; k < SIZE; k++ ) cout << *( numbers + k ) << ' '
Use a for statement to print the elements of array numbers using pointer/subscript notation with pointer nPtr
cout << fixed << showpoint << setprecision( 1 ); for ( int m = 0; m < SIZE; m++ ) cout << nPtr[ m ] << ' ';
Use a stream manipulator that causes the exponent in scientific notation and the letters in hexadecimal values to print in capital letters
cout << uppercase;
Use a stream manipulator to ensure floating-point values print in scientific notation
cout << scientific;
Use a stream manipulator such that, when integer values are output, the integer base for octal and hexadecimal values is displayed.
cout << showbase;
Use a stream member function to set the fill character to '*' for printing in field widths larger than the values being output. Write a separate statement to do this with a stream manipulator
cout.fill( '*' ); cout << setfill( '*' );
__________ must be used to initialize constant members of a class
Member initializers
Member objects are constructed __________ their enclosing class object
before
Member function _________ can be used to set and reset format state
flags
Member function read cannot be used to read data from the input object cin
False
Member functions seekp and seekg must seek relative to the beginning of a file
false
Outputs to the standard error stream are directed to either the ___________ or the ___________ stream object
cerr or clog
Output operations are supported by class ___________.
ostream
Output to cerr is unbuffered and output to clog is buffered
true
Output the string "Enter your name: "
cout << "Enter your name: ";
Output the address of the variable myString of type char *
cout << static_cast< void * >( myString );
Output the address in variable integerPtr of type int *.
cout << integerPtr;
Output the value pointed to by floatPtr of type float *.
cout << *floatPtr;
Output the characters '0' and 'K' in one statement with ostream function put
cout.put( '0' ).put( 'K' );
Preparation for Final Exam mcq Quiz big - Попытка 1
Начало формы
Question1
Баллов: 1
Write one or more statements that perform the following task for and array called “fractions”.Refer to array element 4.
Выберите один ответ.
|
a. fractions[ 3 ] |
|
|
b. fractions( 3 ) |
|
|
c. fractions( 4 ) |
|
|
d. no ideas |
|
+ |
e. fractions[ 4 ] |
|
Question2
Баллов: 1
What keyword covers unhandled possibilities?
Выберите один ответ.
|
a. all |
|
|
b. other |
|
|
c. else |
|
|
d. contingency |
|
+ |
e. default |
|
Question3
Баллов: 1
Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10.
!( ((count < 10) || (x < y)) && (count >= 0) )
Выберите один ответ.
|
a. !(=true) |
|
|
b. true |
|
|
c. None of the given choices. |
|
|
d. Both true and false |
|
+ |
e. false |
|
Question4
Баллов: 1
Which of these has the lowest precedence priority?
Выберите один ответ.
|
a. >> |
|
|
b. ?: |
|
+ |
c. \ |
|
|
d. || |
|
|
e. && |
|
Question5
Баллов: 1
The stream member function flags with no arguments resets the stream's format state
Ответ:
+False
Question6
Баллов: 1
How many times is a do while loop guaranteed to loop?
Выберите один ответ.
|
a. Variable |
|
|
b. 1 |
|
|
c. 0 |
|
+ |
d. Infinitely |
|
|
e. 5 |
|
Question7
Баллов: 1
Use a stream manipulator to ensure floating-point values print in scientific notation
Выберите один ответ.
+ |
a. cout << scientific; |
|
|
b. cout << setprecision(2)<<fixed; |
|
Question8
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Append the first 10 characters from the string in s2 to the string in s1.
Выберите один ответ.
|
a. catstrn( s1, s2, 10 ); |
|
+ |
b. strncat( s1, s2, 10 ); |
|
|
c. string_cat( s1, s2, 10 ); |
|
Question9
Баллов: 1
Which of the following is a valid inline for function foo?
Выберите один ответ.
+ |
a. inline:void foo() {} |
|
|
b. None |
|
|
c. inline int foo() {} |
|
|
d. void foo() inline {} |
|
|
e. inline void foo() {} |
|
Question10
Баллов: 1
All variables must be declared before they are used.
Ответ:
+True
Preparation for Final Exam mcq Quiz big - Попытка 1
Начало формы
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Question11
Баллов: 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; }
Выберите один ответ.
|
a. AC |
|
|
b. C |
|
|
c. A |
|
+ |
d. B |
|
|
e. AB |
|
Question12
Баллов: 1
Which of the following classes handlers file input?
Выберите один ответ.
|
a. iomanip |
|
|
b. instream |
|
|
c. ofstream |
|
+ |
d. ifstream |
|
|
e. inputfile |
|
Question13
Баллов: 1
How many times is Hello World printed by this program?
#include <iostream>
struct BS { BS() { std::cout << "Hello World" << std::endl; } unsigned int color; };
struct mid1 : virtual public BS { }; struct mid2 : virtual public BS { }; struct mid3 : public BS { }; struct mid4 : public BS { };
struct DR : public mid1, public mid2, public mid3, public mid4 { };
int main(int argc, char** argv) { DR d; return 0; }
Выберите один ответ.
|
a. 1 |
|
|
b. 3 |
|
+ |
c. 2 |
|
|
d. code is ill-formed |
|
Question14
Баллов: 1
Which of the following adds one string to the end of another?
Выберите один ответ.
|
a. ++; |
|
+ |
b. stradd(); |
|
|
c. strcat(); |
|
|
d. append(); |
|
|
e. stringadd(); |
|
Question15
Баллов: 1
__________ must be used to initialize constant members of a class
Выберите один ответ.
+ |
a. Member initializers |
|
|
b. Classes |
|
|
c. Initializes |
|
Question16
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the value of the object pointed to by fPtr.
Выберите один ответ.
|
a. cout << "The value of &fPtr is " << &fPtr << endl; |
|
+ |
b. cout << "The value of *fPtr is " << *fPtr << endl; |
|
|
c. cout << "The value of fPtr is " << fPtr << endl; |
|
Question17
Баллов: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int a=10, b=3;
int * c = &a;
*c = 5;
cout << a << " " << b;
return 0;
}
Выберите один ответ.
|
a. 3 5 |
|
|
b. 5 3 |
|
|
c. 5 5 |
|
+ |
d. 10 3 |
|
|
e. None of the given choices. |
|
Question18
Баллов: 1
Give the function header for the following function. Function hypotenuse that takes two double-precision, floating-point arguments, side1 and side2, and returns a double-precision, floating-point result.
Выберите один ответ.
+ |
a. double hypotenuse( double side1, double side2) |
|
|
b. float hypotenuse( float side1, float side2) |
|
|
c. double float hypotenuse( double float side1, double float side2) |
|
|
d. float hypotenuse( double side1, double side2) |
|
|
e. not sure |
|
Question19
Баллов: 1
What does the program below output?
#include<iostream>
Using namespace 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;
}
Выберите один ответ.
|
a. 1440 |
|
|
b. None of the given answers. |
|
|
c. 25 |
|
|
d. 8 |
|
+ |
e. 1 |
|
Question20
Баллов: 1
What is the result of the following code? x=0; switch(x) { case 1: cout<<"One"; case 0: cout<<"Zero"; case 2: cout<<"Hello World"; }
Выберите один ответ.
|
a. Hello World |
|
|
b. ZeroHello World |
|
|
c. One |
|
|
d. OneZero |
|
+ |
e. Zero |
|
Preparation for Final Exam mcq Quiz big - Попытка 1
Начало формы
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Question21
Баллов: 1
What gets printed for the value of z?
#include <iostream>
struct Foo { Foo(int n) : x(n++), y(n++), z(n++) {} int x; int y; int z; };
int main(int argc, char** argv) { Foo f(3);
std::cout << "x: " << f.x << std::endl; std::cout << "y: " << f.y << std::endl; std::cout << "z: " << f.z << std::endl;
return 0; }
Выберите один ответ.
|
a. code is ill-formed |
|
|
b. 4 |
|
|
c. 5 |
|
|
d. 3 |
|
Question22
Баллов: 1
Find the error(s) in the following and correct it (them). The following is a partial definition of class Time:
class Time{ public: // function prototypes private: int hour = 0; int minute = 0; int second = 0; }; // end class Time
Выберите один ответ.
|
a. class Time { public: // function prototypes private: hour = 0; minute = 0; second = 0; }; // end class Time |
|
|
b. class Time{ public: // function prototypes Time (int my_hour, int my_minute, int my_second) { hour=my_hour; minute=my_minute; second=my_second; } private: int hour; int minute; int second; }; // end class Time |
|
|
c. no errors |
|
Question23
Баллов: 1
All programs can be written in terms of three types of control structures:
Sequence, selection and repetition.
Question24
Баллов: 1
Find the error(s) in the following code segment. The following code should print the values 1 to 10: n = 1; while ( n < 10 )
cout << n++ << endl;
Выберите один ответ.
|
a. n = 1; while ( n <=11 ) cout << n++ << endl; |
|
|
b. n = 1; while ( n < 11 ) cout << n++ << endl; |
|
|
c. n = 1; while ( n <= 10 ) cout << ++n << endl; |
|
Question25
Баллов: 1
All arguments to function calls in C++ are passed by value
Ответ:
True+False
Question26
Баллов: 1
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
int a = 1;
do {
a+=1;
cout << a;
} while (a<5);
return 0;
}
Выберите один ответ.
|
a. 1234 |
|
|
b. 23456 |
|
|
c. 2345 |
|
|
d. 12345 |
|
|
e. 123456 |
|
Question27
Баллов: 1
Predecrement the variable x by 1, then subtract it from the variable total
Выберите один ответ.
|
a. total = --x; |
|
|
b. total -= x--; |
|
|
c. total -= ++x; |
|
+ |
d. total -= --x; |
|
|
e. total -= x++-; |
|
Question28
Баллов: 1
A function that calls itself either directly or indirectly (i.e., through another function) is a ( n ) ________ function
Выберите один ответ.
+ |
a. recursive |
|
|
b. special |
|
|
c. not sure |
|
|
d. repetition |
|
|
e. loop |
|
Question29
Баллов: 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 * );
Выберите один ответ.
|
a. int Employee( const char *, const char * ); |
|
+ |
b. Employee( const char *, const char * ); |
|
|
c. Employee( const char , const char ); |
|
Question30
Баллов: 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 the value pointed to by sPtr to number number = *sPtr;
Выберите один ответ.
|
a. number = *static_cast< int * >( sPtr ); |
|
|
b. number = sPtr; |
|
|
c. number = *sPtr; |
|
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Preparation for Final Exam mcq Quiz big - Попытка 1
Начало формы
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Question31
Баллов: 1
What is the output of the program?
#include <iostream>
using namespace std;
int main() {
int a=3, b=5;
int * c = &a;
c = &b;
*c = 10;
cout << a << " " << b;
return 0;
}
Выберите один ответ.
|
a. 3 5 |
|
|
b. None of the given choices. |
|
|
c. 10 10 |
|
|
d. 10 5 |
|
|
e. 3 10 |
|
Question32
Баллов: 1
What does the program below output?
#include<iostream>
usingnamespace std;
int main() {
int a[6] = {3,5,1,6,8,2};
int result = 0;
for (int i=0; i<6; i++)
result += a[i];
cout << result << endl;
return 0;
}
Выберите один ответ.
|
a. 1440 |
|
|
b. 1 |
|
|
c. 8 |
|
|
d. 25 |
|
|
e. None of the given choices. |
|
Question33
Баллов: 1
Print the message "This is a C++ program" on one line:
Выберите один ответ.
|
a. std::cout >> "This is a C++ program\n"; |
|
|
b. std::cout << "This is a C++ \t\nprogram\n"; |
|
|
c. std::cin << "This is a C++ program\n"; |
|
|
d. std::cout << "This is a C++ program\n"; |
|
|
e. std::cout << "This \nis \na C++ pr\nogram\n"; |
|
Question34
Баллов: 1
Declare a pointer nPtr that points to a variable of type double
Выберите один ответ.
|
a. double *nPtr; |
|
|
b. double nPtr; |
|
|
c. double &nPtr; |
|
Question35
Баллов: 1
Which of the following is evaluated first?
Выберите один ответ.
|
a. I don t know |
|
|
b. || |
|
|
c. && |
|
|
d. Depends |
|
|
e. ! |
|
Question36
Баллов: 1
A function is invoked with a ________.
Выберите один ответ.
|
a. prototype |
|
|
b. int main() |
|
|
c. function name |
|
|
d. function call |
|
Question37
Баллов: 1
Output the address in variable integerPtr of type int *.
Выберите один ответ.
|
a. cout << * integerPtr; |
|
|
b. cout << integerPtr; |
|
|
c. cout << &integerPtr; |
|
Question38
Баллов: 1
Print
the message "This is a C++ program" with each word
separated from the next by a tab:
Question39
Баллов: 1
If a member initializer is not provided for a member object of a class, the object's __________ is called
Выберите один ответ.
|
a. initializer |
|
|
b. constructor |
|
|
c. creator |
|
|
d. default constructor |
|
Конец формы
Preparation for Final Exam mcq Quiz big - Попытка 1
Начало формы
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Question41
Баллов: 1
When used, the _________ stream manipulator causes positive numbers to display with a plus sign.
Выберите один ответ.
|
a. showpos |
|
|
b. where_is |
|
|
c. show |
|
|
d. place |
|
Question42
Баллов: 1
If assumptions in the code below are true what value would be the final value printed by this program? int main(int argc, char** argv) { std::cout << sizeof(int) << std::endl; int *x = new int; std::cout << x << std::endl; std::cout << x + 3 << std::endl; return 0; }
Выберите один ответ.
|
a. 0x6000000C |
|
|
b. undefined |
|
|
c. 0x60000003 |
|
|
d. 0x60000000 |
|
|
e. implementation defined |
|
Question43
Баллов: 1
An array that uses two subscripts is referred to as a ( n ) _________ array
Выберите один ответ.
|
a. double array |
|
|
b. no ideas |
|
|
c. two-dimensional |
|
|
d. multi-dimensional |
|
Question44
Баллов: 1
Give the function header for the following function. Function intToDouble that takes an integer argument, number, and returns a double-precision, floating-point result.
Выберите один ответ.
|
a. double intToDouble( int number) |
|
|
b. not sure |
|
|
c. float intToDouble( int number) |
|
|
d. int intToDouble( number) |
|
|
e. double intToDouble( double number) |
|
Question45
Баллов: 1
An individual array element that is passed to a function and modified in that function will contain the modified value when the called function completes execution
Ответ:
True
False
Question46
Баллов: 1
Which properly declares a variable of struct foo?
Выберите один ответ.
|
a. foo; |
|
|
b. var foo; |
|
|
c. foo var; |
|
|
d. struct foo; |
|
|
e. int foo; |
|
Question47
Баллов: 1
What output will be produced by the following code?
int extra = 2;
if (extra < 0)
cout << "small";
else if (extra == 0)
cout << "medium";
else
cout << "large";
Выберите один ответ.
|
a. None of the given choices. |
|
|
b. small |
|
|
c. medium |
|
|
d. Error |
|
|
e. large |
|
Question48
Баллов: 1
State
the values of the variable after the calculation is performed. Assume
that, when a statement begins executing, all variables have the
integer value 5: product *= x++;
Result:
product
=
x
=
Question49
Баллов: 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.
Выберите один ответ.
|
a. cin << fixed << left << setprecision( 1 ) << setw( 15 ) << 333.546372 << setprecision( 2 ) << setw( 15 ) << 333.546372 << setprecision( 3 ) << setw( 15 ) << 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 << setprecision( 1 ) << 333.546372; << setprecision( 2 ) << 333.546372; << setprecision( 3 ) << 333.546372; << endl; |
|
|
d. cout << fixed << left << setw( 15 ) << 333.546372 << setw( 15 ) << 333.546372 << setw( 15 ) << 333.546372 << endl; |
|
Question50
Баллов: 1
Declare the variables c, thisIsAVariable, q76354 and number to be of type int.
Выберите по крайней мере один ответ:
|
a. int c, thisIsAVariable, q76354, number |
|
|
b. int c, thisIsAVariable, q76354, number; |
|
|
c. int c; int thisIsAVariable; int q76354 int number; |
|
|
d. double c, thisIsAVariable, q76354, number; |
|
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Конец формы
Preparation for Final Exam mcq Quiz big - Попытка 1
Начало формы
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Question51
Баллов: 1
What will !((1 || 0) && 0) evaluate to?
Выберите один ответ.
|
a. Wrong code |
|
|
b. 1 |
|
|
c. 0 |
|
|
d. Undefined behaviour |
|
|
e. I don't know |
|
Question52
Баллов: 1
Repeating
a set of instructions a specific number of times is
called
repetition.
Question53
Баллов: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign the address of variable number1 to pointer variable fPtr.
Выберите один ответ.
|
a. fPtr = &number1; |
|
|
b. *fPtr = number1; |
|
|
c. fPtr = *number1; |
|
|
d. fPtr = *&number1; |
|
Question54
Баллов: 1
The types of arguments in a function call must match the types of the corresponding parameters in the function prototype's parameter list.
Ответ:
True
False
Question55
Баллов: 1
Every function's body is delimited by left and right braces ({ and }).
Ответ:
True
False
Question56
Баллов: 1
What value is printed out for the variable x? #include <iostream> int x; int main() { int y; std::cout << x << std::endl; std::cout << y << std::endl; return 0; }
Выберите один ответ.
|
a. zero |
|
|
b. 2 |
|
|
c. undefined |
|
|
d. -858993460 |
|
|
e. 3 |
|
Question57
Баллов: 1
Find the error in the following program segment and correct the error: Assume that int a[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } };
a[ 1, 1 ] = 5;
Выберите один ответ.
|
a. a[ 1, 1 ] = 5; |
|
|
b. a[ 1 ][ 1 ] = 5; |
|
Question58
Баллов: 1
#include<iostream>
usingnamespace std;
int ifunc(int a) {
return a/10.0;
}
double dfunc(int a) {
return a/10.0;
}
int main() {
cout << ifunc(9) << " " << dfunc(9) << endl;
return 0;
}
Выберите один ответ.
|
a. 0.9 |
|
|
b. 0.9 0 |
|
|
c. 0.9 0.9 |
|
|
d. 0 0.9 |
|
|
e. 0 0 |
|
Question59
Баллов: 1
Write the function header for a function called exchange that takes two pointers to double-precision, floating-point numbers x and y as parameters and does not return a value
Выберите один ответ.
|
a. void exchange( double x, double y ) |
|
|
b. void exchange( double *x, double y ) |
|
|
c. void exchange( double *x, double *y ) |
|
|
d. void exchange( double x, double *y ) |
|
Question60
Баллов: 1
Which of the following lines should NOT compile? 1 2 int main() 3 { 4 int a[54] = {}; 5 6 int b[54] = {}; 7 8 int* x = a; 9 10 int* const y = a; 11 12 b = x; 13 14 b = y; 15 16 return 0; 17 }
Выберите один ответ.
|
a. 12, 14 |
|
|
b. 8, 12 |
|
|
c. 8, 10, 12, 14 |
|
|
d. none |
|
|
e. 14 |
|
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Конец формы
Preparation for Final Exam mcq Quiz big - Попытка 1
Начало формы
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Question61
Баллов: 1
What statement is used to make decisions:
Выберите один ответ.
|
a. while |
|
|
b. not |
|
|
c. true/false |
|
|
d. and |
|
+ |
e. if |
|
Question62
Баллов: 1
If the variable number is not equal to 7, print "The variable number is not equal to 7".
Выберите один ответ.
|
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"; |
|
Question63
Баллов: 1
Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements?
Выберите один ответ.
|
a. foo[7]; |
|
|
b. foo; |
|
|
c. foo[100] |
|
|
d. foo(6); |
|
+ |
e. foo[100-94]; |
|
Question64
Баллов: 1
Correct the mistakes
float a, b, c;
cin << a,b,c;
Выберите один ответ.
|
a. cin << a,b,c; |
|
+ |
b. cin >> a,b,c; |
|
|
c. cin << a; b; c; |
|
|
d. cin >> a; b; c; |
|
|
e. cin >> a >> b >> c; |
|
Question65
Баллов: 1
If we have this code: char arr[8]; cin >> arr; And this text is entered: Hello World , what there will be in arr ?
Выберите один ответ.
+ |
a. Other |
|
|
b. Hello |
|
|
c. Hello W |
|
|
d. Hello Wo |
|
|
e. Hello World |
|
Question66
Баллов: 1
A variable that is known only within the function in which it is defined is called a ________.
Выберите один ответ.
+ |
a. local variable |
|
|
b. static variable |
|
|
c. class variable |
|
|
d. temporary variable |
|
|
e. global variable |
|
Question67
Баллов: 1
If we have class A with variable Name in it and write: A *obj , how do you invoke the Name variable?
Выберите один ответ.
|
a. A.Name |
|
|
b. A->Name |
|
|
c. obj.Name |
|
+ |
d. obj->Name |
|
|
e. None of these will work |
|
Question68
Баллов: 1
Which properly declares a variable of struct foo?
Выберите один ответ.
|
a. foo var; |
|
+ |
b. struct foo; |
|
|
c. var foo; |
|
|
d. int foo; |
|
|
e. foo; |
|
Question69
Баллов: 1
Given the assumptions in the comments, what values is printed for x? int main(int argc, char** argv) { std::cout << sizeof(int) << std::endl; int x = 0x1000; x = x << 32; std::cout << std::hex << x << std::endl; return 0; }
Выберите один ответ.
|
a. 0 |
|
|
b. undefined |
|
|
c. 0x00000000 |
|
|
d. implementation defined |
|
+ |
e. 0xFFFFFFFF |
|
Question70
Баллов: 1
When
it is not known in advance how many times a set of statements will be
repeated, a
value
can be used to terminate the repetition.
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Preparation for Final Exam mcq Quiz big - Попытка 1
Начало формы
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Question71
Баллов: 1
If ASCII code of 'A' is 65, what is the ASCII code of 'X'?
Выберите один ответ.
+ |
a. 88 |
|
|
b. 87 |
|
|
c. 86 |
|
|
d. 90 |
|
|
e. 89 |
|
Question72
Баллов: 1
The symbol for the stream insertion operator is ____________.
Выберите один ответ.
|
a. [ ] |
|
|
b. >> |
|
|
c. & |
|
|
d. @ |
|
|
e. << |
|
Question73
Баллов: 1
The SCOPE of an identifier is the portion of the program in which the identifier can be used.
Question74
Баллов: 1
Write a C++ statement or a set of C++ statements to print the integers from 1 to 20 using a while loop and the countervariable x. Assume that the variable x has been declared, but not initialized. Print only 5 integers per line. [Hint: Use the calculation x % 5. When the value of this is 0, print a newline character; otherwise, print a tab character.]
Выберите один ответ.
|
a. x = 1; while ( x >= 20 ) { cout << x; if ( x % 5 == 0 ) cout << endl; else cout << '\t'; x++; } |
|
|
b. x = 1; while ( x <= 20 ) { cout << x; if ( x % 5 = 0 ) cout << endl; else cout << '\t'; x++; } |
|
+ |
c. x = 1; while ( x <= 20 ) { cout << x; if ( x % 5 == 0 ) cout << endl; else cout << '\t'; x++; } |
|
Question75
Баллов: 1
Which of the following is a static string?
Выберите один ответ.
+ |
a. static string str; |
|
|
b. Static String |
|
|
c. char string[100]; |
|
|
d. 'Static String' |
|
|
e. static |
|
Question76
Баллов: 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; |
|
Question77
Баллов: 1
Find four different C++ statements that each add 1 to integer variable x:
Выберите по крайней мере один ответ:
+ |
a. ++x; |
|
|
b. x == x + 1; |
|
|
c. x += 1; |
|
+ |
d. x =+ 1; |
|
|
e. x += x + 1; |
|
+ |
f. x = x + 1; |
|
+
|
g. x++; |
|
Question78
Баллов: 1
Which of the following is true?
Выберите один ответ.
|
a. .1 |
|
|
b. 66 |
|
|
c. All of the above |
|
+ |
d. 1 |
|
|
e. -1 |
|
Question79
Баллов: 1
Which of the following is not a correct variable type?
Выберите один ответ.
|
a. char |
|
|
b. double |
|
|
c. int |
|
+ |
d. real |
|
|
e. float |
|
Question80
Баллов: 1
Which of the following operators does NOT indicate a sequence point in the code?
Выберите один ответ.
|
a. && |
|
+ |
b. ? |
|
|
c. , |
|
|
d. = |
|
|
e. || |
|
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Preparation for Final Exam mcq Quiz big - Попытка 1
Начало формы
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
Question81
Баллов: 1
What is the correct value to return to the operating system upon the successful completion of a program?
Выберите один ответ.
|
a. 1 |
|
|
b. Programs do not return a value. |
|
|
c. OK |
|
|
d. 01 |
|
|
e. -1 |
|
Question82
Баллов: 1
What is the value of y at the end of main? const int x = 5; int main(int argc, char** argv) { int x[x]; int y = sizeof(x) / sizeof(int); return 0; }
Выберите один ответ.
|
a. 0 |
|
|
b. undefined |
|
|
c. 20 |
|
|
d. 1 |
|
|
e. 5 |
|
Question83
Баллов: 1
Use a for statement to print the elements of array numbers using pointer/subscript notation with pointer nPtr
Выберите один ответ.
|
a. cout << fixed << showpoint << setprecision( 1 ); for ( int m = 0; m < SIZE; m++ ) cout << nPtr[ m ] << ' '; |
|
|
b. cout << fixed << showpoint << setprecision( 1 ); for ( int m = 0; m < SIZE; m++ ) cout << nPtr << ' '; |
|
|
c. cout << fixed << showpoint << setprecision( 1 ); for ( int m = 0; m < SIZE; m++ ) cout << *nPtr[ m ] << ' '; |
|
Question84
Баллов: 1
Outputs to the standard error stream are directed to either the ___________ or the ___________ stream object
Выберите один ответ.
|
a. cerr or clog |
|
|
b. cout or cin |
|
|
c. error.out or log.out |
|
|
d. error or log |
|
Question85
Баллов: 1
The ________ qualifier is used to declare read-only variables
Выберите один ответ.
|
a. read-only |
|
|
b. const |
|
|
c. static |
|
|
d. read |
|
|
e. unchangeable |
|
Question86
Баллов: 1
Identify and correct the errors in the following code: cin << value;
Ответ:
Question87
Баллов: 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; }
Выберите один ответ.
|
a. ill-formed |
|
|
b. 3 |
|
|
c. undefined |
|
|
d. 5 |
|
|
e. 6 |
|
Question88
Баллов: 1
What value does size print out? #include <iostream> const int SIZE = 5; struct tester { int array[SIZE]; enum { SIZE = 3 }; void size() { std::cout << sizeof(array) / sizeof(int); } }; int main(int argc, char** argv) { tester t; t.size(); return 0; }
Выберите один ответ.
|
a. 3 |
|
|
b. 0 |
|
|
c. 8 |
|
|
d. undefined |
|
|
e. 5 |
|
Question89
Баллов: 1
For a local variable in a function to retain its value between calls to the function, it must be declared with the ________ storage-class specifier
Выберите по крайней мере один ответ:
|
a. static |
|
|
b. auto |
|
|
c. local |
|
|
d. register |
|
|
e. member |
|
Question90
Баллов: 1
Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10.
(limit > 0) && ((limit/count) > 7)
Выберите один ответ.
|
a. false |
|
|
b. Both true and false |
|
|
c. None of the given choices. |
|
|
d. true |
|
|
e. Error |
|
Страница: (Назад) 1 2 3 4 5 6 7 8 9 10 (Далее)
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.
|
a. ++x; |
|
|
b. x += 1; |
|
|
c. x++; |
|
|
d. x += x + 1; |
|
|
e. x == x + 1; |
|
|
f. x =+ 1; |
|
|
g. x = x + 1; |
|
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. result sum( int x, int y ) { int result; result = x + y; } |
|
|
d. int sum( int x, int y ) { result x + y; } |
|
|
e. all variants are correct |
|
Correct
Marks for this submission: 1/1.
Question 16
Marks: 1
What is the output of the program?
#include <iostream> using namespace std; int main() { for (int a=10; a<91; a*=3) cout << a << " "; cout << endl; return 0; }
Choose one answer.
|
a. 10 30 90 270 |
|
|
b. 10 11 12 ... 90 |
|
|
c. 10 30 |
|
|
d. 10 30 90 |
|
|
e. 1 2 3 ... 90 |
|
Correct
Marks for this submission: 1/1.
Question 17
Marks: 1
The four objects that correspond to the standard devices on the system include _________, _________, __________ and ___________.
Choose one answer.
|
a. std.int, std.out, std.err and std.log |
|
|
b. cin, cout, cerr and clog |
|
|
c. in, out, err and log |
|
Incorrect
Marks for this submission: 0/1.
Question 18
Marks: 1
What is the value of the local variable x at the end of main? int x = 5; int main(int argc, char** argv) { int x = x; return 0; }
Choose one answer.
|
a. undefined |
|
|
b. 5 |
|
|
c. 3 |
|
|
d. 0 |
|
|
e. code is incorrect |
|
Incorrect
Marks for this submission: 0/1.
Question 19
Marks: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Append the first 10 characters from the string in s2 to the string in s1.
Choose one answer.
|
a. string_cat( s1, s2, 10 ); |
|
|
b. catstrn( s1, s2, 10 ); |
|
|
c. strncat( s1, s2, 10 ); |
|
Incorrect
Marks for this submission: 0/1.
Question 20
Marks: 1
The three ways to return control from a called function to a caller are ________, ________ and ________.
Choose at least one answer.
|
a. stop |
|
|
b. forward call |
|
|
c. encounter the closing right brace of a function |
|
|
d. return expression |
|
|
e. return |
|
|
f. break |
|
|
g. repeat |
|
|
h. goto |
|
Partially correct
Marks for this submission: 0.67/1.
Question 21
Marks: 1
Which of the following is a correct comment?
Choose one answer.
|
a. { Comment } |
|
|
b. */ Comments */ |
|
|
c. \\ |
|
|
d. /* Comment */ |
|
|
e. ** Comment ** |
|
Correct
Marks for this submission: 1/1.
Question 22
Marks: 1
What is the value of x at the end of main? int main(int argc, char** argv) { int x = 50 % -7; return 0; }
Choose one answer.
|
a. -1 |
|
|
b. 1 |
|
|
c. implementation defined |
|
|
d. undefined |
|
|
e. compiler error |
|
Incorrect
Marks for this submission: 0/1.
Question 23
Marks: 1
What header file contains C++ file I/O instructions?
Choose one answer.
|
a. iostream.h |
|
|
b. outstream.h |
|
|
c. file.h |
|
|
d. infstream.h |
|
|
e. fstream.h |
|
Incorrect
Marks for this submission: 0/1.
Question 24
Marks: 1
What is the output of the program?
#include <iostream>
struct BS { unsigned int color; };
struct car : public BS { };
struct truck : public BS { };
struct city : public car, public truck { };
int main(int argc, char** argv) { city c;
c.color = 3;
std::cout << c.color << std::endl;
return 0; }
Choose one answer.
|
a. 0 |
|
|
b. 3 |
|
|
c. ill-formed |
|
Incorrect
Marks for this submission: 0/1.
Question 25
Marks: 1
The ________ enables access to a global variable with the same name as a variable in the current scope
Choose one answer.
|
a.
unary scope resolution operator (: |
|
|
b. name |
|
|
c. local |
|
|
d. register |
|
|
e. var |
|
Incorrect
Marks for this submission: 0/1.
Question 26
Marks: 1
Identify and correct the errors in the following statement (assume that the statement using std::cout; is used): if ( c => 7 ) cout << "c is equal to or greater than 7\n";
Choose at least one answer.
|
a. if ( c !> 7 ) cout << "c is equal to or greater than 7\n"; |
|
|
b. if ( c >> 7 ) cout << "c is equal to or greater than 7\n"; |
|
|
c. if ( c = 7 ) cout << "c is equal to or greater than 7\n"; |
|
|
d. if ( c >< 7 ) cout << "c is equal to or greater than 7\n"; |
|
|
e. if ( c >= 7 ) cout << "c is equal to or greater than 7\n"; |
|
Correct
Marks for this submission: 1/1.
Question 27
Marks: 1
Which conversion is not possible?
Choose one answer.
|
a. All are possible |
|
|
b. float to int |
|
|
c. double to float |
|
|
d. int to float |
|
|
e. char to float |
|
Incorrect
Marks for this submission: 0/1.
Question 28
Marks: 1
The ________ qualifier is used to declare read-only variables
Choose one answer.
|
a. read |
|
|
b. read-only |
|
|
c. const |
|
|
d. static |
|
|
e. unchangeable |
|
Incorrect
Marks for this submission: 0/1.
Question 29
Marks: 1
What is the maximum number of implicitly defined constructors that this struct will have?
struct A { A(A& a) { } A(double d) {} int val; };
Choose one answer.
|
a. 2 |
|
|
b. 0 |
|
|
c. implementation specified |
|
|
d. 1 |
|
Incorrect
Marks for this submission: 0/1.
Question 30
Marks: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign the address of variable number1 to pointer variable fPtr.
Choose one answer.
|
a. fPtr = *number1; |
|
|
b. fPtr = &number1; |
|
|
c. *fPtr = number1; |
|
|
d. fPtr = *&number1; |
|
Correct
Marks for this submission: 1/1.
Question 31
Marks: 1
Write a program segment to print the values of each element of array table in tabular format with 3 rows and 3 columns. Assume that the array was initialized with the declaration int table[ arraySize ][ arraySize ] = { { 1, 8 }, { 2, 4, 6 }, { 5 } }; and the integer variables i and j are declared as control variables.
Choose one answer.
|
a. cout << " [0] [1] [2]" << endl; for ( i = 0; i < arraySize; i++ ) { cout << '[' << i << "] "; for ( j = 0; j < arraySize; j++ ) cout << setw( 3 ) << table[ i ][ j ] << " "; cout << endl; |
|
|
b. cout << " [0] [1] [2]" << endl; for ( int i = 0; i < arraySize; i++ ) { cout << '[' << i << "] "; for ( int j = 0; j < arraySize; j++ ) cout << setw( 3 ) << table[ i ][ i ] << " "; cout << endl; |
|
|
c. cout << " [0] [1] [2]" << endl; for ( int i = 0; i < arraySize; i++ ) { cout << '[' << i << "] "; for ( int j = 0; j < arraySize; j++ ) cout << setw( 3 ) << table[ i ][ j ] << " "; cout << endl; |
|
Incorrect
Marks for this submission: 0/1.
Question 32
Marks: 1
All arguments to function calls in C++ are passed by value
Answer:
True False
Correct
Marks for this submission: 1/1.
Question 33
Marks: 1
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
char *a = "final exam";
cout << a+6;
return 0;
}
Choose one answer.
|
a. whitespace |
|
|
b. exam |
|
|
c. ASCII code of 'e' |
|
|
d. e |
|
|
e. address of a[6] |
|
Incorrect
Marks for this submission: 0/1.
Question 34
Marks: 1
Write single C++ statements that input integer variable x with cin and >>
Answer:
Correct
Marks for this submission: 1/1.
Question 35
Marks: 1
Output the address of the variable myString of type char *
Choose one answer.
|
a. cout << static_cast< void >( myString ); |
|
|
b. cout << void * ( myString ); |
|
|
c. cout << static_cast< void * >( myString ); |
|
Incorrect
Marks for this submission: 0/1.
Question 36
Marks: 1
Does the following code pass the parameters to the function swap2 by reference? #include <iostream> using namespace std; void swap2(int a ,int b ){ int temp = a; a = b; b = temp; } int main(){ int a = 5 ,b = 7; swap2(a,b); cout << a << " " << b; return 0; }
Answer:
True False
Incorrect
Marks for this submission: 0/1.
Question 37
Marks: 1
Find the error(s) in the following code segment. The following code should print the values 1 to 10: n = 1; while ( n < 10 )
cout << n++ << endl;
Choose one answer.
|
a. n = 1; while ( n <= 10 ) cout << ++n << endl;
|
|
|
b. n = 1; while ( n <=11 ) cout << n++ << endl; |
|
|
c. n = 1; while ( n < 11 ) cout << n++ << endl; |
|
Incorrect
Marks for this submission: 0/1.
Question 38
Marks: 1
An individual array element that is passed to a function and modified in that function will contain the modified value when the called function completes execution
Answer:
True False
Incorrect
Marks for this submission: 0/1.
Question 39
Marks: 1
Which one is correct?
Choose one answer.
|
a. int a; a = new int(20); |
|
|
b. int *a; a new int[20]; |
|
|
c. int *a; a = new sizeof(int*20); |
|
|
d. int *a; a = new 20; |
|
|
e. int a; a = new int[20]; |
|
|
f. int a; a = new sizeof(int*20); |
|
Incorrect
Marks for this submission: 0/1.
Question 40
Marks: 1
What will be the results of “54 << 3"?
Choose one answer.
|
a. I don’t know |
|
|
b. 623 |
|
|
c. 556 |
|
|
d. None of these |
|
|
e. 523 |
|
Correct
Marks for this submission: 1/1.
Close this window
Midterm II
Review of attempt 1
Close this window
Started on |
Wednesday, 8 December 2010, 04:58 PM |
Completed on |
Wednesday, 8 December 2010, 05:46 PM |
Time taken |
48 mins 2 secs |
Marks |
29/40 |
Grade |
72.5 out of a maximum of 100 (73%) |
Question 1
Marks: 1
Write a program segment to print the values of each element of array table in tabular format with 3 rows and 3 columns. Assume that the array was initialized with the declaration int table[ arraySize ][ arraySize ] = { { 1, 8 }, { 2, 4, 6 }, { 5 } }; and the integer variables i and j are declared as control variables.
Choose one answer.
|
a. cout << " [0] [1] [2]" << endl; for ( int i = 0; i < arraySize; i++ ) { cout << '[' << i << "] "; for ( int j = 0; j < arraySize; j++ ) cout << setw( 3 ) << table[ i ][ i ] << " "; cout << endl; |
|
|
b. cout << " [0] [1] [2]" << endl; for ( int i = 0; i < arraySize; i++ ) { cout << '[' << i << "] "; for ( int j = 0; j < arraySize; j++ ) cout << setw( 3 ) << table[ i ][ j ] << " "; cout << endl; |
|
|
c. cout << " [0] [1] [2]" << endl; for ( i = 0; i < arraySize; i++ ) { cout << '[' << i << "] "; for ( j = 0; j < arraySize; j++ ) cout << setw( 3 ) << table[ i ][ j ] << " "; cout << endl; |
|
Correct
Marks for this submission: 1/1.
Question 2
Marks: 1
What will be at output? #include <iostream> using namespace std; int main() { int a = 5; a = *&*&*&*&a; cout << a << "\n"; return 0; }
Choose one answer.
|
a. 5 0x22ff74 |
|
|
b. 0x22ff78 |
|
|
c. 6 |
|
|
d. 5 |
|
Correct
Marks for this submission: 1/1.
Question 3
Marks: 1
Output the value pointed to by floatPtr of type float *.
Choose one answer.
|
a. cout << &floatPtr; |
|
|
b. cout << floatPtr; |
|
|
c. cout << *floatPtr; |
|
Correct
Marks for this submission: 1/1.
Question 4
Marks: 1
Find the error in the following program segment and correct the error:
arraySize = 10; // arraySize was declared const
Choose one answer.
|
a. const int arraySize; arraySize =10; |
|
|
b. const int arraySize=10; |
|
|
c. no errors |
|
Correct
Marks for this submission: 1/1.
Question 5
Marks: 1
Select the best answer to the output of the program:
#include<iostream>
usingnamespace std;
int main() {
double y = 10;
double *x = &y;
cout << x << " " << x-1 << " " << *x-1 << endl;
return 0;
}
Choose one answer.
|
a. 002BF7E0 002BF7E8 9 |
|
|
b. 002BF7EC 002BF7E8 9 |
|
|
c. 002BF7E0 002BF7D8 9 |
|
|
d. 10 9 002BF7E0 |
|
|
e. None of the given choices. |
|
Incorrect
Marks for this submission: 0/1.
Question 6
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 7
Marks: 1
What will !((1 || 0) && 0) evaluate to?
Choose one answer.
|
a. 0 |
|
|
b. 1 |
|
|
c. I don't know |
|
|
d. Undefined behaviour |
|
|
e. Wrong code |
|
Correct
Marks for this submission: 1/1.
Question 8
Marks: 1
What (if anything) prints when the following statement is performed?Assume the following variable declarations: char s1[ 50 ] = "jack"; char s2[ 50 ] = "jill"; char s3[ 50 ]; cout << strcpy( s3, s2 ) << endl;
Choose one answer.
|
a. jill (50 times) |
|
|
b. jill |
|
|
c. nothing |
|
|
d. no ideas |
|
Incorrect
Marks for this submission: 0/1.
Question 9
Marks: 1
What is required to avoid falling through from one case to the next?
Choose one answer.
|
a. break; |
|
|
b. continue; |
|
|
c. end; |
|
|
d. A semicolon. |
|
|
e. Stop; |
|
Correct
Marks for this submission: 1/1.
Question 10
Marks: 1
If we have this code:
class A { public: int a; }; A *obj;
How do we access the “a” variable?
Choose one answer.
|
a. obj::a |
|
|
b. obj-a |
|
|
c. I don’t know |
|
|
d. obj->a |
|
|
e. obj.a |
|
Correct
Marks for this submission: 1/1.
Question 11
Marks: 1
What value gets printed by the program?
#include <iostream>
int foo(int x, int y = x) { return x+y+1; }
int main(int argc, char** argv) { std::cout << foo(2) << std::endl; return 0; }
Choose one answer.
|
a. 1 |
|
|
b. 3 |
|
|
c. 5 |
|
|
d. ill-formed |
|
Incorrect
Marks for this submission: 0/1.
Question 12
Marks: 1
What value should be printed for x? #include <iostream> int main() { int x = int() = 3; std::cout << x << std::endl; return 0; }
Choose one answer.
|
a. won't compile |
|
|
b. 0 |
|
|
c. undefined |
|
|
d. -858993460 |
|
|
e. 3 |
|
Correct
Marks for this submission: 1/1.
Question 13
Marks: 1
What header file contains C++ file I/O instructions?
Choose one answer.
|
a. iostream.h |
|
|
b. file.h |
|
|
c. fstream.h |
|
|
d. infstream.h |
|
|
e. outstream.h |
|
Incorrect
Marks for this submission: 0/1.
Question 14
Marks: 1
Calculate the remainder after q is divided by divisor and assign the result to q. Write this statement two different ways.
Choose at least one answer.
|
a. q *= divisor; |
|
|
b. q -= divisor/q; |
|
|
c. q = q – divisor/q; |
|
|
d. q = q / divisor; |
|
|
e. q /= divisor; |
|
|
f. q = q * divisor; |
|
|
g. q %= divisor; |
|
|
h. q = q % divisor; |
|
Correct
Marks for this submission: 1/1.
Question 15
Marks: 1
Correct the mistakes
float a, b, c;
cin << a,b,c;
Choose one answer.
|
a. cin >> a >> b >> c; |
|
|
b. cin >> a,b,c; |
|
|
c. cin << a; b; c; |
|
|
d. cin << a,b,c; |
|
|
e. cin >> a; b; c; |
|
Correct
Marks for this submission: 1/1.
Question 16
Marks: 1
The keyword
is
used in a function header to indicate that a function does not return
a value or to indicate that a function contains no parameters
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
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. 12345 |
|
|
b. 2345 |
|
|
c. 23456 |
|
|
d. 123456 |
|
|
e. 1234 |
|
Correct
Marks for this submission: 1/1.
Question 19
Marks: 1
What value gets printed by the program? #include <iostream> int main(int argc, char** argv) { int x; x = 1, 2, 3; std::cout << x << std::endl; return 0; }
Choose one answer.
|
a. 2 |
|
|
b. undefined |
|
|
c. 6 |
|
|
d. 1 |
|
|
e. 3 |
|
Correct
Marks for this submission: 1/1.
Question 20
Marks: 1
Which properly declares a variable of struct foo?
Choose one answer.
|
a. foo var; |
|
|
b. int foo; |
|
|
c. foo; |
|
|
d. struct foo; |
|
|
e. var foo; |
|
Incorrect
Marks for this submission: 0/1.
Question 21
Marks: 1
Give the function header for the following function. Function hypotenuse that takes two double-precision, floating-point arguments, side1 and side2, and returns a double-precision, floating-point result.
Choose one answer.
|
a. float hypotenuse( double side1, double side2) |
|
|
b. double float hypotenuse( double float side1, double float side2) |
|
|
c. not sure |
|
|
d. double hypotenuse( double side1, double side2) |
|
|
e. float hypotenuse( float side1, float side2) |
|
Correct
Marks for this submission: 1/1.
Question 22
Marks: 1
The ostream member function ___________ is used to perform unformatted output
Choose one answer.
|
a. write |
|
|
b. read |
|
|
c. cout |
|
|
d. cin |
|
Correct
Marks for this submission: 1/1.
Question 23
Marks: 1
Which of the following shows the correct syntax for an if statement?
Choose one answer.
|
a. if expression |
|
|
b. if{ expression |
|
|
c. if [expression] |
|
|
d. expression if |
|
|
e. if( expression) |
|
Correct
Marks for this submission: 1/1.
Question 24
Marks: 1
Which properly declares a variable of struct foo?
Choose one answer.
|
a. struct foo; |
|
|
b. int foo; |
|
|
c. foo var; |
|
|
d. var foo; |
|
|
e. foo; |
|
Incorrect
Marks for this submission: 0/1.
Question 25
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.
Question 26
Marks: 1
Write two separate statements that each assign the starting address of array numbers to the pointer variable nPtr.
Choose one answer.
|
a. nPtr = &numbers; nPtr = numbers[ 0 ]; |
|
|
b. nPtr = numbers; nPtr = &numbers[ 0 ]; |
|
|
c. nPtr = *numbers; nPtr = &numbers[ 0 ]; |
|
Incorrect
Marks for this submission: 0/1.
Question 27
Marks: 1
An array that uses two subscripts is referred to as a _________ array
Choose one answer.
|
a. double array |
|
|
b. two-dimensional |
|
|
c. multi-dimensional |
|
|
d. no ideas |
|
Correct
Marks for this submission: 1/1.
Question 28
Marks: 1
What is the output of the program?
#include <iostream> using namespace std; int main() { for (int a=10; a<91; a*=3) cout << a-1 << " "; cout << endl; return 0; }
Choose one answer.
|
a. 9 29 |
|
|
b. 10 30 90 |
|
|
c. 9 29 89 |
|
|
d. 10 30 90 270 |
|
|
e. 10 30 |
|
Correct
Marks for this submission: 1/1.
Question 29
Marks: 1
Where can you put a continue statement?
Choose one answer.
|
a. In a nested loop |
|
|
b. In or as a loop body |
|
|
c. Inside a function |
|
|
d. Everywhere in the program |
|
|
e. I don’t know |
|
Correct
Marks for this submission: 1/1.
Question 30
Marks: 1
Correct mistake in the statement below:
#include<iosteam>
Choose one answer.
|
a. #include < iosrteam > |
|
|
b. #include < iostream > |
|
|
c. #include < iostraem > |
|
|
d. #include < iosteaem > |
|
|
e. #include < iosteram > |
|
Correct
Marks for this submission: 1/1.
Question 31
Marks: 1
Output the string "Enter your name: "
Choose one answer.
|
a. cout >> "Enter your name: "; |
|
|
b. cout << "Enter your name: "; |
|
|
c. cin << "Enter your name: "; |
|
Correct
Marks for this submission: 1/1.
Question 32
Marks: 1
Which of the following lines should NOT compile? 1 2 int main() 3 { 4 int a[54] = {}; 5 6 int b[54] = {}; 7 8 int* x = a; 9 10 int* const y = a; 11 12 b = x; 13 14 b = y; 15 16 return 0; 17 }
Choose one answer.
|
a. 8, 10, 12, 14 |
|
|
b. 8, 12 |
|
|
c. 12, 14 |
|
|
d. 14 |
|
|
e. none |
|
Incorrect
Marks for this submission: 0/1.
Question 33
Marks: 1
What is the maximum number of implicitly defined constructors that this struct will have?
struct A { A(A& a) { } A(double d) {} int val; };
Choose one answer.
|
a. 2 |
|
|
b. 1 |
|
|
c. implementation specified |
|
|
d. 0 |
|
Incorrect
Marks for this submission: 0/1.
Question 34
Marks: 1
What value gets printed by the program? #include <iostream> struct Foo { Foo(int d) : x(d) {} int x; }; int main() { double x = 3.14; Foo f( int(x) ); std::cout << f.x << std::endl; return 0; }
Choose one answer.
|
a. 3.14 |
|
|
b. 3 |
|
|
c. 0 |
|
|
d. implementation-defined |
|
|
e. nothing, its ill-formed |
|
Incorrect
Marks for this submission: 0/1.
Question 35
Marks: 1
Find the error in the following program segment: void product( void ) { 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; }
Choose one answer.
|
a. No idea |
|
|
b. void product( void ) { int a; int b; int c; int result; cout << "Enter three integers: "; cin >> a >> b >> c; result = a * b * c; cout << "Result is " << result; } |
|
|
c. All variants are correct |
|
|
d. void product( void ) { 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 void; } |
|
|
e. void product( void ) { 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 product; } |
|
Correct
Marks for this submission: 1/1.
Question 36
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 37
Marks: 1
A variable that is known only within the function in which it is defined is called a ________.
Choose one answer.
|
a. global variable |
|
|
b. class variable |
|
|
c. local variable |
|
|
d. static variable |
|
|
e. temporary variable |
|
Correct
Marks for this submission: 1/1.
Question 38
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 }; if ( strcmp( string1, string2 ) ) cout << "The strings are equal" << endl;
Choose one answer.
|
a. no errors |
|
|
b. if ( strcmp( string1, string2 ) != 0) cout << "The strings are equal" << endl; |
|
|
c. if ( strcmp( string1, string2 ) == 0) cout << "The strings are equal" << endl;
|
|
Correct
Marks for this submission: 1/1.
Question 39
Marks: 1
In addition to c-style, which casts can be used to cast an int to a pointer or a pointer to an int?
Choose one answer.
|
a. static_cast or dynamic_cast |
|
|
b. none of the above |
|
|
c. reinterpret_cast |
|
|
d. static_cast |
|
|
e. dynamic_cast |
|
Incorrect
Marks for this submission: 0/1.
Question 40
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.
Close this window
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 |
49 mins 59 secs |
Marks |
18/40 |
Grade |
45 out of a maximum of 100 (45%) |
Question 1
Marks: 1
What value does size print out? #include <iostream> const int SIZE = 5; struct tester { int array[SIZE]; enum { SIZE = 3 }; void size() { std::cout << sizeof(array) / sizeof(int); } }; int main(int argc, char** argv) { tester t; t.size(); return 0; }
Choose one answer.
|
a. 3 |
|
|
b. undefined |
|
|
c. 8 |
|
|
d. 0 |
|
|
e. 5 |
|
Incorrect
Marks for this submission: 0/1.
Question 2
Marks: 1
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
int a = 1;
do {
a+=1;
cout << a;
} while (a<5);
return 0;
}
Choose one answer.
|
a. 23456 |
|
|
b. 123456 |
|
|
c. 2345 |
|
|
d. 12345 |
|
|
e. 1234 |
|
Incorrect
Marks for this submission: 0/1.
Question 3
Marks: 1
What is the output of the program?
#include <iostream>
struct BS { unsigned int color; };
struct car : public BS { };
struct truck : public BS { };
struct city : public car, public truck { };
int main(int argc, char** argv) { city c;
c.color = 3;
std::cout << c.color << std::endl;
return 0; }
Choose one answer.
|
a. 0 |
|
|
b. ill-formed |
|
|
c. 3 |
|
Incorrect
Marks for this submission: 0/1.
Question 4
Marks: 1
Which of the following correctly declares an array?
Choose one answer.
|
a. int anarray; |
|
|
b. array anarray[10]; |
|
|
c. int anarray[10]; |
|
|
d. int array[10]; |
|
|
e. anarray{10}; |
|
Incorrect
Marks for this submission: 0/1.
Question 5
Marks: 1
Add variable x to variable sum and assign the result to variable sum
Answer:
Incorrect
Marks for this submission: 0/1.
Question 6
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; |
|
Incorrect
Marks for this submission: 0/1.
Question 7
Marks: 1
What is the output of the program?
#include<iostream>
usingnamespace std;
int main() {
char *a = "international";
cout << a+5;
return 0;
}
Choose one answer.
|
a. ASCII code of 'n' |
|
|
b. national |
|
|
c. international5 |
|
|
d. n |
|
|
e. international |
|
Incorrect
Marks for this submission: 0/1.
Question 8
Marks: 1
Which of the following is the boolean operator for logical-and?
Choose one answer.
|
a. AND |
|
|
b. & |
|
|
c. |& |
|
|
d. | |
|
|
e. && |
|
Incorrect
Marks for this submission: 0/1.
Question 9
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 10
Marks: 1
Declare a pointer nPtr that points to a variable of type double
Choose one answer.
|
a. double nPtr; |
|
|
b. double *nPtr; |
|
|
c. double &nPtr; |
|
Correct
Marks for this submission: 1/1.
Question 11
Marks: 1
Every C++ program
begins execution at the function
?
Correct
Marks for this submission: 1/1.
Question 12
Marks: 1
Correct mistake in the program below:
int main {
cout << “anyonghaseyo” << endl;
return 0;
}
Choose one answer.
|
a. void main() { cout << “anyonghaseyo” << endl; return 0; } |
|
|
b. int main() { cout << “anyonghaseyo” << endl; } |
|
|
c. int main() { cout << “anyonghaseyo” << endl; return 0; }
|
|
|
d. int main { cout << “anyonghaseyo” << endl; return 0; } |
|
|
e. int main { cout << “anyonghaseyo” << endl; } |
|
Correct
Marks for this submission: 1/1.
Question 13
Marks: 1
This question has been deleted. Please contact your teacher
Question 14
Marks: 1
What is the output of the program? #include <iostream> using namespace std; int main() { int a = 5; do { cout << a; a--; } while (a>0); return 0; }
Choose one answer.
|
a. 4321 |
|
|
b. 543210 |
|
|
c. 1234 |
|
|
d. 12345 |
|
|
e. 54321 |
|
Incorrect
Marks for this submission: 0/1.
Question 15
Marks: 1
Why would you want to use inline functions?
Choose one answer.
|
a. To make your code more clear |
|
|
b. To remove unnecessary functions |
|
|
c. To increase the speed of the resulting program |
|
|
d. To decrease the size of the resulting program |
|
|
e. To simplify the source code file |
|
Correct
Marks for this submission: 1/1.
Question 16
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;
cout << *(x+3) << endl;
return 0;
}
Choose one answer.
|
a. 3 |
|
|
b. 8 |
|
|
c. 7 |
|
|
d. 002BF7E0 |
|
|
e. 9 |
|
Correct
Marks for this submission: 1/1.
Question 17
Marks: 1
Which of the following is true?
Choose one answer.
|
a. 1 |
|
|
b. -1 |
|
|
c. 66 |
|
|
d. All of the above |
|
|
e. .1 |
|
Correct
Marks for this submission: 1/1.
Question 18
Marks: 1
Which of the following is not a correct variable type?
Choose one answer.
|
a. real |
|
|
b. float |
|
|
c. char |
|
|
d. int |
|
|
e. double |
|
Correct
Marks for this submission: 1/1.
Question 19
Marks: 1
Which of the following is a valid function call (assuming the function exists)?
Choose one answer.
|
a. funct x, y; |
|
|
b. funct; |
|
|
c. int funct(); |
|
|
d. int funct(int); |
|
|
e. funct(); |
|
Correct
Marks for this submission: 1/1.
Question 20
Marks: 1
Which of the following classes handlers file input?
Choose one answer.
|
a. inputfile |
|
|
b. iomanip |
|
|
c. ofstream |
|
|
d. instream |
|
|
e. ifstream |
|
Incorrect
Marks for this submission: 0/1.
Question 21
Marks: 1
Header file __________ contains the declarations required for user-controlled file processing
Choose one answer.
|
a. <fstream> |
|
|
b. <iostream> |
|
|
c. <filestream> |
|
|
d. <file> |
|
Incorrect
Marks for this submission: 0/1.
Question 22
Marks: 1
Set variable sum to 0
Answer:
Incorrect
Marks for this submission: 0/1.
Question 23
Marks: 1
If the file-position pointer points to a location in a sequential file other than the beginning of the file, the file must be closed and reopened to read from the beginning of the file
Answer:
True False
Correct
Marks for this submission: 1/1.
Question 24
Marks: 1
The keyword __________ specifies that an object or variable is not modifiable after it is initialized
Choose one answer.
|
a. pointer |
|
|
b. global |
|
|
c. const |
|
|
d. static |
|
Correct
Marks for this submission: 1/1.
Question 25
Marks: 1
Which conversion is not possible?
Choose one answer.
|
a. int to float |
|
|
b. double to float |
|
|
c. float to int |
|
|
d. All are possible |
|
|
e. char to float |
|
Correct
Marks for this submission: 1/1.
Question 26
Marks: 1
Write one or more statements that perform the following task for and array called “fractions”. Assign the value 3.333 to the seventh element of the array
Choose one answer.
|
a. fractions( 6 ) = 3.333; |
|
|
b. fractions( 7 ) = 3.333; |
|
|
c. no ideas |
|
|
d. fractions[ 7 ] = 3.333; |
|
|
e. fractions[ 6 ] = 3.333; |
|
Incorrect
Marks for this submission: 0/1.
Question 27
Marks: 1
What value is printed out for the variable x? #include <iostream> int x; int main() { int y; std::cout << x << std::endl; std::cout << y << std::endl; return 0; }
Choose one answer.
|
a. undefined |
|
|
b. -858993460 |
|
|
c. 3 |
|
|
d. zero |
|
|
e. 2 |
|
Incorrect
Marks for this submission: 0/1.
Question 28
Marks: 1
What value gets printed by the program? #include <iostream> struct Foo { Foo(int d) : x(d) {} int x; }; int main() { double x = 3.14; Foo f( int(x) ); std::cout << f.x << std::endl; return 0; }
Choose one answer.
|
a. 0 |
|
|
b. implementation-defined |
|
|
c. 3 |
|
|
d. nothing, its ill-formed |
|
|
e. 3.14 |
|
Incorrect
Marks for this submission: 0/1.
Question 29
Marks: 1
Output to cerr is unbuffered and output to clog is buffered
Answer:
True False
Correct
Marks for this submission: 1/1.
Question 30
Marks: 1
Each parameter in a function header should specify both a and a .
Correct
Marks for this submission: 1/1.
Question 31
Marks: 1
Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Declare the variable fPtr to be a pointer to an object of type double.
Choose one answer.
|
a. double *&fPtr; |
|
|
b. double *fPtr; |
|
|
c. double &fPtr; |
|
Correct
Marks for this submission: 1/1.
Question 32
Marks: 1
The stream manipulators dec, oct and hex affect only the next integer output operation
Answer:
True False
Incorrect
Marks for this submission: 0/1.
Question 33
Marks: 1
A program must call function close explicitly to close a file associated with an ifstream, ofstream or fstream object.
Answer:
True False
Correct
Marks for this submission: 1/1.
Question 34
Marks: 1
What will be the result of: cout << (5 << 3); ?
Choose one answer.
|
a. Compiler error |
|
|
b. 53 |
|
|
c. 40 |
|
|
d. I don t know |
|
|
e. 35 |
|
Incorrect
Marks for this submission: 0/1.
Question 35
Marks: 1
Output the value pointed to by floatPtr of type float *.
Choose one answer.
|
a. cout << *floatPtr; |
|
|
b. cout << floatPtr; |
|
|
c. cout << &floatPtr; |
|
Correct
Marks for this submission: 1/1.
Question 36
Marks: 1
A __________ should be used to declare the size of an array, because it makes the program more scalable
Choose one answer.
|
a. number |
|
|
b. constant variable |
|
|
c. constant |
|
|
d. static variable |
|
Incorrect
Marks for this submission: 0/1.
Question 37
Marks: 1
Input operations are supported by class __________.
Choose one answer.
|
a. istream |
|
|
b. fstream |
|
|
c. sinput |
|
|
d. ifile |
|
Correct
Marks for this submission: 1/1.
Question 38
Marks: 1
What character ends all strings?
Choose one answer.
|
a. '.' |
|
|
b. ' ' |
|
|
c. '\n' |
|
|
d. ; |
|
|
e. '\0' |
|
Incorrect
Marks for this submission: 0/1.
Question 39
Marks: 1
Which is not a loop structure?
Choose one answer.
|
a. FOR |
|
|
b. for |
|
|
c. do while |
|
|
d. while |
|
|
e. Repeat Until |
|
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 n = 1; while (n<=5) cout << ++n; return 0; }
Choose one answer.
|
a. 1234 |
|
|
b. 2345 |
|
|
c. 123456 |
|
|
d. 23456 |
|
|
e. 12345 |
|
Incorrect
Marks for this submission: 0/1.
Close this window
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
