using namespace std;
class shape
{
public:
virtual int getA()=0;
int setwid(int wid)
{
width=wid;
}
int sethei(int h)
{
height=h;
}
protected:
int height,width;
};
class rectangle:public shape
{
public:
int getA()
{
return (height*width);
}
} ;
class triangle:public shape
{
public:
int getA()
{
return (height*width/2);
}
};
int main()
{
rectangle r;
triangle t;
r.setheig(7);
r.setwid(5);
cout<<"total rectangle area : "<<r.getA()<<endl;
t.setheig(7);
t.setwid(5);
cout<<"total triangle area : "<<t.getA()<<endl;
return 0;
}
Programs:-
There are programs of Object-Oriented Programing, Operators (logical, arithmethic ,relational,etc) ,exception handeling , inheritance ,string operations ,etc
No comments:
Post a Comment