Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Akmaral c++.docx
Скачиваний:
20
Добавлен:
25.02.2016
Размер:
201.76 Кб
Скачать

 

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

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]