题解 | 类的应用 | 比较长方形的面积大小
比较长方形的面积大小
https://www.nowcoder.com/practice/61e0c4069baf474db635cd492ac9ba9c
#include<bits/stdc++.h>
using namespace std;
class rectangle{
private:
int length,width;
public:
void set(int x,int y){
length=x;
width=y;
}
int getlength(){
return length;
}
int getwidth(){
return width;
}
int area(){
return length*width;
}
void compare(rectangle a){
// write your code here......
if(area() > a.area()){
cout<<1;
}else{
cout<<0;
}
}
};
int main(){
int l1,w1,l2,w2;
cin>>l1>>w1>>l2>>w2;
rectangle a,b;
a.set(l1,w1);
b.set(l2,w2);
a.compare(b);
return 0;
}
C/C++题解 文章被收录于专栏
记录个人编程题的解题思路以及学习的新知识
腾讯成长空间 6071人发布