Limited_Ice

shapes.h

May 16th, 2021
661
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma once
  2. class shape {
  3. protected:
  4.     double height, width;
  5.     virtual void area() = 0;
  6. };
  7.  
  8. class rectangle : shape {
  9. public:
  10.     rectangle() {
  11.         cout << "what is your rectangles's height: ";
  12.         cin >> height;
  13.         cout << "what is your rectangle's width: ";
  14.         cin >> width;
  15.         this->area();
  16.     }
  17. private:
  18.     void area(){
  19.         cout << "the area of your rectangle is: " << height * width << endl;
  20.     }
  21. };
  22.  
  23. class triangle : shape {
  24. public:
  25.     triangle() {
  26.         cout << "what is your triangle's height: ";
  27.         cin >> height;
  28.         cout << "what is your triangles width: ";
  29.         cin >> width;
  30.         this->area();
  31.     }
  32. private:
  33.     void area() {
  34.         cout << "the area of your triangle is: " << width / 2 * height << endl;
  35.     }
  36. };
RAW Paste Data