永发信息网

C语言实训--计算器的实现

答案:2  悬赏:70  手机版
解决时间 2021-06-02 11:28

1运动浮点数进行简单的加减乘除。最后可以计算其混合运算。

2可能会随时追问

3急用。分会高。

最佳答案
已经给你发了 有问题可以不找老师 直接找我!反正我这里已经顺利运行了,如果想把结果显示在那计算器的显示器里 你就告诉我 我帮你改
全部回答

// 101.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <conio.h> #include <cmath> #include "windows.h" #define PI 3.1415926 using namespace std;

void gotoxy(int x,int y)     {  HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);       COORD   coordScreen={x,y};       SetConsoleCursorPosition(hConsole,coordScreen);     return;   } 

void setcolor(unsigned short ForeColor,unsigned short BackColor)     // 0--黑  1--暗蓝 2--暗绿  3--暗青  4--暗红  5--暗紫 6--蟹黄  7--暗白     // 8--灰  9--亮蓝 10-亮绿  11-亮青  12-亮红  13-亮紫 14-黄    15-亮白 {  HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hCon,(ForeColor % 16)|(BackColor % 16 * 16)); };  

double plus(void) {double a,b,c;char p; setcolor(15,3); system("cls");  cout<<"    made by Huang Shaoying" ; gotoxy(15,10); cout<<"please input a,b:    ";

cin>>a>>b; c=a+b; gotoxy(15,13);cout<<a<<"  +  "<<b<<"  =   "<<c<<endl<<endl<<endl; cout<<"    按  任  意  键  返  回  主  菜  单    "; p=getche( ); return c;}

double minus(void ) {double a,b,c;char p; setcolor(10,1); system("cls"); cout<<"    made by Huang Shaoying" ;  gotoxy(15,10); cout<<"please input a,b:    "; cin>>a>>b; c=a-b; gotoxy(15,13);cout<<a<<"  -  "<<b<<"  =  "<<c<<endl<<endl<<endl; cout<<"    按  任  意  键  返  回  主  菜  单    "; p=getche( ); return c;}

double multiply(void ) {double a,b,c;char p; setcolor(4,15); system("cls");  cout<<"    made by Huang Shaoying" ; gotoxy(15,10); cout<<"please input a,b:    "; cin>>a>>b; c=a*b; gotoxy(15,13);cout<<a<<" * "<<b<<"  =  "<<c<<endl<<endl<<endl; cout<<"    按  任  意  键  返  回  主  菜  单    "; p=getche( ); return c;}

double divide( void) {double a,b,c;char p; setcolor(15,4);  system("cls"); cout<<"    made by Huang Shaoying" ; gotoxy(15,10); cout<<"please input a,b:    "; cin>>a>>b; c=a/b; gotoxy(15,13);cout<<a<<"  /  "<<b<<"  =  "<<c<<endl<<endl<<endl; cout<<"    按  任  意  键  返  回  主  菜  单    "; p=getche( ); return c;}

long f(int n) {long t; if(n<=1) t=1; else t=n*f(n-1); return t; }

long fun (void) {int a;long b;char p; setcolor(0,5);  system("cls"); cout<<"    made by Huang Shaoying" ; gotoxy(15,10); cout<<"please input a:    "; cin>>a; b=f(a); gotoxy(15,13);cout<<a<<" !  =   "<<b<<endl<<endl<<endl; cout<<"    按  任  意  键  返  回  主  菜  单    "; p=getche( ); return b;}

double sin (void )

{int flag=1;char p; double a,a1,b; setcolor(14,8); system("cls"); cout<<"    made by Huang Shaoying" ;  gotoxy(15,10); cout<<"please input a:    "; cin>>a;a1=a; while (a>3*PI/2 ) a-=2*PI; while (a<(-PI/2) ) a+=2*PI; while  (a>PI ) {a-=PI;flag=-1;} while  (a>PI/2) {a-=PI;flag=-1;} b=flag*(a-a*a*a/f(3)+a*a*a*a*a/f(5)-a*a*a*a*a*a*a/f(7)+a*a*a*a*a*a*a*a*a/f(9)-a*a*a*a*a*a*a*a*a*a*a/f(11)); gotoxy(15,13);cout<<"sin "<<a1<<"  =  "<<b<<endl<<endl<<endl; cout<<"    按  任  意  键  继  续    "; p=getche( ); return b;}

double cos(void) {int flag=1;char p; double a,a1,b; setcolor(1,7); system("cls"); cout<<"    made by Huang Shaoying" ; gotoxy(15,10); cout<<"please input a:    "; cin>>a;a1=a; a=PI/2-a; while (a>3*PI/2 ) a-=2*PI; while (a<(-PI/2) ) a+=2*PI; while  (a>PI ) {a-=PI;flag=-1;} while  (a>PI/2) {a-=PI;flag=-1;}

b=flag*(a-a*a*a/f(3)+a*a*a*a*a/f(5)-a*a*a*a*a*a*a/f(7)+a*a*a*a*a*a*a*a*a/f(9)-a*a*a*a*a*a*a*a*a*a*a/f(11)); gotoxy(15,13);cout<<"cos "<<a1<<"  =  "<<b<<endl<<endl<<endl; cout<<"    按  任  意  键  继  续    "; p=getche( ); return b;}

double tan(void) { double a,b;char p; setcolor(15,6); system("cls"); cout<<"    made by Huang Shaoying" ;  gotoxy(15,10); cout<<"please input a:    "; cin>>a; b=sin( )/cos( );system("cls"); cout<<"    made by Huang Shaoying" ;  gotoxy(15,10); cout<<"得到最后结果:"<<endl; cout<<"    tan "<<a<<"  =  "<<b<<endl<<endl<<endl; cout<<"    按  任  意  键  返  回  主  菜  单    "; p=getche( ); return b;}

double ctan (void) { double a,b;char p; setcolor(15,1); system("cls"); cout<<"    made by Huang Shaoying" ;  gotoxy(15,10); cout<<"please input a:    "; cin>>a; b=cos( )/sin( ); system("cls");   gotoxy(15,10); cout<<"得到最后结果:"<<endl; cout<<"    ctan "<<a<<"  =  "<<b<<endl<<endl<<endl; cout<<"    按  任  意  键  返  回  主  菜  单    "; p=getche( ); return b;}

double sqrt(void) {double a;char p; float x,b=1; setcolor(9,8); system("cls"); cout<<"    made by Huang Shaoying" ; gotoxy(15,10); cout<<"please input a:    "; cin>>a;

do{x=b; b=(x+a/x)/2;} while(fabs(x-b)>1e-5);

gotoxy(15,13);cout<<"sqrt "<<a<<"  =  "<<b<<endl<<endl<<endl; cout<<"    按  任  意  键  返  回  主  菜  单    "; p=getche( ); return b;}

void mi(void) {double a,x,b=1;char p; setcolor(15,1); system("cls"); cout<<"    made by Huang Shaoying" ;  gotoxy(15,10); cout<<"请输入指数a(a不等于0),底数x:    "; cin>>a>>x; for (int i=1;i<=a;i++) b*=x;

cout<<endl<<endl; cout<<"    "<<x<<"^"<<a<<"  =  "<<b<<endl<<endl<<endl; cout<<"    按  任  意  键  返  回  主  菜  单    "; p=getche( ); }

int main(int argc, char* argv[]) { char sig='1'; setcolor( 0,7);  system("cls");    //  清屏       while(sig != '0')    { setcolor(14,7);   system("cls");    //  清屏     cout<<"    made by Huang Shaoying" ;       setcolor(14,8);      gotoxy(8,2); cout<<"    ";     gotoxy(8,3); cout<<"    【    简 * 易 * 函 * 数 * 计 * 算 * 器   】    ";     gotoxy(8,4); cout<<"    ";    setcolor( 15,3);       gotoxy(8,7);  cout<<"    1 --- 加    2 --- 减    ";     gotoxy(8,9);  cout<<"    3 --- 乘    4 --- 除    ";     gotoxy(8,11); cout<<"    5 --- 阶乘    6 --- sin    ";     gotoxy(8,13); cout<<"    7 --- cos    8 --- tan    ";     gotoxy(8,15); cout<<"    9 --- ctan    a --- 开方    ";          gotoxy(8,17); cout<<"    b --- 幂函数    0----退出    ";     gotoxy(8,20); cout<<"    请选择(0---9,a,b):    ";     do {gotoxy(35,20);sig=getchar( );}     while (sig<'0'||sig>'9'&&sig!='a'&&sig!='b') ; setcolor( 9,7);     switch(sig)     {case '0':break;     case '1':plus( );break;     case '2':minus( );break;     case '3':multiply( );break;     case '4':divide( );break;     case '5':fun( );break;     case '6':sin( );break;     case '7':cos( );break;     case '8':tan( );break;     case '9':ctan( );break;     case 'a':sqrt( );break;     case 'b':mi( );break;        }  }  setcolor(15,1);   system("cls");cout<<"    made by Huang Shaoying" ; 

  gotoxy(30,10);setcolor(15,1);   cout<<"感 谢 使 用 计 算 器 !"<<endl;   sig=getche();  return 0; }

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
好友买卖最富裕的是谁?
飞车上我的宠物 经验到0了怎么办啊
花藤几级才有两朵花?
qq农场如何获得桑葚等不能买着的植物
谁给我一个QQ爱墙种子,感激不尽!
农村经济适用手机卡
即使他不明白,是否依然坚持自己内心的想法?
七夕情人节送男友衬衣好吗
你好,出个主意?
给孩子更名咋这么麻烦
李俊基是哪里人?
该怎样去面对社会啊
死神最新主题曲change是谁唱的,超赞!
英语题目诶。。很急。
推荐几款带java,网速快,耐磨的直板手机,几
推荐资讯
刚收获的花椒怎样制作成干花椒
我的电脑突然一下子自动关机了 跟我一起的旁
如何防止做手术晕台?
录取接过查到有没有录取通知书怎么办?
DNF秋叶刀值钱么
谁邀请我开通qq餐厅--有分加的
弹弹堂啵咕普通第三关吃上面的宝箱技巧
公司发给我们的医疗本一什么用
我想家了不想念书怎么办
有谁能给我拟一个灵异校园小说开头,要吸引人
玩qq餐厅怎么还用加入班级呢谁会加啊
请问早上睡醒时泡杯茶叶喝`会不会对身体有害
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?