WAP with classes to represent circle, rectangle and triangle. Each classes should have data members to represent the actual objects and member functions to read and display objects, find perimeter and area of the objects with other useful functions. Use the classes to created objects in your program.
---------------------------------------------------------------------------------------------
Program:
#include<iostream.h>
#include<conio.h>
#define pi 3.1415
class circle
{
float r;
public:
void areaper()
{
cout<<"CIRCLE"<<endl;
cout<<"enter
radius=";
cin>>r;
cout<<"area="<<pi*r*r<<endl;
cout<<"perimeter"<<2*pi*r<<endl;
}
};
class rectangle
{
float l,b;
public:
void areaper()
{ cout<<"RECTANGLE"<<endl;
cout<<"enter
length and breadth=";
cin>>l>>b;
cout<<"area="<<l*b<<endl;
cout<<endl<<"perimeter="<<2*(l+b)<<endl;
}
};
class triangle
{
float ba,h,a,b,c;
public:
void areaper()
{
cout<<"TRIANGLE"<<endl;
cout<<"enter
base and height";
cin>>ba>>h;
cout<<"area="<<0.5*ba*h;
cout<<"enter
sides of the triangle";
cin>>a>>b>>c;
cout<<"perimeter="<<a+b+c;
}
};
void main()
{
clrscr();
circle cir;
rectangle rec;
triangle tri;
cir.areaper();
rec.areaper();
tri.areaper();
getch();
}
Output:
errrooorrrrr
ReplyDelete