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

 

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

Marks

27.33/40

Grade

68.33 out of a maximum of 100 (68%)

Question 1

Marks: 1

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.

Choose one answer.

a. cout << fractions[ 6 ] < < ' ' fractions[ 9 ] << endl;

b. cout << fixed; cout << fractions[ 6 ] < < fractions[ 9 ] << endl;

c. no ideas

d. cout << fixed << setprecision ( 2 ); cout << fractions[ 6 ] < < ' ' fractions[ 9 ] << endl;

Correct

Marks for this submission: 1/1.

Question 2

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. nothing

b. jill

c. no ideas

d. jill (50 times)

Correct

Marks for this submission: 1/1.

Question 3

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. 123456

c. 2345

d. 12345

e. 23456

Correct

Marks for this submission: 1/1.

Question 4

Marks: 1

In one statement, assign the sum of the current value of X and y to z and postincrement the value of X:

Choose one answer.

a. z=++x +y;

b. z = x++ + y;

c. z=x++y;

d. z=x+y++;

e. x++; z=x+y;

Correct

Marks for this submission: 1/1.

Question 5

Marks: 1

What purpose do classes serve?

Choose one answer.

a. simplifying code reuse

b. all of the these

c. code inheritance

d. providing a convenient way of modeling real-world objects

e. data encapsulation

Correct

Marks for this submission: 1/1.

Question 6

Marks: 1

What will output? #include <iostream> using namespace std; int main() { int i; int j; i = 10; j = 100; if (j > 0) { int i; i = j / 2; cout << i << " "; } cout << i << "\n"; return 0; }

Choose one answer.

a. 61 10

b. 50 10

c. 50 11

d. 51 11

Correct

Marks for this submission: 1/1.

Question 7

Marks: 1

Use a stream manipulator that causes the exponent in scientific notation and the letters in hexadecimal values to print in capital letters

Choose one answer.

a. cout << uppercase;

b. cout >> uppercase;

c. cin>>uppercase;

Correct

Marks for this submission: 1/1.

Question 8

Marks: 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.

Correct

Marks for this submission: 1/1.

Question 9

Marks: 1

Correct mistake in the program below:

Int main {

 cout << “anyonghaseyo” << endl;

 return 0;

}

Choose one answer.

a.

int main() {

 cout << “anyonghaseyo” << endl;

}

b.

int main {

 cout << “anyonghaseyo” << endl;

 return 0;

}

c.

int main() {

 cout << “anyonghaseyo” << endl;

 return 0;

}

d.

int main {

 cout << “anyonghaseyo” << endl;

}

e.

void main() {

 cout << “anyonghaseyo” << endl;

 return 0;

}

Correct

Marks for this submission: 1/1.

Question 10

Marks: 1

The three values that can be used to initialize a pointer are_____________,__________ and___________.

Choose one answer.

a. 6, 8, 10

b. 0, NULL, an address

c. no ideas

d. value, name, number

e. null, nil, 0

Correct

Marks for this submission: 1/1.

Question 11

Marks: 1

What does the program below output?

#include<iostream>

usingnamespace std;

int main() {

 int a[6] = {3,5,1,6,8,2};

 int result = 1;

 for (int i=0; i<6; i++)

 result *= a[i];

 cout << result << endl;

 return 0;

}

Choose one answer.

a. 25

b. 1440

c. 8

d. 0

e. None of the given choices.

Incorrect

Marks for this submission: 0/1.

Question 12

Marks: 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.]

Choose one answer.

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++;

}

Correct

Marks for this submission: 1/1.

Question 13

Marks: 1

Find the error in the following program segment:

int g( void) { cout << "Inside function g" << endl; int h( void ) { cout << "Inside function h" << endl; } }

Choose one answer.

a. int g( void) { cout << "Inside function g" << endl; } int h( void ) { cout << "Inside function h" << endl; }

b. not sure

c. all variants are correct

d. int h( void) { cout << "Inside function h" << endl; int g( void ) { cout << "Inside function g" << endl; } }

e. int g( void) { cout << "Inside function g" << endl; extern int h( void ) { cout << "Inside function h" << endl; } }

Correct

Marks for this submission: 1/1.

Question 14

Marks: 1

Which of the following is not a valid ofstream argument?

Choose one answer.

a. ios::trunc

b. ios::create

c. ios::out

d. ios::noreplace

e. ios::app

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