Define a class Shape and create constant object from the class with at least one constant data member. Create object in main function from the class Shape. Also display state of the constant object in main( ) function
#include <iostream>
using namespace std;
class Shape
{
public:
Shape(double r);
void SetRadius(double r) { radius = r; }
double GetRadius() { return radius; }
double GetArea() { return PI * radius * radius; }
private:
double radius;
const double PI = 3.145;
};
Shape::Shape(double r) : radius(r)
{
}
int main()
{
cout << "Define new shape" << endl;
Shape Circle(5);
cout << "Shape is circle with radius " << Circle.GetRadius() << endl;
cout << "Set radius to our shape to 10" << endl;
Circle.SetRadius(10);
cout << "Shape is circle with radius " << Circle.GetRadius() << endl;
cout << "And its area is: " << Circle.GetArea() << endl;
return 0;
}
Comments
Leave a comment