CSCI 240 Sample Final Exam

The following are examples of the types of questions that may appear on the final exam. The posted quiz questions are also another good place to find example questions.

Beginning Material -- material through the midterm exam

  1. What is wrong with the following definition for a C-style symbolic constant called PI?

  2. #define PI = 3.24159
    1. The actual value of the mathematical constant pi is not 3.24159
    2. There should be a semi-colon at the end of the line
    3. There should not be an equal sign
    4. The name PI is a reserved word and therefore cannot be used
    5. There is nothing wrong with the definition

  3. Which of the following is a condition that will test if the value in the integer variable num is even?

    1. (num % 2) == 0
    2. (num / 2) == 0
    3. (num % 2) == 1
    4. (num / 2) == 1
    5. none of the above

  4. Which of the following (a-c) is a control structure?

    1. sequence structure
    2. repetition structure
    3. decision structure
    4. all of the above are control structures
    5. none of the above are control structures

  5. How many times will the following while loop print "hello"?

  6. int i = 1;
      
    while( i <= 10 )
      cout << "hello"
    1. 10
    2. 8
    3. an infinite number of times
    4. 0

  7. A function prototype does not have to __________.

    1. include argument names
    2. end with a semi-colon
    3. agree with the function header
    4. match with all calls of the function

  8. What will be displayed by the following code?

  9. int main()
      {
      int num = 3;
      
      fn(num);
      cout << num;
      
      return 0;
      }
      
      
    void fn( int n )
      {
      n++;
      }
    1. The code will not display anything
    2. 3
    3. 4
    4. 5
    5. There is not enough information provided to determine what will be displayed.

Arrays

  1. What is the subscript of the last element in the array Table if it is defined as follows?

  2. float Table[30];
    1. 30
    2. 31
    3. 29
    4. 0
    5. none of the above

  3. Which of the following statements (a-d) about Table is true?

  4. float Table[] = { 0.9, 0.8, 0.7, 0.6 };
    1. The definition for Table will cause an error because there is no value specified inside of the square brackets
    2. Table[1] contains the value 0.9
    3. There are actually 5 values stored in Table - the four listed and a null terminator as the fifth element
    4. The definition for Table will cause an error because an array cannot be initialized when it is created
    5. All of the statement (a-d) are false

  5. Which of the following "chunks" of C++ code will print the contents of an array called ar that has been defined to hold 25 integer values and has been initialized with 25 integer values?

  6. int i;
    1. cout << ar[];
    2. for( i = 0; i == 25; i++ )
        cout << ar[i] << " ";
    3. for( i = 0; i < 25; i++ )
        cout << ar[i] << " ";
    4. for( i = 0; i < 25; i++ );
        cout << ar[i] << " ";

  7. The following is a valid array definition.

  8. int ar[];
    1. true
    2. false

  9. What will be displayed by the following code?

  10. int main()
      {
      int num[5] = { 2, 4, 6, 8, 10 };
      int i;
      
      fn(num);
      
      for( i = 0; i < 5; i++ )
        cout << num[i] << ' ';
      
      return 0;
      }
      
      
    int fn( int n[] )
      {
      n[3] = n[3] + 1;
      }
    1. The code will not display anything
    2. 2 4 6 8 10
    3. 2 4 7 8 10
    4. 2 4 6 9 10
    5. There is not enough information provided to determine what will be displayed.

References

  1. Which of the following statements (a-d) are true if the following lines of code are executed?

  2. int G = 17;
    int &H = G;
    1. H is now an alternate name for G
    2. Adding 1 to H will change the value of G to 18
    3. Subtracting 5 from G and printing H will display the value 12
    4. The condition H == G will give a true result
    5. All of the statements (a-d) are true

  3. Which of the following is the correct definition for a variable called dblRef that can hold a reference to the double variable dblNum?

    1. double dblRef = dblNum;
    2. double *dblRef = &dblNum;
    3. double &dblRef = dblNum;
    4. double &dblRef;

C++ Strings & string functions

  1. The null terminator is __________.

    1. used to advance to a new line when executing a cout statement
    2. represented as '\0'
    3. used to end a valid string
    4. a movie starring Arnold Schwarzenegger
    5. All of the statements (a-d) are correct
    6. Only statements b and c are correct

  2. Which of the following string functions will ALWAYS produce a valid string after execution?

    1. strcpy
    2. strcat
    3. Both of the functions (a-b) will produce a valid string

  3. If a string will need room for 25 characters, how should it be defined so that it will be a valid string?

    1. char str[25];
    2. char str[24];
    3. char str[26];
    4. char str[];

Object Oriented Programming

  1. Which of the following statements (a-d) about classes is true?

    1. A class can contain both data members and methods
    2. The members of a class may be private or public
    3. The name of the constructor is always the same as the name of the class
    4. The class definition contains prototype statements for the methods
    5. All of the statements (a-d) are true.

  2. The :: operator is used to associate a method with a specific class.

    1. true
    2. false

  3. An instance of a class is known as a/an __________.

    1. variable
    2. method
    3. object
    4. thing

  4. The class X contains two data members: an integer called xVal and a float called xPerc. Which of the following is not a valid prototype for the class definition for X?

    1. void X( int, float );
    2. void setxVal( int );
    3. float getxPerc();
    4. X( int, float );
    5. void printX();