Posts

Showing posts from March, 2021

Area of Polygon using C++ Inheritance

/* This is a menu-based program where the user will choose an option in the menu to find the area Base Class: Polygon Sub Base Class: Triangle, Qudrangle, Pentagon Sub Sub Base Class (Qudrangle): Rectangle, Square, Parallelogram */  #include <iostream> using namespace std; class polygon{ protected:     int length, height;     float area; public:     void input(){     cout << "Enter the length and height of polygon: ";     cin >> length >> height;     }     void display(){     cout << "Length: " << length << " units" << endl;     cout << "Height: " << height << " units" << endl;     cout << "Area: " << area << " units square" << endl;     } }; class triangle : public polygon{ public:     void area_of_polygon(){     input();     area = 0.5*length*heigh...