题目描述:
(1)能完成任意两个数的四则运算(加、减、乘、除)。
(2)能完成三角函数运算(sin(x),cos(x),tan(x),sin-1(x),cos-1(x),tan-1(x)。
(3)能完成对数运算(lnx,log10x)。
(4)其它运算(ex,平方分计算,xy)。
(5)系统以菜单方式工作,每个功能里的运算用二级菜单实现,例如:加、减、乘、除
的选择需用二级菜单提示。
另:(1)q=1,代表执行第一种操作,依次类推可知q变量的作用;m和p变量与q变量的作用一样
(2)该题目大多数操作均可以通过调用函数完成
(3)这里出于习惯将变量都定义成了double类型
(4)执行第二种操作时,x指代弧度。以sin (x) 为例,当x等于30时,输出的结果是-0.988032(四舍五入后的结果)
代码:
#include <cstdio> #include <cmath> #include <cstring> #include <iostream> using namespace std; const ?double pi = 3.1415926; string sh;//定义字符串变量sh
int main() { ?? ?int q; ?? ?scanf("%d", &q); ?? ?if (q == 1) { ?? ??? ?double a, b; ?? ??? ?char c; ?? ??? ?scanf("%lf%c%lf", & a, & c, &b); ?? ??? ?if (c == '+') { ?? ??? ??? ?printf("%lf\n", a + b); ?? ??? ?} else if (c == '-') { ?? ??? ??? ?printf("%lf\n", a - b ); ?? ??? ?} else if (c == '*') { ?? ??? ??? ?printf("%lf\n", a * b); ?? ??? ?} else if (c == '/') { ?? ??? ??? ?printf("%lf\n", a / b * 1.0); ?? ??? ?} ?? ?} else if (q == 2) { ?? ??? ?double x; ?? ??? ?cin >> sh; ?? ??? ?scanf("%lf", &x); ?? ??? ?if (sh == "sin") ?? ??? ??? ?printf("%lf\n", sin(x)); ?? ??? ?if (sh == "cos") ?? ??? ??? ?printf("%lf\n", cos(x)); ?? ??? ?if (sh == "tan") ?? ??? ??? ?printf("%lf\n", tan(x)); ?? ??? ?if (sh == "asin") ?? ??? ??? ?printf("%lf\n", asin(x)); ?? ??? ?if (sh == "acos") ?? ??? ??? ?printf("%lf\n", acos(x)); ?? ??? ?if (sh == "atan") ?? ??? ??? ?printf("%lf\n", atan(x)); ?? ?} else if (q == 3) { ?? ??? ?double x; ?? ??? ?scanf("%lf", &x); ?? ??? ?int m; ?? ??? ?cin >> m; ?? ??? ?if (m == 1) ?? ??? ??? ?printf("%lf\n", log10(x)); ?? ??? ?if (m == 2) ?? ??? ??? ?printf("%lf\n", log(x)); ?? ?} else if (q == 4) { ?? ??? ?int p; ?? ??? ?cin >> p; ?? ??? ?double x, y; ?? ??? ?if (p == 1) { ?? ??? ??? ?scanf("%lf", &x); ?? ??? ??? ?printf("%lf\n", exp(x));//exp函数求e的x次方 ?? ??? ?} ?? ??? ?if (p == 2) { ?? ??? ??? ?scanf("%lf", &x); ?? ??? ??? ?printf("%lf\n", x * x); ?? ??? ?} ?? ??? ?if (p == 3) { ?? ??? ??? ?scanf("%lf %lf", &x, &y); ?? ??? ??? ?printf("%lf\n", pow(x, y));//pow函数求x的y次方 ?? ??? ?} ?? ?} ?? ?return 0; }
如果出现问题,欢迎指正呀
|