Note:- If you are looking for simple program of area of shapes(not using function), please see this.
else continue here……
This is a tutorial of area of different shapes using function. The simple program(not using function) link is given above. The Program using function is given below. The program is extendable. Go enjoy the program. Lets begin…..
Program to find area of different shapes using function
//clear the screen.
//declare variables as int.
//Input the radius, sides and length and breadth.
cout<<“Enter the radius of circle”<<endl;
cout<<“Enter the side of square”<<endl;
cout<<“Enter the length and breadth of rectangle”<<endl;
//calculate area using functions and print it.
cout<<“Area of circle is “<<cir(r)<<endl;
cout<<“Area of square is “<<sq(a)<<endl;
cout<<“Area of rectangle is “<<rec(l,b)<<endl;
float cir(float x)
float sq(float x)
float rec(float x,float y)
Enter the radius of circle
Enter the side of square
Enter the length and breadth of rectangle
Area of circle is 3.14
Area of square is 25
Area of rectangle is 20
How does it work
- You enter the necessary inputs.
- The function calculates the area.
- The area is printed.
The program can be extended by using more different shapes of geometry. You can take the necessary inputs and calculate the area of the given geometry and add there respective functions at end. Even you can do the same program to find the perimeter of different shapes.
- Include ‘iostream.h’ and ‘conio.h’ files.
- Declare the function prototype.
- Add void main.
- Start program by first clearing the screen.
- Declare the variables as int (name them as you want.)
- Add the cout and cin of necessary shapes.
- Add the cout of area and call the function.
- Add the function definition outside the void main().
At the end
You learnt creating the C++ program of Area of different shapes using function. So now enjoy the program.
Please comment on the post and share it.
And like it if you liked.