Defining a vector of shared pointers to the base class

  c++, vector

Here’s my Specific question and below the code I wrote so far.

I need to write a program that defines a vector of shared pointers to the base class and it puts the following objects into vector:

• Point with coordinates (1.0, 1.0)

MY CODE:

#pragma once
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

class Point {

public:
    Point(double xcoord = 0.0, double ycoord = 0.0);

    virtual ~Point() = default;
    virtual void input(const char* prompt);
    virtual void output() const;
    virtual double area() const;
    void move(double deltax, double deltay);

private:
    double x;
    double y;
};

class Circle : public Point {
public:
    Circle(double xcoord = 0.0, double ycoord = 0.0, float r0 = 0.0) : Point(xcoord, ycoord) { radius = r0; }

    virtual ~Point() = default;
    virtual void input(const char* prompt);
    virtual void output() const;
    virtual double area() const;

private:
    float radius;
};


class Square : public Point {

public:
    Square(double xcoord = 0.0, double ycoord = 0.0, float w = 0.0, float h = 0.0) : Point(xcoord, ycoord) { width = w, height = h; }

    virtual ~Point() = default;
    virtual void input(const char* prompt);
    virtual void output() const;
    virtual double area() const;

private:
    float width;
    float height;

}; 

Source: Windows Questions C++

LEAVE A COMMENT