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: @ 216.73.216.213

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

switch (a)
     {
     case 1: printf("TV is on.");

     case 2: printf("Stereo is on.");
         break;

     case 3: printf("Room lights dimmed.");
         break;

     default: printf("Say what?");
         break;
     }

a) TV is on.
b) TV is on. Stereo is on.
c) Room lights dimmed.
d) Say what?

2. A certain function has the following prototype:

float MyFunct(int x, float z);

Which statement below correctly calls this function? Assume that A and B are type INT, and C is type FLOAT.

a) MyFunct( a, b);
b) a = MyFunct( 0, a);
c) c = MyFunct( a, 1.41459 );
d) None of the above

3. 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

4. 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

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

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

MyFunct(x, y);

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

6. Given that A=25 and B=10, what will the output of the fragment below be?

if (a<20)
     printf("Too Small.");
     else
     if (b >= 10)
         printf("Everything is OK.");
         else
         printf("B is too small.");

a) Too Small.
b) B is too small.
c) Everything is OK.
d) None of the above

7. What will be in variable 'A' after executing the following code?

int a,b;

b = 24;
a = ++b + 10;

a) 34
b) 35
c) 33
d) None of the above

8. To print a FLOAT with a field width of 10 and 2 digits to the right of the decimal point, what PRINTF format specifier should be used?

a) "%8.2lf"
b) "%10.2f"
c) "%12.2d"
d) None of the above

9. In C, how is a logical OR indicated?

a) &&
b) ||
c) ++
d) None of the above

10. 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

11. The pointer value obtained from the 'FOPEN()' function (when used to open a disk file) is often referred to by programmers as a/an:

a) Array
b) Structure
c) Handle
d) None of the above

12. 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
b) lpStr.re
c) re
d) None of the above

13. 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

14. 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

15. 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

16. 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

17. What is a stream?

a) A path of communication between a program and the operating system
b) A method for writing to the video screen
c) A method for checking the contents of variables
d) None of the above

18. Why is it important to open a file in the binary mode when reading and writing in-memory contents such as structures?

a) To avoid undesired translation of certain memory content values
b) To allow automatic error checking of the file contents by the operating system
c) To minimize disk space requirements
d) None of the above

19. 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

20. What is a structure?

a) A user-defined data type that can contains aggregate data
b) A special type of C pointer that can not be dereferenced directly
c) Another name for a C program
d) None of these

21. Given the class definition:

Class CGeek
{
public:
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

22. 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

23. 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

24. 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

25. The functions that are part of Class objects are called the:

a) Data members
b) Elements
c) Methods
d) None of the above

26. 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

27. 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

28. What is the default access type for members of a class?

a) Public
b) Private
c) Protected
d) None of the above

29. The method of a class that is called automatically when objects of that class are instantiated is called the:

a) Constructor
b) Initializer
c) Destructor
d) None of the above

30. 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

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!