C++ program to demonstrate Class and Object

//Class Rectangle with length and breadth as private members
//and appropriate member functions to read data, calculate and display area
#include <iostream>
using namespace std;
class Rectangle
{
    private:
        float l,b,a;
    public:
        void ReadData()
        {
            cout<<"Enter length and breadth: ";
            cin>>l>>b;
        }
        void CalculateArea()
        {
            a=l*b;
        }
        void DisplayArea()
        {
            cout<<"The area is "<<a;
        }
};
int main()
{
    Rectangle r1;
    r1.ReadData();
    r1.CalculateArea();
    r1.DisplayArea();
    return 0;
}

No comments:

Post a Comment