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

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. Given the declarations:

char szData[64];
int i;


Supposed that we wish to place a text message into szData that shows the value in variable i. Which of the statements below would accomplish this?

a) strcpy( szData , "i = %d", i);
b) sprintf( szData , "i = %d" , i );
c) strcat( szData , i , "i = %d" );
d) None of these

2. What information must be passed to the STRCPY() library routine?

a) The length of each string, and the address of each string.
b) The address of each string.
c) The length of one of the strings.
d) None of these

3. Which of these lists the products of a C compilation session in correct order?

a) Assembly code - Source code - Object code - Machine code
b) Machine code - Object code - Source code - Assembly code
c) Source code - Assembly code - Object code - Machine code
d) None of these

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

5. Given the following declaration:

int Values[25];

Which expression below is equivalent to: Values?

a) &Values[0]
b) Values[0]
c) Values[-1]
d) None of these

6. What conditions must be present for the fragment below to print the message "B is too small?"

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

a) (a < 20)
b) (a > 20) and (b >= 10)
c) (a>=20) and (b < 10)
d) None of the above

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

8. What type of data must be in variable A below?

printf("A = %d now.\n", a );

a) int
b) char
c) float
d) double

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

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

10. What is the data type of the following expression:


a) Int
b) Float
c) Double
d) None of the above

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

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

13. Which standard stream below could be used to talk to the video display?

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

14. When a text file has been opened and a newline '\n' character is written into it by a C program, what character sequence is actually created in the file?

a) '\n' (LF)
b) '\r' (CR)
c) '\r' '\n' (CR - LF)
d) None of the above

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

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

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

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

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

19. Given the following declaration:

struct Complex
    double re;
    double im;

Complex Values[10];

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

a) 160
b) 80
c) 40
d) None of these

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

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

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

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

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

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

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!