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 编写一个rectangle 类,属性为左上角和右下角的坐标,编写方法,计算矩形面积
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)
#### 编写一个stu 类,属性包括学号,和三门成绩,编写方法,输出平均成绩,并输出是否通过。
class stud:
stuid=''
score1=''
score2=''
score3=''
def setstuid(self,stuid):
self.stuid=stuid
def setscore1(self,score1):
self.score1=score1
def setscore2(self,score2):
self.score2=score2
def setscore3(self,score3):
self.score3=score3
def getstuid(self,stuid):
return self.stuid
def getscore1(self,score1):
return self.score1
def getscore2(self,score2):
return self.score2
def getscore3(self,score3):
return self.score3
def addstudent():
stu=stud()
stuid=input('请输入学号id:')
stu.setstuid(stuid)
score1 = input('请输入成绩一:')
stu.setscore1(score1)
score2 = input('请输入成绩二:')
stu.setscore2(score2)
score3 = input('请输入成绩三:')
stu.setscore3(score3)
avg=(int(stu.score1)+int(stu.score2)+ int(stu.score3))/3
print(avg)
if int(stu.score1) < 60:
print('failed')
elif int(stu.score2) < 60:
print('failed')
elif int(stu.score3) < 60:
print('failed')
else:
print('passwd')
addstudent()
炊烟起了;夕阳下了;细雨来了
多调试,交互式编程体验
记录,独立思考,对比
感谢转载作者
修车
国产化
read and connect
匍匐前进,
讲故事