How to ask the user to input the number in my code in order to print out the result

  abstract-base-class, area, c++, virtual-functions

How can I ask the user to input those two numbers and print out the result in C++ here? Please, I need your help. I am a newbie in C++, that’s why sorry if it’s a very silly question. Thanks in advance!

#include <iostream>
using namespace std;

class Polygon {
  protected:
    int width, height;
  public:
    void set_values (int a, int b)
      { width=a; height=b; }
    virtual int area ()
      { return 0; }
};

class Rectangle: public Polygon {
  public:
    int area ()
      { return width * height; }
};

class Triangle: public Polygon {
  public:
    int area ()
      { return (width * height / 2); }
};

int main () {
  Rectangle rect;
  Triangle trgl;
  Polygon * ppoly1 = &rect;
  Polygon * ppoly2 = &trgl;
  ppoly1->set_values (4,5);
  ppoly2->set_values (4,5);
  cout << ppoly1->area() << 'n';
  cout << ppoly2->area() << 'n';
  return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT