zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    Java 单链表的倒置
    Android查询:模拟键盘鼠标事件(adb shell 实现)
    安卓 发送短信两种方式
    java tcp socket实例
    Java中读取某个目录下的所有文件和文件夹
    Android剖析和运行机制
    linux下搭建android NDK开发环境
    把log存起来
    判断Android系统net和wap接入点的开发实例
    android 4.0.4系统下实现apk的静默安装和启动
  • 原文地址:https://www.cnblogs.com/feiyun8616/p/9318781.html
Copyright © 2011-2022 走看看