Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1. 1. (TCO 2) Consider the following class definition. class rectangleT

ID: 3558613 • Letter: Q

Question

Question 1.1. (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; Question 2.2. (TCO 2) The components of a class are called the ____ of the class. (Points : 4)        elements
       members
       objects
       properties Question 3.3. (TCO 2) In C++ terminology, _____. (Points : 4)        a class object is the same as a class instance
       a class object is the same as a class member
       a class object is the same as a class access specifier
       a class object is the same as a non member function Question 4.4. (TCO 2) Consider the following 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(); Question 5.5. (TCO 2) In C++, class is a reserved word that defines _____. (Points : 4)        a data type
       an object type
       a variable
       an enumeration Question 6.6. (TCO 4) A derived class can _____. (Points : 4)        never access public members of a base class
       directly access public members of a base class
       not change the value of public members of a base class
       directly access only private members of the base class Question 7.7. (TCO 4) The constructor of a derived class _____. (Points : 4)        cannot specify a call to the constructor of a base class in the body of the constructor function definition
       can specify a call to the constructor of a base class only when the access specifier for the class set is protected
       can specify a call to the constructor of a base class in the body of the function definition
       can specify a call to the constructor of a base class in the body of the constructor function definition Question 8.8. (TCO 4) A derived class can redefine _____. (Points : 4)        a private member function of the base class
       a public member function of the base class
       both public and private member functions of the base class
       niether public nor private member functions of the base class Question 9.9. (TCO 4) Which of the following is true about a derived class? (Points : 4)        A derived class can directly access any member variable of the base class.
       A derived class can redefine any public member function of the base class.
       A derived class can have, at most, one base class.
       A derived class can redefine any member function of the base class. Question 10.10. (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
       The BClass constructor only. The AClass constructor is not called if the AClass is derived private from BClass.
       The AClass constructor only. The BClass constructor is not called if the BClass is derived private from AClass. Question 11.11. (TCO 4) The new classes that we create from the existing classes are called ____ classes. (Points : 4)        sibling
       base
       derived
       parent Question 12.12. (TCO 4) Which of the following is a valid definition of the derived class bClass? (Points : 4)        class aClass: public bClass{ //...};
       class bClass: public aClass{ //...};
       class aClass::bClass{ //...};
       class bClass::aClass{ //...} Question 13.13. (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 Question 1.1. (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;

Explanation / Answer

1) rectangleType rectangle;
//rectangleType is like a composite datatype defined by user
and rectangle is the name of the object

2) members
functions are called as member functions
variables/attributes are called as data members

3) a class object is the same as a class instance

4) myObject.print();
explnation: print is a function it can be called
it can't be given a value like myObject.print = 10; //this is wrong

5) an object type

6) directly access public members of a base class
expl::public members are visible publicly

7) can specify a call to the constructor of a base class in the body of the constructor function definition
A constructor performs its work in this order:
a)It calls base class and member constructors in the order of declaration.
b)If the class is derived from virtual base classes, it initializes the object's virtual base pointers.
c)If the class has or inherits virtual functions, it initializes the object's virtual function pointers. Virtual function pointers point to the class's virtual function table to enable correct binding of virtual function calls to code.
d)It executes any code in its function body.


8) (c) both public and private member function of the base class

9) (d) A derived class can redefine any member function of the base class.
Expl:Look at this code

#include <iostream>

using namespace std;

class Base
{
public:
void operate_on();
private:
virtual void do_operate_on() = 0;
};

void Base::operate_on()
{
// check preconditions
do_operate_on();
// check postconditions
}

class Derived: public Base
{
// this overrides Base::do_operate_on
void do_operate_on();
};

void Derived::do_operate_on()
{
// do something
cout<<"base function called";
}

int main()
{
  
Base* p = new Derived;

// this calls Base::operate_on, which in turn calls the overridden
// Derived::do_operate_on, not Base::do_operate_on (which doesn't have an
// implementation anyway)
p->operate_on();

delete p;
}


OUTPUT::base function called

Try to run. Hence derived class can redefine any function
of base class provided its virtual (polymorphism)


10) BClass constructor first, AClass constructor second
expl::
A constructor performs its work in this order:
a)It calls base class and member constructors in the order of declaration.
b)If the class is derived from virtual base classes, it initializes the object's virtual base pointers.
c)If the class has or inherits virtual functions, it initializes the object's virtual function pointers. Virtual function pointers point to the class's virtual function table to enable correct binding of virtual function calls to code.
d)It executes any code in its function body

I mean the code of the constructor of derived class will be executed later than that of base class

11) derived

12) class bClass: public aClass{ //...};
here base class is aClass which is inherited publicly

13) Mother and Father to Children
Expl: multiple inheritance means more than 1 base class of 1 derived class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote