Monday, September 24, 2018

Inheritance: program 1

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

Introduction about this page

This web page is going to provide you with the c++ programming language program(solutions) with various problem statements every day!.

Inheritance: program 1

Problem statement: write a cpp program to create a class shape,with data members side1,side2 and the member functions get data and put dat...