In the following Rectangle class declaration, the width, length, and area members are of type double. Rewrite the class as a template that will accept any numeric type for these members. class Rectangle {private:double width;double length;double area; public:void setData(double w, double l) { width = w; length = l; }void calcArea(){ area = width * length; } double getWidth(){ return width; } double getLength(){ return length; } double getArea(){ return area; }};
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
In the following Rectangle class declaration, the width, length, and area members are of type double. Rewrite the class as a template that will accept any numeric type for these members.
class Rectangle
{
private:
double width;
double length;
double area; public:
void setData(double w, double l) { width = w; length = l;
}
void calcArea()
{ area = width * length; } double getWidth()
{ return width; } double getLength()
{ return length; } double getArea()
{ return area; }
};
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images