1运动浮点数进行简单的加减乘除。最后可以计算其混合运算。
2可能会随时追问
3急用。分会高。
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; }