COMP270 Practice for Exam 2 -- OOPS, NEED TO UPDATE

Instructions: There are 30 questions on this test. It is written in a style very similar to the REAL exam 2. Choose the best answer from among those given. Click the GRADE button on the bottom of the form when you want the exam graded.

Note: You can practice this test as many times as you desire; the system will cook you up a fresh batch of questions each time you access this page.

Your Name: @

1. What is the data type of the following expression?

"The quick brown fox jumped over the lazy dog."

a) int*
b) double*
c) float*
d) char*
e) None of the above

2. What output will be produced by the DO loop below?

int i=2;

do  {
     if (i==7) continue;
     printf("%d", i);

a) 3 4 5 6 7 8 9
b) 2 3 4 5 6 7 8
c) 3 4 5 6 8 9 10
d) None of the above

3. What is wrong with the function below?

float MyFunct(int x, float z)
float x2;

x2 = z*z + x;

a) Function defined as type FLOAT but fails to return a value
b) A semicolon is required on the first line 'float MyFunct(int x, float z);'
c) The function is returning the wrong data type (INT)
d) None of the above

4. If A=4 upon entry into the code below, what will be output?

switch (a)
     case 1: printf("Unlocking door.");

     case 2: printf("Checking back door.");

     case 3: printf("Locking door.");

     default: printf("Unknown command.");

a) Checking back door
b) Unlocking door
c) Locking door
d) Unknown command

5. According to the way "MyFunct" is being used below, what is its prototype?

int x,y;
float z;
//Program logic to fill x and y with data here

z=MyFunct(x, y);

a) void MyFunct(int, int);
b) double MyFunct(double, int);
c) float MyFunct(int, int);
d) None of these

6. What will be the output of the following FOR loop?

for(i=0 ; i<5 ; i++)
     if (i==2) continue;
     printf("%d", i);

a) 1 2 3 4 5
b) 0 1 2 3 4
c) 0 1 3 4
d) None of the above

7. Which of these would be BEST to do before using a pointer to access memory?

a) Make sure sufficient memory exists to use the pointer.
b) Check to see if your C compiler supports pointers.
c) Make sure the pointer address is valid
d) None of these

8. What is object code?

a) Incomplete machine code
b) Instructions typed in by the programmer
c) The result of the C preprocessor's operation
d) None of the above

9. The data being manipulated by a program is also known as:

a) The objects
b) The algorithm
c) The flow
d) None of the above

10. What is the default data type returned by C functions?

a) int
b) float
c) void
d) None of the above

11. Given the following declaration:

struct Complex
    double re;
    double im;

double GetMagnitude(Complex* lpStr)

To access the member 're' within the function, what notation would be used?

a) lpStr->re
c) re
d) None of the above

12. If the character sequence CR-LF ('\r' '\n') is encountered while reading a text file, what character sequence will result on the C side of the interface?

a) '\r'
b) '\r' '\n'
c) '\0' (NUL)
d) None of the above

13. What must be done with any objects created through the 'NEW' operator prior to termination of a program?

a) The objects must be tested to see if they hold proper values
b) The objects must be tested with the 'OLD' operator
c) The objects must be deleted from memory
d) None of the above

14. Given the following declaration:

struct Complex
    double re;
    double im;

If a DOUBLE uses 8 memory locations, how much memory is used up?

a) 8 locations
b) 16 locations
c) 0 locations
d) None of these

15. Which of these is a disadvantage of passing structures to functions by value?

a) Two copies of the structure occupy memory during the function's execution
b) Copying the structure is a relatively slow process
c) The function can not modify the original values in the structure
d) All of the above

16. Which stream below is normally associated with the keyboard?

a) stdout
b) stderr
c) stdprn
d) stdaux
e) None of the above

17. Which standard stream below could be used to talk to a printer?

a) stdout
b) stdprn
c) stderr
d) stdaux
e) None of the above

18. What must be done with open files prior to ending a program?

a) Close them
b) Write the final information into them
c) Check their contents
d) None of the above

19. Which statement below would correctly allocate an array of 500 integers by using the 'NEW' operator?

a) int* Array = new int[500];
b) new int Array[500];
c) Array[500] = new int;
d) None of the above

20. What value is returned by the NEW operator when a memory allocation request fails?

a) -1
b) NULL pointer
c) 0xffff
d) None of the above

21. How does C++ discriminate between overloaded functions -- in other words, how does C++ know which version of an overloaded function to call?

a) By looking at the returned data type and comparing it with how the caller is using the function
b) By examining the parameter list and comparing it with the caller's parameters
c) By counting the number of times the function has been called
d) None of the above

22. Given the class definition:

Class CGeek
int m_nNeckties;
void TalkGibberish();

What is the correct prototype for the default constructor?

a) int Geek(char*);
b) void ~CGeek();
c) CGeek();
d) None of these

23. Suppose that the following memory allocation is performed:

Class CDonuts MyDonuts[100];

Which statement will execute the method TasteTest() in the sixth element of the array of objects?

a) TasteTest.MyDonuts[5];
b) MyDonuts[5].TasteTest();
c) CDonuts.TasteTest.MyDonuts(5);
d) None of the above

24. In what file would you find the definition (prototypes) for a class called CGhostBuster?

a) GhostBuster.h
b) GhostBuster.cpp
c) CGhostBuster.c
d) None of the above

25. What is the primary difference between objects defined with Class versus those defined with Struct?

a) The Class objects have active behaviors
b) The Struct objects have built-in data protection
c) There's no functional difference between them
d) None of the above

26. If a class member is defined as "private," who can access it?

a) Only functions within the same program
b) Any function within any process running on the computer
c) Only methods within the class itself
d) None of the above

27. Suppose that the following overloaded function prototypes are given:

A) void Homer(int, char, float);
B) int Homer(double);
C) float Homer(double, int, int, double);

Which version will be called by the program statement:

Homer(35,'A', 3.14159);

a) Version "A"
b) Version "B"
c) Version "C"
d) Insufficient information

28. Suppose that a function has the following prototype:

void DonutLove(int& nLamars );

How will the calling function be passing its value?

a) By reference (implied pointer)
b) By pointer (explicit pointer operation required)
c) By value
d) None of the above

29. What parameter passing method of C++ gives the advantage of passing values by pointer, yet avoids the use of pointer notation in both the calling and called functions?

a) Passing by value
b) Passing by reference
c) Passing by array
d) None of these

30. Which statement will correctly and dynamically allocate room for 13 (baker's dozen) CDonut objects?

a) CDonuts* NoSprinkles = new CDonuts[13];
b) CDonuts NoSprinkles[13];
c) NoSprinkles[13]->CDonuts[13];
d) None of the above

Extra information for Exam 1:

You will be asked to write two short programs. In one program, you will instantiate an array of objects of a predefined type, and call one or more methods of each object. In the second program, you will write the code to overload two of the built-in operators for objects of a class. Make sure you know and understand the "formulas" for overloading operators!

Grade Exam!