引用测试

//
// Created by 刘彪 on 2020/2/29.
//

#include <iostream>
#include <iomanip>
#include <cstdio>
using namespace std;
class Rect {
    int x,y;
    int w,h;
public:
    Rect(int x1,int y1,int w1,int h1){
        x = x1;y = y1;
        w = w1;h = h1;
    }
    void Move(int x1,int y1){x=x1;y=y1;}
    void Size(int w1,int h1){w=w1;h=h1;}
    void Where(int &x1,int &y1){x1 = x;y1=y;}
    int Area(){return w*h;}
};
int main(){
    Rect r(2,3,20,10);
    int x,y;
    cout<<"矩形面积:"<<r.Area()<<endl;
    cout<<"移动到(5,4)"<<endl;
    r.Move(5,4);
    cout<<"改变宽为6,高为3"<<endl;
    r.Size(6,3);
    r.Where(x,y);
    cout<<"左上角:("<<x<<","<<y<<")"<<endl;
    cout<<"矩形面积:"<<r.Area()<<endl;
    return 0;
}


//p118

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务