a) Write code to create ‘Shape’ class and include following:
#include <iostream>
using namespace std;
class Shape
{
private:
float length;
float width;
string name;
public:
void setLength(float length)
{
this->length = length;
}
void setWidth(float width)
{
this->width = width;
}
void setName(string name)
{
this->name = name;
}
float getLength() const
{
return length;
}
float getWidth() const
{
return width;
}
string getName() const
{
return name;
}
Shape(float length, float width, string name)
{
setLength(length);
setWidth(width);
setName(name);
}
Shape(const Shape &shape)
{
setLength(shape.getLength());
setWidth(shape.getWidth());
setName(shape.getName());
}
~Shape()
{
cout << "name: " << name << endl;
cout << "length: " << length << endl;
cout << "width: " << width << endl << endl;
}
};
int main()
{
Shape rectangle1(5,10,"rectangle");
Shape rectangle2 = rectangle1;
return 0;
}
Comments
Leave a comment