• 面向对象的程序设计第五次作业


    #include <bits/stdc++.h>
    using namespace std;
     
    struct Point
    {
        int x;
        int y;
    };
     
    void displayMenu() {
        for (int i = 0; i < 32; ++i)
            cout << "*";
        cout << endl;
        cout << "    1.Circle(圆)" << endl;
        cout << "    2.Rectangle(长方形)" << endl;
        cout << "    0.Exit(退出)" << endl;
        for (int i = 0; i < 32; ++i)
            cout << "*";
        cout << endl;
        cout << "Please select the shape:";
    }
     
    // void getTwoPoints(struct Point * P1, struct Point * P2) {
         
    // }
     
    // void printPoint(struct Point *) {
     
    // }
     
    void drawCircle(struct Point * P1, struct Point * P2) {
        if (P2 -> x - P1 -> x == P2 -> y - P1 -> y) {
            cout << "Draw a circle at center (" << (P1 -> x + P2 -> x) / 2 << "," << (P2 -> y + P1 -> y) / 2 << ")" << "with radius " << (P2 -> x - P1 -> x) / 2 << endl;
        }
        else {
            cout << "Not a circle, select again" << endl;
        }
     
    }
     
    void drawRectangle(struct Point * P1, struct Point * P2) {
        cout << "Draw a rectangle at toleft(" << P1 -> x << "," << P1 -> y << "), whose width is " <<  P2 -> x - P1 -> x << " and height is " << P2 -> y - P1 -> y << endl;
    }
     
    int main () {
        int choice;
        struct Point startP, endP;
        while (choice) {
            displayMenu();
            cin >> choice;
                switch (choice) {
            case 1:
                cout << "Please input the coordinate(x,y)of the start point:";
                cin >> startP.x >> startP.y;
                cout << "Please input the coordinate(x,y)of the end point:";
                cin >> endP.x >> endP.y;
                if (endP.x <= startP.x || endP.y <= startP.y){
                    cout << "输入点的坐标存在问题,请重新输入!" << endl; 
                    break;
                }
                //getTwoPoints(&startP, &endP);
                drawCircle(&startP, &endP);
                break;
            case 2:
                cout << "Please input the coordinate(x,y)of the start point:";
                cin >> startP.x >> startP.y;
                cout << "Please input the coordinate(x,y)of the end point:";
                cin >> endP.x >> endP.y;
                if (endP.x <= startP.x || endP.y <= startP.y){
                    cout << "输入点的坐标存在问题,请重新输入!" << endl; 
                    break;
                }
                //getTwoPoints(&startP, &endP);
                drawRectangle(&startP, &endP);
                break;
            case 0:
                cout << "Good Bye!
    ";
                break;
            default:
                cout << "Not supported! Please select again!
    ";
                break; 
            }
        }
        return 0;
    }
    // //测试样例
    // 1
    // 5 20
    // 15 30
    // 1
    // 5 20
    // 15 25
    // 2
    // 3 10
    // 20 30
    // 3
    // 0
    
    #include <bits/stdc++.h>
    
    using namespace std;
    
    struct Rule
    {
        double money;
        double rate;
    };
    
    void showMenu() {
        cout << "请输入规则的条数:" << endl;;
    }
    
    double computeTax(struct Rule rules[], int n, double income) {
        double ans = 0;
        for (int i = n; i >= 1; i--) {
            if (income > rules[i].money) {
                ans += (income - rules[i].money) * rules[i].rate / 100;
                while (i - 1) {
                    ans += (rules[i].money - rules[i - 1].money) * rules[i - 1].rate / 100;
                    i--;
                }
                break;
            }
        }
        return ans;
    }
    
    int main () {
        showMenu();
        int N = 0;
        cin >> N;
        struct Rule rule[10];
        for (int i = 1; i <= N; ++i) {
            cout << "请输入第" << i << "条规则:";
            cin >> rule[i].money >> rule[i].rate;
        }
    
        double income;
        cout << "请输入您的收入:";
        cin >> income;
        while (income != -1) {
            cout << "您的收入是:" << income << ",";
            cout << "应缴所得税:" << fixed << setprecision(2) << computeTax(rule, N, income) << "元。";
            cout << endl;
            cout << "请输入您的收入:";
            cin >> income;
        }
        cout << "再见" << endl;
    }
    // 3
    // 800 3
    // 2000 4
    // 5000 3
    // 0
    // 800
    // 801
    // 2000
    // 1999
    // 5000
    // 10000
    // -1
    
    作者:LightAc
    出处:https://www.cnblogs.com/lightac/
    联系:
    Email: dzz@stu.ouc.edu.cn
    QQ: 1171613053
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
  • 相关阅读:
    python——实现三级菜单选择的功能(原创)
    Python之路购物车
    Python基础介绍
    python登陆接口编写
    Oculus Store游戏下载默认路径修改方法
    【转载】关于api-ms-win-crt-runtimel1-1-0.dll缺失的解决方案
    安装Appium
    ASP.NET之MVC 微信公众号授权给第三方平台的技术实现流程一(获取第三方平台access_token)
    C# 利用反射更改父类公开对象
    mysql 根据某个值叠加查询
  • 原文地址:https://www.cnblogs.com/lightac/p/10681845.html
Copyright © 2020-2023  润新知