Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
2.6 kB
4
Indexable
Never
#include<iostream>
using namespace std;

class Rectangle {
private:
    static int num;
    float width;
    float length;
    //Rectangle **aaa;

public:
    
    void setObj();
    
    Rectangle() {
        num++;
        set(0,0);
        
    }
    Rectangle(float w){
        num++;
        set(w,0);
    }
    Rectangle(float w,float l){
        num++;
        set(w,l);
        
    }
    ~Rectangle(){
        num--;
    cout<<"bye bye"<<num<<endl;
}
    
    void set (float w,float l){
        width=w;
        length=l;
    }
    
    void setWidth(float w){
        width=w;
    }
    void setLength(float l){
        length=l;
    }
    
    
    
    float getWidth(){
        return width;
    }
    
   float getLength(){
        return length;
    }
    
    float getArea(){
        float area=width*length;
        return area;
    }
    
    float getPerimeter(){
        float perimeter=2*(width+length);
        return perimeter;
    }
    
    void show(void);
   // void add(Rectangle);
    
    static int count(){
       return num;
        
   }

};

class MyRectangle{
    Rectangle **rectArray;
    
};


//int getArea(){
    
  //  total=(width*length);
    //return total;
    //srl=2*total;
//}



void Rectangle::show(){
    cout<<"Width ="<<width<<endl;
    cout<<"Length ="<<length<<endl;
    cout<<"Square area ="<<getArea()<<endl;
    cout<<"Square round length ="<<getPerimeter()<<endl;
    
    cout<<endl;
}



int Rectangle:: num;



int main(){
    cout<<Rectangle::count()<<endl;
    Rectangle aRectangle;
    aRectangle.show();
    
    
    cout<<Rectangle::count()<<endl;
    Rectangle bRectangle(2);
    bRectangle.show();
    cout<<"-----------"<<endl;
    bRectangle.setWidth(1);
    bRectangle.show();
    cout<<"-----------"<<endl;
    cout<<"GetArea = "<<bRectangle.getArea()<<endl;
    cout<<"GetPerimeter = "<<bRectangle.getPerimeter()<<endl;
    cout<<"GetLength = "<<bRectangle.getLength()<<endl;
    cout<<"GetWidth = "<<bRectangle.getWidth()<<endl;
    cout<<"-----------"<<endl;
    
    cout<<Rectangle::count()<<endl;
    Rectangle cRectangle(3,4);
    cRectangle.show();
    cout<<"-----34------"<<endl;
    cRectangle.setWidth(1);
    cRectangle.setLength(2);
    cRectangle.show();
    cout<<"-----12------"<<endl;
    cRectangle.set(1,1);
    cRectangle.show();
    cout<<"-----11------"<<endl;
    cout<<"GetArea = "<<cRectangle.getArea()<<endl;
    cout<<"GetPerimeter = "<<cRectangle.getPerimeter()<<endl;
    cout<<"GetLength = "<<cRectangle.getLength()<<endl;
    cout<<"GetWidth = "<<cRectangle.getWidth()<<endl;
    
    cout<<"-----------"<<endl;
    
    
}