2020/3/13_C++实验课

#include <iostream>
#include <cmath>
using namespace std;
double calcualateCircle(double r = 0) {
    return acos(-1) * r * r;
}

double calcualateRectangle(double len = 0, double high = 0) {
    return len * high;
}


double calcualateSquare(double len = 0) {
    return len * len;
}
int main()
{
    cout << "请输入用户选择图形的类型" << endl;
    cout << "1.圆形   2.长方形   3.正方形" << endl;
    int choice;
    cin >> choice;
    switch (choice){
        case 1:
            cout << "请输入圆形的半径:" << endl;
            double r;
            cin >> r;
            cout << calcualateCircle(r) << endl;
            break;
        case 2:
            cout << "请输入长方形的宽和高:" << endl;
            double len, high;
            cin >> len >> high;
            cout << calcualateRectangle(len, high) << endl;
            break;
        case 3:
            cout << "请输入正方形的边长:" << endl;
            double l;
            cin >> l;
            cout << calcualateSquare(l) << endl;
            break;
        default:
            cout << "输入错误" << endl;
    }
    return 0;
}

 

posted @ 2020-03-13 09:06  LightAc  阅读(215)  评论(0编辑  收藏  举报
返回顶端