python3 练习3

##c##写法

#include<iostream>
using namespace std;
class Rectangle{
public:
    int j;
void area(int X=0,int Y=0,int A=0,int B=0);
private:
int x,y,a,b;
};
void Rectangle::area(int X,int Y,int A,int B){
x=X;y=Y;a=A;b=B;
j=(a-x)*(b-y);
 }
 int main(){
int x,y,a,b;
Rectangle rectangle;
cout<<"输入左下角坐标x和y"<<endl;
cin>>x>>y;
cout<<"输入右上角坐标为a和b"<<endl;
cin>>a>>b;
     rectangle.area(x,y,a,b);
cout<<"该矩形面积为:"<<rectangle.j<<endl;
return 0;
 }

## 1

class Rectangle:
def __init__(self,x1=0,y1=0,x2=1,y2=1):
self.x1=x1
self.y1=y1
self.x2=x2
self.y2=y2
def print_area(self,t):
print((t.x2-t.x1)*(t.y2-t.y1))
t=Rectangle()
t.x1=1.0
t.x2=2.1
t.y1=2.0
t.y2=3.2
t.print_area(t)


####

猜你喜欢

转载自www.cnblogs.com/feiyun8616/p/9318781.html