CSc 330 - Quiz #1

Professor B. Domanski

WRITE YOUR NAME ON EACH SHEET & DATE IT! Answer all questions. No partial credit will be given. Cheating will result in a failing grade. If you have any questions whatsoever about portions of this exam, ask the Professor, not your neighbor!

 

Given the following C++ program:

#include <stdio.h>

class glopplus

{ private:

int data[10];

public:

glopplus(int*);

glopplus();

glopplus operator+( glopplus& );

};


glopplus::glopplus(int x[])

{ for (int i=0; i<10; i++) data[i] = x[i];

return ; }


glopplus::glopplus()

{ for (int i=0; i<10; i++) data[i] = 0; }


glopplus glopplus::operator+( glopplus& op2)

{

int i;

glopplus temp;

for ( i=0; i<10; i++)

temp.data[i] = this->data[i] + op2.data[i];

return temp;

}


main ()

{

int X[10] = { 1,3,5,7,9,11,13,15,17,19 }, Y[10] = { 2,4,6,8,10,12,14,16,18,20};

glopplus a(X), b(Y), c;

c = a + b;

return(0);

}


How many glopplus objects are used in the main program? _____________________

Embedding a function in the glopplus definitions is an example of: _______________

a. function overloading

b. encapsulation

c. template definition

d. type definition

What is the value of c when the main program completes?

________________________________________________________________________

What is the value of data[i] when i =4 in each glopplus object at the end of execution?

___________________________________________________________________


Private data members and member functions can be used by only by members of the class and by ________

Public data members and member functions can be used by ___________________ function.


Given the following

int x=33, y=44;

swap(x,y); // CALL 1

swap(&x,&y); // CALL 2

...

void swap(int a, int b) { ... } ; //FUNCTION A

void swap(int *a, int *b) { ... } ; //FUNCTION B

void swap(int &a, int &b) { ... } ; //FUNCTION C

 

Call 2 invokes function ______________ (A, B or C)

The C++ compiler system cannot figure out which function is invoked by Call 1 (True or False) _____________________


Match up the following terms with their best definition

______ class A. enables the creation of arbitrary objects for arbitrary duration

______ object B. functions not in a class that have access to private member objects of the class

______ delete C. functions beginning with a ~ that have the same name as a defined class

______ operator overloading D. contains function name, number & type of arguments and return type

______ function overloading E. used to unhide a global variable or function

______ member function F. members of a base class are available to a child class

______ scope resolution operator G. multiple functions with the same name but different arguments and/or return types

______ structure H. de-allocate any storage that was dynamically allocated

______ prototype I. stream I/O input and output functions

______ constructor J. a new data type where the user defines its' behavior

______ destructor K. allocations of classes

______ encapsulation L. specifying how traditional operators work with class objects

______ friends M. functions that are part of a class

______ cin,cout N. a collection of data ty7pes, possibly of different types and sizes

______ new O. function that initializes an object upon allocation

______ passing parameters P. bundling data types and functions together

______ inheritance Q. can be done by value and by reference

______ macros R. abbreviations for a larger set of activities