diff --git a/Lab Performance-2 b/Lab Performance-2 index 045b89b..26582b2 100644 --- a/Lab Performance-2 +++ b/Lab Performance-2 @@ -5,10 +5,146 @@ Each shape has common properties like area and perimeter, but also specific attr • Develop a class hierarchy for geometric shapes using inheritance in C++. • Explain how you would utilize inheritance and polymorphism to implement algorithms for calculating area and perimeter that are specific to each type of shape - +#include +using namespace std; +class Shape{ + public: + void area(){ + + } + void perimeter(){ + + } +}; +class Circle:public Shape{ + double r,area_value,perimeter_value; + public: + Circle(){ + cout<<"Enter value of radius of circle: "; + cin>>r; + area(); + perimeter(); + } + void area(){ + area_value=3.14*r*r; + } + void perimeter(){ + perimeter_value=2*3.14*r; + } + void display(){ + cout<<"Area of circle:"<>len; + cout<<"Enter breadth of rectangle:"; + cin>>bre; + area(); + perimeter(); + } + void area(){ + area_value=len*bre; + } + void perimeter(){ + perimeter_value=2*(len+bre); + } + void display(){ + cout<<"Area of rectangle:"<>hei; + cout<<"Enter base or side1 of triangle:"; + cin>>side1; + cout<<"Enter side2 of triangle:"; + cin>>side2; + cout<<"Enter side3 of triangle:"; + cin>>side3; + area(); + perimeter(); + } + void area(){ + area_value=0.5*hei*side1; + } + void perimeter(){ + perimeter_value=side1+side2+side3; + } + void display(){ + cout<<"Area of triangle:"< +using namespace std; +class Overloading{ + int a,b; + public: + void get(){ + cout<<"Enter value of A: "; + cin>>a; + cout<<"Enter value of B: "; + cin>>b; + } + friend Overloading operator+(Overloading &obj, Overloading &obj1); + friend Overloading operator-(Overloading &obj, Overloading &obj1); + void display(){ + cout<<"Addition of A:"<