COMP270 Practice for Exam 1

Instructions: There are 30 questions on this test. It is written in a style very similar to the REAL exam 1. Choose the best answer from among those given. Click the GRADE button on the bottom of the form when you want the exam graded.  And be careful about listening to the "Back Row" folks!

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 wrong with the following code?

char szPassword[24];
gets(szPassword); // Get user password

if ( szPassword == "Joshua" ) printf("Welcome!");

a) The comparison method (==) will not work with strings.
b) GETS() does not input character strings.
c) The array declaration is invalid.
d) None of these

2. What character code is used to end all strings in C?

a) '\n'
b) '\0'
c) '\7'
d) None of these

Are you paying attention Back Row?!?

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

4. For the code below to print the message "OK", what conditions are needed?

if (a<20) && (b == 25)

a) A must be more than 20, OR B must be equal to 25
b) Either A must be less than 20, OR B must be not equal to 25
c) A must be less than 20, AND B must be equal to 25
d) None of the above

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

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

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

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

7. What are the objects in programming?

a) The computer's instructions
b) The data
c) The constants
d) None of the above

8. What is the result of evaluating the following expression?

22/7. + 5/3

a) 4.142857...
b) 4.809523...
c) 5
d) None of the above

9. What is the effect of a return statement within MAIN()?

a) The program starts over at the first statement in MAIN()
b) The program ends and control goes back to the operating system
c) The last executed instruction repeats
d) None of the above

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

int i=0;

do  {
     printf("%d", i);

a) 1 2 3 4 5
b) 0 1 2 3 4
c) 0 1 2 3
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;

Complex Values[ xx ];

If there are 1732 memory locations free, what is the maximum value that "xx" can have, assuming that a DOUBLE uses 8 memory locations?

a) 216
b) 108
c) 132
d) None of these

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

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. The functions that are part of Class objects are called the:

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

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

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

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

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

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

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

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

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

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

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

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

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

OK, just one more question...are you ready?

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

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!