1

Computing Area of Different Shapes (Id-1326)

Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]

Just for Practice 4 Additional [8-Jan-2018 to 31-Mar-2018]

Program ID- 1326

The area is the two-dimensional amount of space that an object occupies. Area is measured along the surface of an object and has dimensions of length squared; for example, square feet of material, or centimetres squared.
The area of a rectangle is equal to the height h times the base b; A = h * b
The equation for the area of a trapezoid is one half the sum of the top t and bottom b times the height h; A = h * [ t + b ] / 2
The area of a circle is A = pi * r2, where pi = 3.14 and r = radius.
Develop a program in C++ using function overloading for computing the area of a rectangle, a trapezoid and a circle by a common function name ComputeArea() with different signature. Assume pi = 3.14. Print only two decimal places for all areas.
Note:
To print only two decimal places of a variable ‘a’, do the following:
#include<iomanip>
cout<<fixed<<setprecision(2)<<a;

Input Format:
Read the base and height of a rectangle.
Read the top, bottom and height of a trapezoid.
Read the radius of a circle.

Output Format:
Display the area of a rectangle, trapezoid and circle each in one line

Boundary Conditions:
You can give any valid integer or float values for inputs.

Code

Please Comment Working if the code worked to you

If you have other working codes please comment the codes enclosing with <pre> and </pre> 🙂

Example: <pre> Your Code </pre>

C++ Code [By Chir Patel]

 

The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

 

Click Here to Leave a Comment Below 1 comments
jeevan - February 16, 2018

#include
using namespace std;
#include
#include
float area(float len,float bre)
{
double a;
a=len*bre;
}
float area(float top,float bottom,float height)
{
float k,p;
double a;
k=bottom+top;
p=k/2;
a=height*p;
}
float area(float radius)
{
double a;
a=3.14*radius*radius;
}




4



0

Reply

Leave a Reply:

This site uses cookies and by using the site you are consenting to this.