COMP220 Week 8 – Study Material for Finals – 13 MCQs, 8 Essay Questions – Guaranteed 100% score

Quiz Price = \$20
Problem Statement

1. (TCO 1) What is the output of the following C++ code?

int list = {0, 5, 10, 15, 20};
int j;
for (j = 1; j <= 5; j++)
cout << list[j];

(Points : 4)
0 5 10 15 20
5 10 15 20 0
5 10 15 20 20
Code contains index out-of-bounds

2. (TCO 1) What is the value of alpha after the following code executes?

int alpha = {0};
int j;
alpha = 5;
for (j = 1; j < 5; j++)
{
if (j % 2 == 0) //see if j is an odd number
alpha[j] = alpha[j - 1] + 2;
else
alpha[j] = alpha[j - 1] + 3;
}

(Points : 4)
10
13
15
17

3. (TCO 1) What is stored in alpha after the following code executes?

int alpha = {0};
int j;
for (j = 0; j < 5; j++)
{
alpha[j] = j + 1;
if (j > 2)
alpha[j - 1] = alpha[j] + 2;
}

(Points : 4)
alpha = {1, 2, 6, 7, 5}
alpha = {1, 2, 3, 4, 5}
alpha = {4, 5, 6, 7, 9}
None of these

4. (TCO 1) Suppose that the array alpha is to be declared as a formal parameter in a function heading. Which of the following about alpha is true?

(i) You must specify the size of alpha in square brackets.
(ii) You cannot pass alpha by value. (Points : 4)
Only (i)
Only (ii)
Both (i) and (ii)
Neither of these

5. (TCO 1) Given the function prototype:

void mystery(int list[], int size);
and the declaration:
int alpha;

which of the following is a valid call to the function mystery? (Points : 4)
mystery(alpha);
mystery(alpha[], 50);
mystery(alpha, 50);
mystery(alpha{50});

6. (TCO 1) Consider the following statements.

int alpha = {0};
int j,k;

Which of the following statements correctly initializes alpha to 0?

(i)
for (j = 0; j < 10; j++)
for(k = 0; k < 5; k++)
alpha[j][k] = 0;
(ii)
for (k = 0; k < 5; k++)
for (j = 0; j < 10; j++)
alpha[j][k] = 0;

(Points : 4)
Only (i)
Only (ii)
Both (i) and (ii)
None of these

7. (TCO 1) Given the following two-dimensional array, which statement correctly sets the third column and fourth row element = 25.0?

double neoMatrix; (Points : 4)
neoMatrix = 25.0;
neoMatrix = 25.0;
neoMatrix = 25.0;
neoMatrix = 25.0;

8. (TCO 2) The member variables of a class (Points : 4)
must be of the same data type.
must be in the same section--either public or private.
can be any data type.
must be initialized in the class definition.

9. (TCO 2) If the heading of a member function of a class ends with the word const, then (Points : 4)
the function members cannot modify the private member variables, but can modify the public member variables.
the function members cannot modify the public member variables, but can modify the private member variables.
the function members cannot modify the private member variables, nor can they modify the public member variables.
all variables can be modified.

10. (TCO 2) Which of the following class definitions is correct in C++? (Points : 4)

class studentType
{
public:
void setData(string, double, int);
private:
string name;
};

class studentType
{
public:
void setData(string, double, int);
void print() const;
private:
string name;
double gpa;
}

class studentType
{
public
void setData(string, double, int);
private
string name;
};

studentType class
{
public:
void setData(string, double, int);
private:
string name;
};

11. (TCO 4) To overload a member function of the base class, (Points : 4)
the name of the function and the formal parameter list of the corresponding function in the derived class must be same.
the name of the function must be different and the formal parameter list of the corresponding function in the derived class must be same.
the name of the function and the formal parameter list of the corresponding function in the derived class must be different.
the name of the function must be the same and the formal parameter list of the corresponding function in the derived class must be different.

12. (TCO 4) The existing classes, from which you create new classes, are called the ____ classes. (Points : 4)
child
base
sibling
derived

13. (TCO 5) Given a class called Employee and the following definitions and statements:

void myFunction( Employee * eptr );
Employee emp;

which of the following statements correctly calls the function passing in the address of the emp object?

(Points : 4)
myFunction(emp);
myFunction(&emp);
myFunction(*emp);
None of the above

Page 2

Multiple Choice Questions
1. (TCO 2) Suppose that you have the following UML class diagram of a class.

Which of the following is the name of the class? (Points : 4)
clock
clockType
Type
ClockType

2. (TCO 2) A ____ sign in front of a member name on the UML diagram indicates that this member is a public member. (Points : 4)
+
-
#
\$

3. (TCO 2) Consider the following class definition:

class circleType
{
public:
void set(double r);
void print();
double area();
//Postcondition: Calculate and return area.
double circumference();
//Postcondition: Calculate and return circumference.
circleType();
circleType(double r);
private:
};

Which of the following statements are valid in C++?

(i)
cin >> r;
myCircle.area = 3.14 * r * r;
cout

(ii)
cin >> r;
myCircle.set(r);
cout

(Points : 4)
Only (i)
Only (ii)
Both (i) and (ii)
None of these

4. (TCO 3) Which of the following may not be used as a class data member? (Points : 4)
struct
class
namespace
arrays

5. (TCO 3) Which is a correct preprocessor directive statement? (Points : 4)
define PI = 3.141593
define PI = 3.141593;
#define PI 3.141593
#define PI = 3.141593

6. (TCO 3) Aggregation is also sometimes called ______. (Points : 4)
inheritance
instantiation
composition
encapsulation

7. (TCO 4) Which of the following statements about inheritance is true if the memberAccessSpecifier is protected? (Points : 4)
The private members of the base class become protected members of the derived class.
The derived class can directly access any member of the base class.
The public members of the base class become protected members of the derived class.
The protected members of the base class become private members of the derived class.

8. (TCO 4) If class AClass is derived from class BClass, which one of the following statements correctly states the constructor call sequence when an object of class AClass is instantiated? (Points : 4)
BClass constructor first, AClass constructor second
AClass constructor first, BClass constructor second
BClass constructor only, the AClass constructor is not called if AClass derived private from BClass
AClass constructor only, the BClass constructor is not called if BClass derived private from AClass

9. (TCO 4) Which of the following relationships is not a correct example of inheritance? (Points : 4)
Parent to Children
Aunt to Uncle
Grandparent to Grandchild
Father and Mother to Children

10. (TCO 5) If p is a pointer variable of type int and num is an int variable, what is the result of the statement p = #? (Points : 4)
p is equal to num.
p is equal to the address of num.
num is equal to the address of p.
p and num are concatenated and assigned to p.

11. (TCO 5) For the statement char *p, how many bytes of storage are allocated on a Pentium class system using 32-bit addressing? (Points : 4)
One
Two
Four
Eight

12. (TCO 5) Which of the following statements correctly allocates space to store 15 real numbers? (Points : 4)
double *dptr = new double;
double dptr = new double;
double *dptr = new double;
real *iptr = new real;

13. (TCO 5) Given a pointer variable called myData which points to an instance of the following structure, which of the following statements assigns the value 123.45 to the dval field of the structure?

struct Data
{
int ival;
double dval;
char cval;
};

(Points : 4)
dval = 123.45;
*mydata = 123.45;
mydata->dval = 123.45;
mydata.dval = 123.45;

Page 3

Multiple Choice Questions
1. (TCO 4) Which of the following is not true about public inheritance? (Points : 4)
All public member functions of the base class become the public member functions of the derived class.
All public member variables of the base class become the public member variables of the derived class.
All public members of the base class become the public members of the derived class.
The public member variables of the base class become the private member variables of the derived class.

2. (TCO 6) Which of the following operators may not be overloaded? (Points : 4)
=
::
||
&&

3. (TCO 6) Which of the following function prototypes overloads the != operator for the class rectangleType? (Points : 4)
bool operator!=(rectangle&) const;
bool operator!=(const rectangleType&) const;
int operator!=(const rectangleType) const;
int operator!=(rectangle&) const;

4. (TCO 6) An example of a unary operator is (Points : 4)
-
+
*
/

5. (TCO 6) When the assignment operator is overloaded for a class object, the return type must be declared (Points : 4)
as a Boolean data type.
as a reference.
as a constant.
as no data type, similar to a constructor.

6. (TCO 6) What is the difference between a friend function and a member function of the class? (Points : 4)
A friend function is a non-member function of the class while a member function is a member of the class.
All member functions of a class are also friend functions.
The prototype for a friend function is not included in the class definition.
The definition of a friend function must be preceded by the class name and the scope resolution operator.

7. (TCO 7) Which term designates the ability to use the same expression to denote different operations? (Points : 4)
Inheritance
Encapsulation
Polymorphism
Composition.

8. (TCO 7) Overriding a base class member function with a derived member function demonstrates the concept of (Points : 4)
inheritance.
polymorphism.
abstraction.

9. (TCO 7) Virtual functions are reserved using what C++ keyword? (Points : 4)
Polymorphic
Static
Dynamic
Virtual

10. (TCO 7) If a class is abstract then (Points : 4)
no objects may be instantiated of that class.
any and all objects of that class must be declared as virtual also.
its destructor must also be virtual.
it provides a blueprint for objects instantiated from it.

11. (TCO 7) With virtual functions and polymorphism, the programmer can (Points : 4)
have all object definitions defined during compilation.
have all object definitions defined during linking.
have the object definitions defined during run-time.
explicitly define all class relationships in the program code.

12. (TCO 8) In a multi-file, object-oriented C++ project, which file contains the class implementation? (Points : 4)
classname.hdr
classname.h
classname.def
classname.cpp

13. (TCO 8) What is the namespace commonly used with ? (Points : 4)
std
standard
.h
cin and cout

14. (TCO 8) Which preprocessor directive is used to end a conditional compilation directive? (Points : 4)
define
ifndef
ifdef
endif

Page 4

Essay Questions
1. (TCO 1) Describe an example of a two-dimensional character array that could be used to hold a set of text data that might be displayed on a handheld information display device such as an MP3 player. Describe what each of the two dimensions might represent and the data that would be held in the array and provide an example array declaration. (Points : 10)

2. (TCO 2) Explain how encapsulation and data hiding are incorporated in C++ classes. Why are these concepts important in object-oriented programming? (Points : 10)
3. (TCO 3) Using a personal computer as a base model, write a C++, syntactically correct class definition demonstrating composition. In the class definition, include at least the three following items common to a PC: a CD drive, a hard disk drive, and a power supply. You are not required to include any constructors, destructors, or additional member functions. You are only required to list members which directly show composition and proper access attributes. (Points : 10)
4. (TCO 4) Explain the usefulness of inheritance. What is the difference between the base and derived classes? Show how to write the code to create a derived class. (Points : 10)
5. (TCO 5) Write the code that will declare an integer array of dimension 10 and then use pointer arithmetic to initialize all elements of that array to zero. Comment on each line of code to describe what that line does. (Points : 10)

6. (TCO 6) Assume that you have that three objects of class Inductor have been instantiated, L1, L2, and L3. Write the overloaded operator prototypes that would be required to perform the following operation. You are only required to write the prototypes and not the implementation code.
L3 = L1 + L2; (Points : 10)

7. (TCO 7) Discuss run-time binding and how it relates to virtual functions. (Points : 10)
8. (TCO 8) Describe what the preprocessor statement is, how it is used, and what part of the development environment it interacts with, and provide a syntactically correct example, describing what it does. (Points : 10)

Relevant Material
Instructions
* Please click on “Buy Now” button to complete the purchase.Please note that the payment is done through PayPal.
* If you have any issues with the payment method, please let us know at support@iqrajavaid.com and that can be discussed and considered.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at support@iqrajavaid.com.