Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Rectangle{
- private:
- int width;
- int height;
- public:
- Rectangle(){set(0,0);}
- Rectangle(int w,int h){set(w,h);}
- void set(int w,int h){width = w;height = h;}
- int getWidth(){
- return width;
- }
- int getHeight(){
- return height;
- }
- void show(void);
- int RecArea();
- int PerLength();
- };
- void Rectangle::show(){
- cout<<"Width = "<<width<<endl;
- cout<<"height = "<<height<<endl;
- }
- int Rectangle::RecArea(){
- return width*height;
- }
- int Rectangle::PerLength(){
- return (width+height)*2;
- }
- int main(){
- Rectangle rect;
- rect.set(3,4);
- rect.show();
- cout<<"Rectangle area = "<<rect.RecArea()<<endl;
- cout<<"Rectangle length = "<<rect.PerLength()<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement