#include <iostream> using namespace std; class Polygon { public: double width, height; void val(double a, double b) { width=a; height=b; } }; class Rectangle: public Polygon{ public: double Rect() { return height*width; } }; class Triangle: public Polygon{ public: double trig() { return height*width*0.5; } }; int main() { Rectangle Rec; Triangle Tri; Rec.val(5,6); cout<<Rec.Rect()<<endl; Tri.val(5,6); cout<<Tri.trig()<<endl; system("pause"); return 0; }The output is given below:
30 15
0 comments:
Post a Comment