# COMP220 Solved Midterm Exam – Week 4 – Previous Exam – Guaranteed 100% score

Exam Price = \$19
[orb_cyber_store id=”182″]
Problem Statement

Week 4 : Object Composition – Midterm Exam 2

1. (TCO 1) Assume you have the following declaration:
char nameList;
which of the following ranges is valid for the index of the array nameList? (Points : 4)
0 through 99
0 through 100
1 through 100
1 through 101

2. (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] = 2 * j; if (j % 2 == 1) //see if j is an even number alpha[j - 1] = alpha[j] + j; } (Points : 4) alpha = {0, 2, 4, 6, 8} alpha = {0, 2, 9, 6, 8} alpha = {0, 3, 4, 7, 8} alpha = {3, 2, 9, 6, 8} 3. (TCO 1) What is the value of alpha after the following code executes? int alpha = {0}; int j; for(j = 4; j >= 0; j–)
{
alpha[j] = j + 5;
if (j % 2 == 0)
alpha[j + 1] = alpha[j] + 3;
} (Points : 4)
5
8
9
10

4. (TCO 1) Consider the following declaration:
int alpha;
Which of the following input statements correctly inputs values into all the array elements of alpha? (Points : 4)
cin >> alpha >> alpha >> alpha;
cin >> alpha >> alpha >> alpha;
cin >> alpha >> alpha >> alpha;
cin >> alpha

5. (TCO 1) Given the function prototype void strange(int a, int b);
And the following declaration,
int alpha;
int beta;
Which of the following is a valid call to the function strange? (Points : 4)
strange(alpha, alpha);
strange(alpha, beta);
strange(alpha, beta);
strange(alpha, beta);

6. (TCO 1) After the following statements execute, what are the contents of matrix?

int matrix = {0};
int j, k;
for (j = 0; j < 3; j++) for (k = 0; k < 2; k++) matrix[j][k] = j + k; (Points : 4) 0 0, 1 1, 2 2 0 1, 2 3, 4 5 0 1, 1 2, 2 3 1 1, 2 2, 3 3 7. (TCO 1) Consider the following statements. int beta = {0}; int j, k; Which of the following statements correctly outputs the elements of beta one row per line? (i) for (j = 0; j < 10; j++) { for (k = 0; k < 5; k++) cout << beta[j][k]; cout << endl; } (ii) for (j = 0; j < 10; j++) for (k = 0; k < 5; k++) { cout << beta[j][k]; cout << endl; } (Points : 4) Only (i) Only (ii) Both (i) and (ii) None of these 8. (TCO 1) Given the following multidimensional array declaration, how many elements exist in the array? double neoMatrix; (Points : 4) 456 60 15 120 9. (TCO 2) In C++, class is a reserved word that defines (Points : 4) a data type. an object type. a variable. an enumeration. 10. (TCO 2) The member functions of a class should usually be (Points : 4) public. private. protected. templates. Page 2 Multiple Choice 1. (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. 2. (TCO 2) Given the declaration: class myClass { public: void print(); private: int x; }; myClass myObject; which statement is legal? (Points : 4) myObject.print = 10; myClass.print = 10; myObject.print(); myClass.print(); 3. (TCO 2) Given: bool clockType::equalTime(const clockType&) const {...} void clockType::getTime(int&, int&, int&) const {...} The word _____ at the end of the member functions in the class clockType specifies that these functions cannot modify the member variables of a clockType object. (Points : 4) void const clockType:: & 4. (TCO 2) A _____ sign in front of a member name on the UML diagram indicates that this member is public. (Points : 4) + - # \$ 5. (TCO 2) Consider the following class definition: class rectangleType { public: void setLengthWidth(double x, double y); //Postcondition: length = x; width = y; void print() const; //Output length and width; double area(); //Calculate and return the area of the rectangle; double perimeter(); //Calculate and return the parameter; rectangleType(); //Postcondition: length = 0; width = 0; rectangleType(double x, double y); //Postcondition: length = x; width = y; private: double length; double width; }; Which of the following class variable declarations is correct? (Points : 4) rectangle rectangleType; class rectangleType rectangle; rectangleType rectangle; rectangle rectangleType.area; 6. (TCO 3) A(n) _____ relationship represents composition. (Points : 4) "has a" "is a" "part of" logical 7. (TCO 8) If a Class A has an object of Class B as a data member, what type of function must be used for an object of Class A to obtain a copy of a private data member of Class B? (Points : 4) Class B copy constructor Class B accessor function Class A accessor function It is not possible for an object of Class A to do this action. 8. (TCO 8) 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 9. (TCO 8) 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 10. (TCO 8) Which one of the commonly used include (header) files is not covered by the std namespace? (Points : 4) math iomanip string iostream Page: 1 2 3 4 Time Remaining:   Week 4 : Object Composition - Midterm Exam Time Remaining: Page: 1 2 3 4 Page 3 Multiple Choice 1. (TCO 2) A class object can be _____. That is, it can be created once, when the control reaches its declaration, and destroyed when the program terminates. (Points : 4) static automatic local public 2. (TCO 3) Which of the following statements is an accurate example of composition? (Points : 4) A car has an engine. A car is an automobile. A car is an object. A car has a class. 3. (TCO 4) A derived class (Points : 4) can never access public members of a base class. can directly access public members of a base class. cannot change the value of public members of a base class. can only directly access private members of the base class. 4. (TCO 4) If inheritance is private (Points : 4) public and protected members of the base class become private members of the derived class. all private members of the base class become public members of the derived class. protected members of the base class become public members of the derived class. none of the members of the base class become members of the derived class. 5. (TCO 4) Suppose that bClass is a class. Which of the following statements correctly derives the class dClass from bClass? (Points : 4) class dClass:: public bClass{ //classMembersList}; class dClass: private bClass{ //classMembersList}; class dClass:: protected bClass{ //classMembersList}; class bClass: public dClass{ //classMembersList}; 6. (TCO 4) OOP implements _____. (Points : 4) UML IPE EIP OOD 7. (TCO 4) Consider the following class definition: class dClass: bClass { //class members list }; The class dClass is derived from the class bClass using the _____ type of inheritance. (Points : 4) public private protected static 8. (TCO 4) Which of the following base class members is never inherited by a derived class, regardless of access attributes? (Points : 4) Mutator Accessor Constructor Data 9. (TCO 4) Which of the following statements correctly describes an example of multiple inheritance? (Points : 4) Mother and Father to Children Animal to Reptile to Snake Parent to Child Animal to Mammal and Bird 10. (TCO 8) In a multifile, object-oriented C++ project, which file contains the class definition? (Points : 4) classname.cpp classname.h classname.def classname.hdr Page: 1 2 3 4 Time Remaining: 1. (TCO 1) Explain how to use loops to process data stored in a two-dimensional array. In your explanation include a two-dimensional array declaration and initialization. (Points : 10) 2. (TCO 1) Given a two-dimensional array declaration, describe two different methods on how the all the array elements could be initialized. For example, write the declaration for a two-dimensional array of type integer and set all elements of the array equal to a value of 0. (Points : 10) 3. (TCO 2) Develop a class definition that models an employee. Include private and public member functions and variables. Demonstrate how the class would be instantiated and how class members would be accessed. (Points : 10) 4. (TCO 2) Describe in detail what is contained in each of three areas of a Unified Modeling Language (UML) diagram of a class. (Points : 10) 5. (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 that directly show composition and proper access attributes. (Points : 10) 6. (TCO 4) Explain the usefulness of inheritance. What is the difference between the base and derived class? Show how to write the code to create a derived class. (Points : 10) 7. (TCO 4) If a class is derived protected from a base class, explain how this affects the inheritance of all public, protected, and private members of the base class by the derived class. (Points : 10) 8. (TCO 8) Why are comments and comment blocks important to programming? (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 [email protected] 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 [email protected].
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at [email protected] and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.