From bdf182907872da46d32fd857857ba0592d4452e7 Mon Sep 17 00:00:00 2001 From: jatinwatts7130 <161716211+jatinwatts7130@users.noreply.github.com> Date: Fri, 5 Apr 2024 20:22:59 +0530 Subject: [PATCH] Update Lab Performance-2 --- Lab Performance-2 | 143 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/Lab Performance-2 b/Lab Performance-2 index 045b89b..e714f08 100644 --- a/Lab Performance-2 +++ b/Lab Performance-2 @@ -12,3 +12,146 @@ Task-2: An operator overloading allows custom behavior to be defined for built-in operators like addition (+), subtraction (-), when we used with user-defined types. When overloading binary operators as friend functions, external functions can access private members of a class. Provide examples how binary operator overloading is implemented using friend functions. +Task 1:- +#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 j,w; + public: + void get(){ + cout<<"Enter value of j: "; + cin>>j; + cout<<"Enter value of w: "; + cin>>w; + } + friend Overloading operator+(Overloading &obj, Overloading &obj1); + friend Overloading operator-(Overloading &obj, Overloading &obj1); + void display0(){ + cout<<"Addition of J:"<