#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: printf("请输入圆形的半径:"); double r; cin >> r; cout << calcualateCircle(r) << endl; case 2: printf("请输入长方形的宽和高:"); double len, high; cin >> len >> high; cout << calcualateRectangle(len, high) << endl; case 3: printf("请输入正方形的边长:"); double l; cin >> l; cout << calcualateSquare(l) << endl; } return 0; }
来源:https://www.cnblogs.com/lightac/p/12484376.html