COP 3330 Myers Test 1 Exam with
complete solutions latest version
Which of the following statements is NOT TRUE regarding classes and objects?
A. Member data of a class is in scope for all the member functions of the class
B. Member functions are called by using the format: object.function()
C. The public section of a class must be listed before the private section
D. Member data of a class can be public or private - CORRECT ANSWER-The public
section of a class must be listed before the private section
For a class called Yadda, which of the following is a default constructor?
A. Yadda (int a = 10);
B. Yadda Yadda();
C. Yadda(int a, int b, = 20);
D. void Yadda(); - CORRECT ANSWER-Yadda (int a = 10);
Which of the following would result in a compile stage error?
A. Having two definitions of a function, each one in a separate code file
B. Doing the division (x/y), where x and y are integers and y is 0
C. Passing an int argument to a function that expects a parameter of type double
D. Calling a function before it is declared - CORRECT ANSWER-Calling a function
before it is declared
In a class, the purpose of a destructor member function is... - CORRECT ANSWER-to
do any final clean-up tasks on an object before it is deallocated
Which of the following statements about operator overloading is TRUE?
A. Operator overloading can set a new precedence level for an operator
B. Operator overloading cannot be used to create new operator symbols
C. A binary operator overload cannot use a built-in type as an operand
BRAINSCAPE1
, BRAINSCAPE1
D. All C++ operators can be overloaded - CORRECT ANSWER-Operator overloading
cannot be used to create new operator symbols
Which of the following describes an implementation of the composition ('has-a')
relationship?
A. Class Tree calls the Grow() function of class Leaf
B. An object of type Rock is declared as member data of class Quarry
C. An object type Cube is declared as member data of class Cube
D. Class Chair is defined inside class Room - CORRECT ANSWER-An object of type
Rock is declared as member data of class Quarry
If Cat is a class with a default constructor and a constructor with two int parameters,
which of the following is a valid declaration of an array of objects of type Cat?
A. Cat list[4] = {Cat(), Cat(4,8), Cat(1,6)};
B. Cat list[] = {Cat(5), Cat(15), Cat()};
C. Cat* list = {Cat1, Cat2, Cat3(1,2)};
D. Cat list[]; - CORRECT ANSWER-Cat list[4] = {Cat(), Cat(4,8), Cat(1,6)};
Which of the following is not a valid operator overload prototype?
A. bool operator< (Box x, Box y);
B. Box operator* (const Box& x, int y);
C. Box operator+ (double x, double y);
D. Box operator== (const Box& ) const; - CORRECT ANSWER-Box operator+ (double
x, double y);
If w1 and w2 are objects of type Weight, which of the following expressions contains a
call to an operator that cannot be overloaded as a member function of class Weight?
A. w1 - w2
B. w1 < 5
C. w1++
D. 10 + w2 - CORRECT ANSWER-10 + w2
Which of the following is a correct way to declare a member function of a class so that it
will be allowed to change the member data of the calling object?
A. int Modify(double& x) const;
B. const int Modify(const double& x);
C. int Modify(const double& x) const;
D. friend int Modify(double& x); - CORRECT ANSWER-const int Modify(const double&
x);
T/F
BRAINSCAPE1