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

1. In C, a logical AND is indicated by what operator?

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

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

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

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

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

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

     default: printf("Unknown command.");
         break;
     }

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

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

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

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

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

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

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

int a,b;

b = 24;
a = b++;

a) 24
b) 25
c) 23
d) None of the above

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

9. Every C statement ends with what character?

a) ','
b) '*'
c) ';'
d) None of the above

10. What is one dangerous situation that can occur when programming character string input in C?

a) Using up excessive amounts of memory.
b) Taking up too much CPU time requirements, which can slow down the disk system.
c) Having insufficient space in an array to hold all the user's input.
d) None of these

11. What two pieces of information are needed by 'FOPEN()' ?

a) A drive letter and file mode specifier
b) A filename and file mode specifier
c) A file mode specifier and system password
d) None of the above

12. What happens when an object is instantiated?

a) The object is deleted or removed from memory
b) A pointer to the object is created
c) The object is dereferenced
d) None of these

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

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

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

16. Which operator is used to access the member elements of a structure?

a) "*"
b) "."
c) "&"
d) None of these

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

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

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

20. Which standard library function below is used to move the file position indicator when implementing a random-access binary file system?

a) fopen()
b) fseek()
c) fputs()
d) None of the above

21. Supposed that an array of CDonut objects called "OurDonuts" has been instantiated dynamically. What is the correct method for deleting the array from memory?

a) delete OurDonuts;
b) delete []OurDonuts;
c) delete AllDonuts;
d) None of the above

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

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

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

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

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

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. What is the default access type for members of a class?

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

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

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!