Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 1

Mark the following statements as true or false. a. The constructor of a derived class can specify a call to the constructor of the base class in the heading of the function definition. b. The constructor of a derived class can specify a call to the constructor of the base class using the name of the class. c. Suppose that \(\mathbf{x}\) and \(\mathbf{y}\) are classes, one of the member variables of \(\mathbf{x}\) is an object of type \(\mathbf{y}\), and both classes have constructors. The constructor of \(\mathbf{x}\) specifies a call to the constructor of \(y\) by using the object name of type \(y\)

Problem 4

Consider the following statements: class dog: public animal { ... }; In this declaration, which class is the base class, and which class is the derived class?

Problem 5

Consider the following class definition: class circle class cylinder: public circle { { public: public: void print() const; void print() const; void setRadius(double); void setHeight(double); double getRadius(); double getHeight(); double area(); double volume(); circle(); double area(); circle(double); cylinder(); cylinder(double, double); private: private: double radius; double height; }; }; Suppose that you have the declaration: cylinder newCylinder;

Problem 6

Suppose that class three is derived from class two, class two is derived from class one, and each class has instance variables. Suppose that an object of class three enters its scope, so the constructors of these classes will execute. Determine the order in which the constructors of these classes will execute.

Problem 8

Consider the following statements: class yClass class xClass: public yClass { { public: public: void one(); void one(); void two(int, int); xClass(); yClass(); private: private: int z; int a; int b; }; }; Suppose the following statements are in a user program (client code): yClass y; xClass x; a. The private members of yClass are public members of xClass. True or False? b. Mark the following statements as valid or invalid. If a statement is invalid, explain why. i. void yClass::one() { cout << a + b << endl; } ii. y.a = 15; x.b = 30; iii. void xClass::one() { a = 10; b = 15; z = 30; cout << a + b + z << endl; } iv. cout << y.a << " " << y.b << " " << x.z << endl;

Problem 10

Explain the difference between the private and protected members of a class.

Problem 11

Explain the difference between the protected and public members of a class.

Problem 13

Assume the declaration of Exercise \(12 .\) Suppose that class third is derived from class first using the statement: class third: protected first Determine which members of class first are private, protected, and public in class third.

Problem 16

What is wrong with the following code? class classA { protected: void setX(int a); //Line 1 //Postcondition: x = a; //Line 2 private: //Line 3 int x; //Line 4 }; . . . int main() { classA aObject; //Line 5 aObject.setX(4); //Line 6 return 0; //Line 7 }

Problem 17

Consider the following code: class one { public: void print() const; //Output the values of x and y protected: void setData(int u, int v); //Postcondition: x = u; y = v; private: int x; int y; }; class two: public one { public: void setData(int a, int b, int c); //Postcondition: x = a; y = b; z = c; void print() const; //Output the values of x, y, and z private: int z; }; a. Write the definition of the function setData of the class two. b. Write the definition of the function print of the class two.

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks