Create a class called Rectangle with data members: width, length and area. The class should have functions to allow for setting of both length and width, calculate the area, and retrieve the width, length and area.
#include<iostream>
using namespace std;
class Rectangle
{
private:
double width;
double length;
double area;
public:
void set_width(double _width)
{
width = _width;
}
void set_length(double _length)
{
length = _length;
}
void set_area()
{
area = 2 * (width + length);
}
double get_width()
{
return width;
}
double get_length()
{
return length;
}
double get_area()
{
return area;
}
};
int main()
{
Rectangle rectangle;
rectangle.set_length(5);
rectangle.set_width(2);
rectangle.set_area();
cout<< rectangle.get_length()<<endl;
cout<<rectangle.get_width()<<endl;
cout<<rectangle.get_area()<<endl;
system("pause");
return 0;
}
Comments
great
Leave a comment