#include <iostream>
using namespace std;
class Shape
{
protected:
int A;
public:
Shape()
{
A=0;
}
void show();
};
class Triangle:public Shape
{
int h, b;
public:
void Geth();
void Getb();
void Showhb();
void CalTriA();
};
class Rectangle:public Shape
{
int l, b;
public:
void Getl();
void Getb();
void Showlb();
void CalRecA();
};
void Shape::show()
{
cout << endl << "Area=" << A << endl ;
}
void Triangle::Geth()
{
cout << endl << "Enter height of the triangle:" ;
cin >> h ;
}
void Triangle::Getb()
{
cout << endl << "Enter base of the triangle:" ;
cin >> b ;
}
void Triangle::Showhb()
{
cout << endl << "Triangle:" << endl ;
cout << "Height=" << h << endl << "Base=" << b << endl ;
}
void Triangle::CalTriA()
{
A = (h*b)/2;
}
void Rectangle::Getl()
{
cout << endl << "Enter length of Rectangle:" ;
cin >> l ;
}
void Rectangle::Getb()
{
cout << endl << "Enter breadth of Rectangle:" ;
cin >> b ;
}
void Rectangle::Showlb()
{
cout << endl << "Rectangle" << endl ;
cout << "Length=" << l << endl << "Breadth=" << b << endl ;
}
void Rectangle::CalRecA()
{
A = l*b ;
}
int main()
{
Triangle T;
T.Geth();
T.Getb();
Rectangle R;
R.Getl();
R.Getb();
T.Showhb();
T.CalTriA();
T.show();
R.Showlb();
R.CalRecA();
R.show();
return 0;
}
C and C++ programs, games, softwares. Easy programming guide. Learn to code and enjoy coding in CoderNepal
Home » OOPL T.U. 2068 Q.N.3
OOPL T.U. 2068 Q.N.3
This is the solution for T.U.2068 Q.N.3
Subscribe to:
Comments (Atom)
No comments:
Post a Comment