forked from iot-lab-kiit/tasks.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56288da
commit 109b530
Showing
1 changed file
with
79 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,91 @@ | ||
//WAP to find area of a circle, a rectangle and a triangle, using concept of function overloading. | ||
|
||
#include<iostream> | ||
#include<math.h> | ||
|
||
using namespace std; | ||
//Area of circle | ||
float area(float r) | ||
|
||
//Function prototying for the function area. | ||
|
||
float area(int); | ||
|
||
float area(int,int); | ||
|
||
float area(float,float); | ||
|
||
//defining the area function. | ||
|
||
//circle | ||
|
||
float area(int r) | ||
{ | ||
float ret=3.14*pow(r,2); | ||
return ret; | ||
return(3.14 * r * r); | ||
} | ||
//Area of the rectangle | ||
float area(float l,float b) | ||
|
||
//Triangle | ||
|
||
float area(int b,int h) | ||
{ | ||
float ret=l*b; | ||
return ret; | ||
return(0.5 * b * h); | ||
} | ||
//Area of the triangle | ||
float area(float s1,float s2,float s3) | ||
|
||
//Rectangle | ||
|
||
float area(float l,float b) | ||
{ | ||
float t=(s1+s2+s3)/2; | ||
float ret=sqrt(t*(t-s1)*(t-s2)*(t-s3)); | ||
return ret; | ||
return (l * b); | ||
} | ||
|
||
int main() | ||
{ | ||
int ch; | ||
while(1){ | ||
cout<<"\n 1. Area of circle \n"<<"2. Area of reactangle\n"<<"3. Area of triangle\n"<<"Enter your choice: "; | ||
cin>>ch; | ||
switch(ch) | ||
{ | ||
case 1: | ||
{ | ||
float n; | ||
cout<<"\nEnter radius: "; | ||
cin>>n; | ||
cout<<"\nArea of sphere: "<<area(n); | ||
break; | ||
} | ||
case 2: | ||
float b,h,r,l; | ||
int ch; | ||
|
||
do | ||
{ | ||
float l,b ; | ||
cout<<"\nEnter length and bredth of the rectangle: "; | ||
cin>>l>>b; | ||
cout<<"Area of Rectangle: "<<area(l,b); | ||
break; | ||
} | ||
case 3: | ||
{ | ||
float s1,s2,s3; | ||
cout<<"Enter sides of triangle:"; | ||
cin>>s1>>s2>>s3; | ||
cout<<area(s1,s2,s3); | ||
break; | ||
} | ||
default: | ||
cout<<"Invalid Input"; | ||
|
||
} | ||
} | ||
return 0; | ||
} | ||
cout<<"\n Enter.. to find \n"; | ||
|
||
cout<<"\n 1. Area of Circle"; | ||
cout<<"\n 2. Area of Triangle"; | ||
cout<<"\n 3. Area of Rectangle"; | ||
|
||
cout<<"\n 4. Exit from the program "; | ||
|
||
cout<<"\n\n Enter Your Choice : "; | ||
cin>>ch; | ||
switch(ch) | ||
{ | ||
case 1: | ||
{ | ||
cout<<"\n enter the radius for circle: "; | ||
cin>>r; | ||
cout<<"\n area of circle is : "<<area(r); | ||
break; | ||
} | ||
|
||
|
||
case 2: | ||
{ | ||
cout<<"\n enter the base & height of triangle : "; | ||
cin>>b>>h; | ||
cout<<"\n area of triangle is : "<<area(b,h); | ||
break; | ||
} | ||
|
||
case 3: | ||
{ | ||
cout<<"\n enter the length & bredth of rectangle : "; | ||
cin>>l>>b; | ||
cout<<"\n Area of rectangle : "<<area(l,b); | ||
break; | ||
} | ||
|
||
case 4: | ||
exit(0); | ||
default: | ||
cout<<"\n enter a valid choice "; | ||
} | ||
|
||
}while(ch!=4); | ||
|
||
return 0; | ||
} |