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.
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>
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.
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>
Code: C++
#include<iostream>
using namespace std;
#include<iomanip>
float area(float a, float b=0, float c=0)
{
double area;
float pi=3.14;
if(b==0 && c==0)
area=pi*a*a;
else if(c==0)
area=a*b;
else
area=c*(a+b)/2;
return area;
}
using namespace std;
#include<iomanip>
float area(float a, float b=0, float c=0)
{
double area;
float pi=3.14;
if(b==0 && c==0)
area=pi*a*a;
else if(c==0)
area=a*b;
else
area=c*(a+b)/2;
return area;
}
NOTE: The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.
No comments:
Post a Comment