The thing is that I am struggling with making objects of the class Shape. I declare the vector, but then do not know how to connect it to the class Shape and its objects. The code itself has one base class, which is Shape and then two subclasses Circle and Rectancle. The idea of the code is to use a vector in the main function, and have multiple cases for the Circle area and the Rectangle area. This is the code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Shape
{
public:
virtual double GetArea() const = 0
{
}
private:
};
class Circle : public Shape
{
public:
Circle(double p, double r) // constructor
{
pi = p;
radius = r;
}
Circle() : pi(3.14), radius(0) {} // default constructor
void SetRadius(double value)
{
radius = value;
}
double GetRadius() const
{
return radius;
}
double GetArea()
{
double area = pi * radius * radius;
return area;
}
private:
double pi = 3.14;
double radius;
};
class Rectangle : public Shape
{
public:
Rectangle(double a, double b) // constructor
{
sideA = a;
sideB = b;
}
Rectangle() : sideA(0), sideB(0) {} // default constructor
void SetSideA(double value)
{
sideA = value;
}
double getSideA() const
{
return sideA;
}
void SetSideB(double val)
{
sideB = val;
}
double getSideB() const
{
return sideB;
}
double getArea()
{
double Area = sideA * sideB;
return Area;
}
private:
double sideA;
double sideB;
};
int main()
{
vector<Shape*> shape;
return 0;
}