Question: C++ C++ Consider the following class definition class Square { public: void print () const; void setWidth(double); double calArea(); Square(); Square(double); private: double width; double
C++
C++
Consider the following class definition
class Square
{
public:
void print () const;
void setWidth(double);
double calArea();
Square();
Square(double);
private:
double width;
double area;
};
class Rod : public Square
{
public:
void print() const;
void setLength (double);
void calVolume();
Rod();
Rod(double, double);
private:
double length;
double volume;
};
a. Fill in the underlines below to complete the definitions of the member functions of the class Square.
Answer:
______________print() const
{
cout << "Area: " << ______________ << endl;
}
______________setWidth(double w)
{
if (w >= 0)
______________
else
width = 0.0;
}
______________calArea()
{
return area = width * width;
}
______________Square()
{
______________;
calArea();
}
______________Square(double w)
{
______________;
calArea();
}
b. Fill in the underlines below to complete the definitions of the member functions of the class Rod.
Answer:
______________print() const
{
Square:: ______________;
cout << "Volume: " << volume << endl;
}
______________setLength(double l)
{
if (l >= 0.0)
______________;
else
length = 0.0;
}
______________calVolume()
{
volume = ______________ * length;
}
______________
{
______________ ;
calVolume();
}
Rod::Rod(double w, double l)
______________
{
______________;
calVolume();
}
c. Identify the member functions of the class Rod that overrides the member functions of the class Square.
Answer:
______________
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
