Saturday, 6 July 2013

C++ programe to find the area of Rectangle using Class

#include<iostream.h>
#include<conio.h>

class rectangle
{
private:
    float l ;
    float w ;
public:
    void set();
    void print();
    float area();
} ;
void rectangle :: set()
    {
    cout<<"\nEnter the value of Length (then press ENTER key): ";
    cin>>l;
    cout<<"Enter the value of Width (then press ENTER key) : ";
    cin>>w;
    }
void rectangle :: print()
    {
    cout<<"\n\nFormula:";
    cout<<"\nArea of Rectangle = Length * Width";
    }
float rectangle :: area()
    {
    return l*w ;
    }

void main()
{
    clrscr();
    cout<<"\nFinding Area of Rectangle";
    cout<<"\n---------------------------";
    rectangle r ;
    r.set() ;
    r.print() ;
    cout<<"\n\nResult:";
    cout<<"\nArea of Rectangle = "<<r.area();
    cout<<"\n---------------------------";
    cout<<"\n\n\nPress any key to Exit";
    getche() ;
}

No comments:

Post a Comment