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]
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.
To print only two decimal places of a variable ‘a’, do the following:
Read the base and height of a rectangle.
Read the top, bottom and height of a trapezoid.
Read the radius of a circle.
Display the area of a rectangle, trapezoid and circle each in one line
You can give any valid integer or float values for inputs.
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]
using namespace std;
float area(float a, float b=0, float c=0)
if(b==0 && c==0)