Program to find area of rectangle & Perimeter


#include<iostream.h>
#include<conio.h>
class rectangle
{
         private :
                int len, br;
         public:
               void area_peri( );       //prototype declaration, to be defined
    void getdata ( )
    {
        cout<<endl<<"Enter length and breadth ";
        cin>>len>>br;
    }
        void setdata (int l, int b )
        {
            len = l;
            br = b;
        }
         void displaydata( )
        {
            cout<<endl<<"length = "<<len;
            cout<<endl<<"breadth = "<<br;
        }
    };
    //………………Member Function Definition…………………
    void rectangle :: area_peri( )
    {
        int a, p;
        a = len * br;
        p = 2 * (len +br);
        cout<<endl<<"Area = "<<a;
        cout<<endl<<"Perimeter = "<<p;
    }
    //………………Main Program……………………..                          
    void main( )
    {
    rectangle r1,r2,r3;             //define 3 objects of class rectangle
    r1.setdata(10,20);            //set data in elements of the object
    r1.displaydata( );             //display the data set by setdata( )
    r1.area_peri( );                // calculates and print area and Perimeter
    r2.setdata(5,8);           
    r2.displaydata( );            
    r2.area_peri( ); 
    r3.getdata( );                   //receive data from keyboard          
    r3.displaydata( );            
    r3.area_peri( ); 
    }

1 comments:

Anonymous said...

I'd like to find out more? I'd love to find out more details.


Have a look at my web-site ... best cellulite treatment

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|