CS 31 – Dis 3C – Fall 08                                                                          Quiz 1
 
Grade yourself: ____________                                       Name: ___________________________
 
 
I. True False: (Explanation required)

 

1.      In C++ the variables Alpha, ALPHA and AlphA are the same identifier.

 

2.      C++ uses only /* */ for comments.

 

3.      A program should have a comment on every line.

 
 
II. Multiple Choice (Many can be correct)
 

1.      In C++, some of the following are legal identifiers. Which? Why?

a)           9xyz

b)           Xyz

c)           X+yz

d)           xy_z

e)           xyz!

 

2.      Pick the C++ keywords out of the following list.

a)           while

b)           total_weight

c)           double

d)           if

e)           number_of_bars

 

3.      Before a variable in C++ is used, it must be

a)           defined

b)           initialized

c)           used in some expression

d)           begin with a capital letter

e)           contain only letters, digits and underscores.

 

4.      In C++, a variable that has been defined but not initialized may

a)           be used in any way any identifier can be used.

b)           not be used at all

c)           have its value fetched prior to assignment.

 

5.      Which of the following are legal definitions with initializations? (Consider each line to be in a different scope so there is no multiple definition of identifiers.)

a)           int count = 0, limit = 19;

b)           int count(0), limit(19);

c)           int count = 0, limit(19);

d)           int limit = 19;

e)           int namespace(0);

 

6.      Which of the following names might give the human reader some hint about the data that is stored in them?

a)           aa, bb, cc

b)           speed, distance, time

c)           hypotenuse, leg1, leg2

d)           v1, v2, v3

e)           principal, interest, payment

 

7.      The value of the expression  20.0 * (9/5) + 32.0 is

a)           68.0

b)           52.0

c)           incorrect expression so there is no value

d)           32.0

e)           incorrect expression , the / should be %

 

 

III. Free Form Questions:

 

1.      In C++, a legal identifiers may contain these kinds of characters __________, _________, _________

 

2.      Given the C++ output statements. What is the output of these lines of code? Explain.

cout << "If you have ";

cout << "a number\nof pods " << endl;

cout << "you can quit.";

cout << "\n";

 

3.      What does the line #include <iostream> do for your program?

 

4.      Write a C++ program that outputs "My first C++ program" and then outputs a new line.

 

5.      Write a short program that contains statements to output the values of a variable that you define but neither initialize nor assign. Discuss the output you get.

 

6.      What is the difference between a warning from the compiler and an error message from the compiler?

 

7.      What is the difference between a compile-time error and run-time error? When does each of them occur?

 

8.      What is the value assigned to the variable in each of these cases? Explain curious results. Be careful!

int x, y;

x = 1/2;

y = 3.0/2.0;

double z, w, t;

z = 1/2;

w = 3/2;

t = 3.0/2.0;