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