Problem statement:
write a cpp program to create a class shape,with data members side1,side2 and the member functions get data and put data, derive a class rectangle from shape class and find out the area of rectangle.
program:
#include<iostream>
using namespace std;
class shape
{
protected:float side1,side2;
public:void getdata()
{
cout<<"enter the length and breadth of the rectangle"<<endl;
cin>>side1>>side2;
}
void putdata()
{
cout<<"length="<<side1<<" "<<"breadth="<<side2;
}
};
class rectangle:public shape
{
float area1;
public:void area()
{
area1=side1*side2;
cout<<endl<<"area="<<area1;
}
};
main()
{
rectangle r;
r.getdata();
r.putdata();
r.area();
}
output : executed in code blocks for c plus plus
write a cpp program to create a class shape,with data members side1,side2 and the member functions get data and put data, derive a class rectangle from shape class and find out the area of rectangle.
program:
#include<iostream>
using namespace std;
class shape
{
protected:float side1,side2;
public:void getdata()
{
cout<<"enter the length and breadth of the rectangle"<<endl;
cin>>side1>>side2;
}
void putdata()
{
cout<<"length="<<side1<<" "<<"breadth="<<side2;
}
};
class rectangle:public shape
{
float area1;
public:void area()
{
area1=side1*side2;
cout<<endl<<"area="<<area1;
}
};
main()
{
rectangle r;
r.getdata();
r.putdata();
r.area();
}
output : executed in code blocks for c plus plus