Â
The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include<conio.h>
class Area
{
public:
float baseBelow, baseAbove, height, area;
Area(float b1, float b2, float h)
{
baseBelow = b1;
baseAbove = b2;
height = h;
}
void display()
{
area = ((baseBelow + baseAbove) / 2) * height;
cout << "Area of the trapezium is:- " << area;
}
};
void main()
{
clrscr()
float b1, b2, h;
cout << "Enter the dimensions of the trapezium.\nAbove base (a) = ";
cin >> b1;
cout << "Below Base (b) = ";
cin >> b2;
cout << "Height = ";
cin >> h;
Area obj(b1, b2, h);
obj.display();
getch();
}
//..........Coded by YASH ALAPURIA
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
class Area
{
public:
float baseBelow, baseAbove, height, area;
Area(float b1, float b2, float h)
{
baseBelow = b1;
baseAbove = b2;
height = h;
}
void display()
{
area = ((baseBelow + baseAbove) / 2) * height;
cout << "Area of the trapezium is:- " << area;
}
};
int main(void)
{
float b1, b2, h;
cout << "Enter the dimensions of the trapezium.\nAbove base (a) = ";
cin >> b1;
cout << "Below Base (b) = ";
cin >> b2;
cout << "Height = ";
cin >> h;
Area obj(b1, b2, h);
obj.display();
}
//..........Coded by YASH ALAPURIA
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP