Computer Science 151
Programming Fundamentals

Quiz #1




Name: _________________________

SSN: __________________________
 

Answer all questions, you may wish to skip difficult questions, so that you may work on other easier questions first, and come back to the more difficult ones.  Your answers must be in english, and readable.  Where appropriate, circle the letter of the answer of your choice.

1. There are several native types of variables in C++.  Each of these types of variables has a certain size, as gone over in class.  Assuming that they are unsigned variables fill in the table below by writing the number of bytes taken by each, and what the corresponding maximum value is, leaving this answer in exponential form is expected.

 
Type # of Bytes Maximum Value

float

int

char

double

short
2. What are the types of the following:  (i.e. 0 = _int_)

    'a' = _______________________

    9.0 = _______________________

    7.3f= _____________________

    178392= ___________________

3. What is the output of the following program: (assume that this code is within main, and all appropriate code which is not shown is correct)
 
 

{

  string str = "Keith";
  int m = 4;
  int n = 5;

  if (n - m > 3) {
     cout << "Hello " << str << endl;
  } else if (n + m < 15) {
     cout << "Welcome to CS151, " << str << endl;
  } else {
     cout << "Goodbye " << str << endl;

  return 0;
}

                                                      Program 1
 
 

Circle the letter of the correct output.  All of the lines below are assumed to have newlines at the end of them.

a. Hello Keith
b. Welcome to CS151, Keith
c. Goodbye Keith
d. none of the above

 
 
 
 
 
 
 
 
 
 
 

4.  For program 1, from problem 3, previous page, draw a flow chart of the progress of the program.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

5.  Fill in the program below to ask for a user's name and then output a message ("Welcome to CS151, " <what the user's name is>).
 

#include <iostream>
#include <string>
using namespace std;

int main() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

  return 0;
}