CS 1044 Quizzes - Fall 2000

Notice:  this website is best viewed with Internet Explorer version 5.0 or later.


Quizzes are given on a more-or-less random basis.  Missed quizzes may not be made up.

# Quiz Date

 

 

 

 

 

 

 

 

 

 

12

 

 

 

 

13

 

 

 

 

14

Given the declarations:

struct Book {

   string ISBN;

   string Title;

   string Author;

   int    Quantity;

};

Book DWH;

Book Lib[100];

 

Write statements to perform the indicated action:

 

Store the string "C++ for Dummies" in the appropriate field of the variable DWH.

 

DWH.Title = "C++ for Dummies";

 

Print the ISBN of the 20th Book in the array Lib to standard output.

 

cout << Lib[19].ISBN;

 

Swap the 17th and 36th Books in the array Lib.

 

Book Temp = Lib[16];

Lib[16] = Lib[35];

Lib[35] = Temp;

 

Nov 28

9

10

11

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5

 

 

 

6

 

 

 

7

 

 

8

Consider executing the following code:

 

int  a, b;            // line  1

bool x, y, z;         // line  2

a = _______;          // line  3

x = _______;          // line  4

y = _______;          // line  5

z = true;             // line  6

b =    0;             // line  7

 

while (a <= 10) {     // line  8

   while (x) {        // line  9

      if (y == z)   { // line 10

        b++;          // line 11

        _________;    // line 12

      }

      else

        x = !x;       // line 13

   }

   a++;               // line 14

}

 

With a initialized to 1, x initialized to true and y initialized to false:

How many times is line 14 executed?    10

How many times is line 11 executed?      0

 

With a initialized to 1, x initialized to true and y initialized to true:

How many times is line 14 executed?      0

How many times is line 11 executed?    infinitely many

 

With the same initializations as in 6, and changing line 12 to:  y = !y;

How many times is line 11 executed?      1

 

What initialization(s) would guarantee that lines 10 through 14 would never be executed?

a = 32;           Yes

a = -5;          No

x = false;    No

Oct 10

 

 

 

 

 

3

 

 

 

 

 

4

Consider reading an input file of the form:

1234567890

1234567890

1234567890

 

What is the value of x after execution of the following code?     890

int x;

char ch;

In.ignore(7, '\n');

In >> x;

 

What is the value of x after execution of the following code?       '8'

int x;

char ch;

In.ignore(10, '7');

In >> x;

 

 

?

2 How could the following statement be expressed using the increment operator:

NumValues = NumValues + 1;

Either of the following answers will do:  

NumValues++;    or             ++NumValues;

Note:  the following statements will also increment NumValues, but inefficiently and not really making proper use of the increment operator.

NumValues = NumValues++; 

NumValues = ++NumValues;

Sept 8

1

Determine whether each of the following is a valid identifier in C++:

b1tree         valid

my array       invalid (spaces are not allowed)

3peat          invalid (1st char can't be digit)

isEmpty        valid

Sept 5


Please send comments and suggestions to William McQuain at mcquain@cs.vt.edu.