c語言計算器編程代碼
Ⅰ c語言編寫簡易計算器程序
C語言編寫計算器
我們可以用printf和scanf函數輸出結果和獲取用戶的輸入。需要<stdio.h>頭文件。scanf函數在讀取數據的時候不需要再一行上輸入每個數據,只要數據和數據之間留出空白就可以了。先聲明兩個變數number1和number2,operation變數用來存儲運算符。用scanf函數獲取這兩個數字和運算符。分別用%lf %c %lf
Ⅱ 計算器c語言代碼
你這個代碼的問題太多了,下面已經給你一一改過來了,並且編譯運行通過了,自己比較一下:
你原先的錯誤都給你標出來了:
#include<stdio.h>
void displaymenu() //這個函數應該放在main函數外面進行定義
{
printf("\n\n*****************************\n");
printf("* 1.加法 *\n");
printf("* 2.?法 *\n");
printf("* 3.乘法 *\n");
printf("* 4.除法 *\n");
printf("* 5.求余 *\n");
printf("* 6.?乘 *\n");
printf("* 7.累加 *\n");
printf("* 8.?束 *\n");
printf("*****************************\n");
printf("????型<1,2,3,4,5,6,7,8>?\n");
}
main()
{
while(1) //這里應該是while(1),以實現循環的執行
{
displaymenu(); //這里原先筆誤成menu()了,應該是displaymenu()
int a=0;
scanf("%d",&a);
switch(a)
{
case 1:
{//int i=0,j=0,add=0; 這里少定義了一個sum=0;
int i=0,j=0,add=0,sum=0;
scanf("%d%d",&i,&j);
sum=i+j;
printf("add=%d\n",sum);
};break;
case 2:
{int i=0,j=0,sub=0;
scanf("%d%d",&i,&j);
sub=i-j;
printf("sub=%d\n",sub);
};break;
case 3:
{int i=0,j=0,multi=0;
scanf("%d%d",&i,&j);
multi=i*j;
printf("multi=%d\n",multi);
};break;
case 4:
{int i=0,j=0;
float divide=0;
scanf("%d%d",&i,&j);
divide=i/j;
if(j=0)
printf("erro\n");
else
printf("divide=%lf\n",divide);
};break;
case 5:
{int i=0,j=0,arith_compliment=0; //這里原先的arith-compliment,不是C語言的合法變數名(變數名中不能有「-」)
scanf("%d%d",&i,&j);
arith_compliment=i%j;
printf("arith-compliment=%d\n",arith_compliment);
};break;
case 6:
{int i=0;
float fac=1.0;
for(i=1;i<=9;i++)
fac=fac*i;
printf("\n");
printf("fac=%lf",fac);
};break;
case 7:
{int i=0,sum_N=0;
for(i=0;i<=9;i++)
sum_N=sum_N+i;
printf("\n");
printf("sum_N=%d",sum_N);
};break;
}
}
}
Ⅲ c語言編寫「多功能計算器」的代碼
#include<stdio.h>
#include<windows.h>
#include<math.h>
double
EPS=10E-6;
double
sum(double
a,double
b)
{
return
a+b;
}
double
sub(double
a,double
b)
{
return
a-b;
}
double
mul(double
a,double
b)
{
return
a*b;
}
double
divv(double
a,double
b)
{
return
a/b;
}
int
rem(int
a
,
int
b)
{
return
a%b;
}
int
addnumber(int
c,int
d)
{
int
sum=0;
for(int
i=c;i<=d;i++)
{
sum+=i;
}
return
sum;
}
int
factor(int
n)
{
int
f=1;
for(int
i=1;i<=n;i++)
{
f*=i;
}
return
f;
}
void
displaymenu()
{
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\n");
printf("*############高級計算器############*
\n");
printf("************************************
\n");
printf("*
①加法運算
*
\n");
printf("*
②減法運算
*
\n");
printf("*
③乘法運算
*
\n");
printf("*
④除法運算
*
\n");
printf("*
⑤取余運算
*
\n");
printf("*
⑥累加運算
*
\n");
printf("*
⑦階乘運算
*
\n");
printf("*
⊙結束運算
*
\n");
printf("************************************
\n");
printf("************************************
\n");
}
void
main()
{
int
c,d;
/*用於做四則運算的兩個數值的說明*/
double
a,b;
/*用來做累加函數的兩個參數值的說明*/
int
intresult;
double
result;
/*用於保存表單運算中函數的返回值*/
int
choice;
displaymenu();/*保存用戶選擇項目菜單項*/
while(1)
{
printf("請選擇你所進行運算項目的符號:");
scanf("%d",&choice);
switch(choice)
{
case
1:
/*加法計算*/
printf("請輸入兩個數字:");
scanf("%lf%lf",&a,&b);
result=sum(a,b);
printf("%lf+%lf的計算結果是:%lf\n",a,b,result);
break;
case
2:
/*減法計算*/
printf("請輸入兩個數字:");
scanf("%lf%lf",&a,&b);
result=sub(a,b);
printf("%lf-%lf的計算結果是:%lf\n",a,b,result);
break;
case
3:
/*乘法計算*/
printf("請輸入兩個數字:");
scanf("%lf%lf",&a,&b);
result=mul(a,b);
printf("%lf*%lf的計算結果是:%lf\n",a,b,result);
break;
case
4:
/*除法計算*/
{
scanf("%lf%lf",&a,&b);
if(b-0.0<EPS)
printf("數字錯誤\n");
else
{
printf("請輸入兩個數字:");
result=divv(a,b);
printf("%lf/%lf的計算結果是:%lf\n",a,b,result);
}
break;
}
case
5:
/*取余計算*/
printf("請輸入兩個數字:");
scanf("%d%d",&c,&d);
result=rem(c,d);
printf("%d
%
%d的計算結果是:%d\n",c,d,result);
break;
case
6:
/*累加計算*/
printf("請輸入兩個整數");
scanf("%d%d",&c,&d);
intresult=addnumber(c,d);
printf("%d-%d的累加計算結果是:%d\n",c,d,intresult);
break;
case
7:
//階乘計算
{
printf("請輸入一個大於0小於10的整數字");
scanf("%d",&c);
if(c<0||c>10)
{
printf("請輸入一個大於0小於10的整數字,數據錯誤。\n");
break;
}
intresult=factor(c);
printf("%d的階乘計算結果是:%d\n",c,intresult);
break;
}
case
0:
printf("謝謝使用。歡迎下次再用。\n");
return
;
default:
printf("選擇錯誤,程序結束\n");
break;
}
}
}
Ⅳ C語言 要求編寫一個簡單計算器的程序
#include<stdio.h>
voidmain(){floatx,y,z;charc;
scanf("%f%c%f",&x,&c,&y);
switch(c){
case'+':z=x+y;break;
case'-':z=x-y;break;
case'*':z=x*y;break;
case'/':z=(y==0)?(0):(x/y);break;
default:z=0;break;
}
printf("%f%c%f=%f ",x,c,y,z);
}
Ⅳ 用c語言編寫一個簡單計算器程序
#include<stdio.h>//計算器
voidmenu()//自定義的菜單界面
{
printf("--------------------\n");
printf("請輸入你的選擇\n");
printf("1.+\n");
printf("2.-\n");
printf("3.*\n");
printf("4./\n");
printf("--------------------\n");
}
intmain()
{
inti=0;
intj=0;
intnum=0;//計算結果存放在nun
intselect=0;//選擇的選項存放在select
do//do-while先執行再判斷循環條件,即可實現重復計算功能
{
menu();//列印出菜單界面
scanf("%d",&select);//輸入你的選項
printf("請輸入計算值:");
scanf("%d%d",&i,&j);//輸入要計算的數值
switch(select)
{
case1:
printf("%d+%d=%d\n",i,j,num=i+j);//實現加法功能
break;
case2:
printf("%d-%d=%d\n",i,j,num=i-j);//實現減法功能
break;
case3:
printf("%d*%d=%d\n",i,j,num=i*j);//實現乘法功能
break;
case4:
printf("%d-%d=%d\n",i,j,num=i/j);//實現除法功能
break;
default:
printf("輸入有誤重新選擇");
break;
}
}while(select);
return0;
}
運行結果:
(5)c語言計算器編程代碼擴展閱讀:
return表示把程序流程從被調函數轉向主調函數並把表達式的值帶回主調函數,實現函數值的返回,返回時可附帶一個返回值,由return後面的參數指定。
return通常是必要的,因為函數調用的時候計算結果通常是通過返回值帶出的。如果函數執行不需要返回計算結果,也經常需要返回一個狀態碼來表示函數執行的順利與否(-1和0就是最常用的狀態碼),主調函數可以通過返回值判斷被調函數的執行情況。
Ⅵ 用C語言編計算器程序
#include "stdio.h"
#include "string.h"
#include "ctype.h"
#include "math.h"
//expression evaluate
#define iMUL 0
#define iDIV 1
#define iADD 2
#define iSUB 3
#define iCap 4
//#define LtKH 5
//#define RtKH 6
#define MaxSize 100
void iPush(float);
float iPop();
float StaOperand[MaxSize];
int iTop=-1;
//
char Srcexp[MaxSize];
char Capaexp[MaxSize];
char RevPolishexp[MaxSize];
float NumCapaTab[26];
char validexp[]="*/+-()";
char NumSets[]="0123456789";
char StackSymb[MaxSize];
int operands;
//
void NumsToCapas(char [], int , char [], float []);
int CheckExpress(char);
int PriorChar(char,char);
int GetOperator(char [], char);
void counterPolishexp(char INexp[], int slen, char Outexp[]);
float CalcRevPolishexp(char [], float [], char [], int);
void main()
{
int ilen;
float iResult=0.0;
printf("enter a valid number string:\n");
memset(StackSymb,0,MaxSize);
memset(NumCapaTab,0,26); //A--NO.1, B--NO.2, etc.
gets(Srcexp);
ilen=strlen(Srcexp);
//printf("source expression:%s\n",Srcexp);
NumsToCapas(Srcexp,ilen,Capaexp,NumCapaTab);
printf("Numbers listed as follows:\n");
int i;
for (i=0; i<operands; ++i)
printf("%.2f ",NumCapaTab[i]);
printf("\nCapaexp listed in the following:\n");
printf("%s\n",Capaexp);
ilen=strlen(Capaexp);
counterPolishexp(Capaexp,ilen,RevPolishexp);
printf("RevPolishexp:\n%s\n",RevPolishexp);
ilen=strlen(RevPolishexp);
iResult=CalcRevPolishexp(validexp, NumCapaTab, RevPolishexp,ilen);
printf("\ncounterPolish expression:\n%s%.6f\n",Srcexp,iResult);
}
void iPush(float value)
{
if(iTop<MaxSize) StaOperand[++iTop]=value;
}
float iPop()
{
if(iTop>-1)
return StaOperand[iTop--];
return -1.0;
}
void NumsToCapas(char Srcexp[], int slen, char Capaexp[], float NumCapaTab[])
{
char ch;
int i, j, k, flg=0;
int sign;
float val=0.0,power=10.0;
i=0; j=0; k=0;
while (i<slen)
{
ch=Srcexp[i];
if (i==0)
{
sign=(ch=='-')?-1:1;
if(ch=='+'||ch=='-')
{
ch=Srcexp[++i];
flg=1;
}
}
if (isdigit(ch))
{
val=ch-'0';
while (isdigit(ch=Srcexp[++i]))
{
val=val*10.0+ch-'0';
}
if (ch=='.')
{
while(isdigit(ch=Srcexp[++i]))
{
val=val+(ch-'0')/power;
power*=10;
}
} //end if
if(flg)
{
val*=sign;
flg=0;
}
} //end if
//write Capaexp array
// write NO.j to array
if(val)
{
Capaexp[k++]='A'+j;
Capaexp[k++]=ch;
NumCapaTab[j++]=val; //A--0, B--1,and C, etc.
}
else
{
Capaexp[k++]=ch;
}
val=0.0;
power=10.0;
//
i++;
}
Capaexp[k]='\0';
operands=j;
}
float CalcRevPolishexp(char validexp[], float NumCapaTab[], char RevPolishexp[], int slen)
{
float sval=0.0, op1,op2;
int i, rt;
char ch;
//recursive stack
i=0;
while((ch=RevPolishexp[i]) && i<slen)
{
switch(rt=GetOperator(validexp, ch))
{
case iMUL: op2=iPop(); op1=iPop();
sval=op1*op2;
iPush(sval);
break;
case iDIV: op2=iPop(); op1=iPop();
if(!fabs(op2))
{
printf("overflow\n");
iPush(0);
break;
}
sval=op1/op2;
iPush(sval);
break;
case iADD: op2=iPop(); op1=iPop();
sval=op1+op2;
iPush(sval);
break;
case iSUB: op2=iPop(); op1=iPop();
sval=op1-op2;
iPush(sval);
break;
case iCap: iPush(NumCapaTab[ch-'A']);
break;
default: ;
}
++i;
}
while(iTop>-1)
{
sval=iPop();
}
return sval;
}
int GetOperator(char validexp[],char oper)
{
int oplen,i=0;
oplen=strlen(validexp);
if (!oplen) return -1;
if(isalpha(oper)) return 4;
while(i<oplen && validexp[i]!=oper) ++i;
if(i==oplen || i>=4) return -1;
return i;
}
int CheckExpress(char ch)
{
int i=0;
char cc;
while((cc=validexp[i]) && ch!=cc) ++i;
if (!cc)
return 0;
return 1;
}
int PriorChar(char curch, char stach)
{
//棧外優先順序高於(>)棧頂優先順序時,才入棧
//否則(<=),一律出棧
if (curch==stach) return 0; //等於時應該出棧
else if (curch=='*' || curch=='/')
{
if(stach!='*' && stach!='/')
return 1;
}
else if (curch=='+' || curch=='-')
{
if (stach=='(' || stach==')')
return 1;
}
else if (curch=='(')
{
if (stach==')')
return 1;
}
return 0;
}
void counterPolishexp(char INexp[], int slen, char Outexp[])
{
int i, j, k,pr;
char t;
i=0;
j=k=0;
while (INexp[i]!='=' && i<slen)
{
if (INexp[i]=='(')
StackSymb[k++]=INexp[i];
//iPush(*(INexp+i));
else if(INexp[i]==')')
{
//if((t=iPop())!=-1)
while((t=StackSymb[k-1])!='(')
{
Outexp[j++]=t;
k--;
}
k--;
}
else if (CheckExpress(INexp[i])) // is oparator
{
// printf("operator %c k=%d\n",INexp[i],k);
while (k)
{
// iPush(*(INexp+i));
if(pr=PriorChar(INexp[i],StackSymb[k-1]))
break;
else
{
//if ((t=iPop())!=-1)
t=StackSymb[k-1]; k--;
Outexp[j++]=t;
}
} //end while
StackSymb[k++]=INexp[i]; //common process
}
else //if() 變數名
{
// printf("operand %c k=%d\n",INexp[i],k);
Outexp[j++]=INexp[i];
}
i++; //
}
while (k)
{
t=StackSymb[k-1]; k--;
Outexp[j++]=t;
}
Outexp[j]='\0';
}
Ⅶ C語言程序設計簡易計算器
1、首先,打開Vs 2010,如圖。
2、找到左上角的新建並點擊,給文件為簡單計算器,單擊確定。
3、點擊下一步,注意勾選空項目,點擊下一步,點擊完成。
4、點擊左側的源文件,右擊選擇「添加—>項目」,選擇C++文件,命名為簡單計算器,因為是C程序,注意後綴名要加上.c,點擊確定完成文件新建工作。
5、輸入以下代碼,好了,一個簡單的計算器便做好了
Ⅷ 用c語言編寫計算器
#include <stdio.h>
struct s_node
{
int data;
struct s_node *next;
};
typedef struct s_node s_list;
typedef s_list *link;
link operator=NULL;
link operand=NULL;
link push(link stack,int value)
{
link newnode;
newnode=(link) malloc(sizeof(s_list));
if(!newnode)
{
printf("\nMemory allocation failure!!!");
return NULL;
}
newnode->data=value;
newnode->next=stack;
stack=newnode;
return stack;
}
link pop(link stack,int *value)
{
link top;
if(stack !=NULL)
{
top=stack;
stack=stack->next;
*value=top->data;
free(top);
return stack;
}
else
*value=-1;
}
int empty(link stack)
{
if(stack==NULL)
return 1;
else
return 0;
}
int is_operator(char operator)
{
switch (operator)
{
case '+': case '-': case '*': case '/': return 1;
default:return 0;
}
}
int priority(char operator)
{
switch(operator)
{
case '+': case '-' : return 1;
case '*': case '/' : return 2;
default: return 0;
}
}
int two_result(int operator,int operand1,int operand2)
{
switch(operator)
{
case '+':return(operand2+operand1);
case '-':return(operand2-operand1);
case '*':return(operand2*operand1);
case '/':return(operand2/operand1);
}
}
void main()
{
char expression[50];
int position=0;
int op=0;
int operand1=0;
int operand2=0;
int evaluate=0;
printf("\nPlease input the inorder expression:");
gets(expression);
while(expression[position]!='\0'&&expression[position]!='\n')
{
if(is_operator(expression[position]))
{
if(!empty(operator))
while(priority(expression[position])<= priority(operator->data)&&
!empty(operator))
{
operand=pop(operand,&operand1);
operand=pop(operand,&operand2);
operator=pop(operator,&op);
operand=push(operand,two_result(op,operand1,operand2));
}
operator=push(operator,expression[position]);
}
else
operand=push(operand,expression[position]-48);
position++;
}
while(!empty(operator))
{
operator=pop(operator,&op);
operand=pop(operand,&operand1);
operand=pop(operand,&operand2);
operand=push(operand,two_result(op,operand1,operand2));
}
operand=pop(operand,&evaluate);
printf("The expression [%s] result is '%d' ",expression,evaluate);
getch();
}
Ⅸ c語言編程…急求一個「計算器」代碼 錯誤要最少,每句代碼後還要有中文注釋
#include<stdio.h>
int
main()
{
int
a,b,d;
char
c;
int
fun(int
a,char
c,int
b);
printf("請輸入計算式(如:3
+
2
):");
scanf("%d%c%d",&a,&c,&b);
d=fun(a,c,b);
if(d==99999)
printf("字元輸入錯誤!");
else
printf("%d%c%d=%d",a,c,b,d);
fflush(stdin);
getchar();
return
0;
}
int
fun(int
a,char
c,int
b)
{
return
c=='+'?a+b:(c=='-'?a-b:(c=='*'?a*b:(c=='/'?a/b:99999)));
}
絕對經典的計算器,數據必須是整型哦
Ⅹ 用C語言編寫一個計算器程序,實現加,減,乘,除,求平方根(正數),倒數等功能.
#include<iostream>
#include<cmath>
#include<string>
using
namespace
std;
const
double
pi
=
3.14159265;
const
double
e
=
2.718281828459;
const
int
SIZE
=
1000;
typedef
struct
node//為了處理符號而建立的鏈表(如:
1+(-2))
{
char
data;
node
*next;
}node;
typedef
struct
stack_num//存儲
數
的棧
{
double
*top;
double
*base;
}stack_num;
typedef
struct
stack_char//存儲
運算符號
的棧
{
char
*top;
char
*base;
}stack_char;
stack_num
S_num;//定義
stack_char
S_char;//定義
char
fu[18]
=
{'\n',
')',
'+',
'-',
'*',
'/',
'%',
'^',
'Q',
'L',
'C',
'S',
'T',
'c',
's',
't',
'('};
int
compare[1000];//表現出各運算符號的優先順序
double
shu[1000];//存儲
"數"
的數組
double
dai_result;//運算的結果,是為了處理
M
運算(簡介函數里有M的定義)
int
biao
=
0;//和dia_result
一樣,為了處理
M
運算
char
line[SIZE];//輸入的所要計算的表達式
void
init()//初始化
{
compare[fu[0]]
=
-2;//用數字的大小表現出符號的優先順序
compare[fu[1]]
=
-1;
compare[fu[2]]
=
2;
compare[fu[3]]
=
2;
compare[fu[4]]
=
4;
compare[fu[5]]
=
4;
compare[fu[6]]
=
4;
compare[fu[7]]
=
5;
for(int
i
=
8;
i
<=
15;
i++)
compare[fu[i]]
=
6;
compare[fu[16]]
=
7;
S_num.base
=
(double*)malloc(sizeof(double)*SIZE);//為棧開辟空間
S_char.base
=
(char*)malloc(sizeof(char)*SIZE);//同上
S_num.top
=
S_num.base;
S_char.top
=
S_char.base;
}
void
push_num(double
n)//數字進棧
{
*
++S_num.top
=
n;
}
void
push_char(char
c)//運算符號進棧
{
*
++S_char.top
=
c;
}
double
pop_num()//數字出棧
{
double
m
=
*S_num.top;
S_num.top--;
return
m;
}
char
pop_char()//運算符號出棧
{
char
cc
=
*S_char.top;
S_char.top--;
return
cc;
}
char
get_top_char()//得到運算符號的棧中最頂端的運算符號
{
return
*S_char.top;
}
double
operate(double
y,
char
c,
double
x)//
對兩個數計算
(
含是雙目運算符
:
如
*,
/
等等
)
{
double
r;
if(c
==
'-')
r
=
x
-
y;
else
if(c
==
'+')
r
=
x
+
y;
else
if(c
==
'/'
&&
y
!=
0)
r
=
x
/
y;
else
if(c
==
'*')
r
=
x
*
y;
else
if(c
==
'^')
{
r
=
1;
for(int
i
=
1;
i
<=
y;
i++)
r
*=
x;
}
else
if(c
==
'%')
{
int
r0
=
(int)x
%
(int)y;
r
=
double(r0);
}
return
r;
}
double
operate_one(double
one,
char
cc)//
對一個數運算
(
含單目運算符
:
如
log(L),
sin(S)
等等
)
{
double
r;
if(cc
==
'Q')
r
=
sqrt(one);
else
if(cc
==
'C')
r
=
cos(one);
else
if(cc
==
'S')
r
=
sin(one);
else
if(cc
==
'T')
r
=
tan(one);
else
if(cc
==
'c')
i++;
}
i++;
}
if(ge
>=
3)
return
0;
else
return
1;
}
void
output(double
result)//
打出結果
{
printf("
所得結果是
:
");
cout<<result<<endl;
}
void
check()//
檢查表達式是否合法
{
void
introce();
char
cc;//
決定計算器按哪種功能進行計算
double
result;//
結果
void
input();//
定義
if(
check_kuohao()
&&
check_char()
)//
看是否合法
,
合法則計算
{
result
=
compute();
output(result);
cout<<"
輸入一個字元
'M'
或
'D'
或
'F',
決定是否繼續
:
"<<endl;
while(cin>>cc)
{
if(cc
==
'M')
{
system("cls");
introce();
printf("
您上次所得結果為
:
");
cout<<result<<endl;
cout<<"
在上次計算結果的基礎上
,
請繼續輸入想計算的表達式
"<<endl;
dai_result
=
result;
biao
=
1;
input();//
輸入表達式
break;
}
else
if(cc
==
'D')
{
system("cls");
introce();
cout<<"
計算器已清零
,
請輸入您所要計算的表達式
"<<endl;
input();//
輸入表達式
break;
}
else
if(cc
==
'F')
{
system("cls");
cout<<"
計算器關閉
,
謝謝使用
!"<<endl;
break;
}
else
{
cout<<"
所輸入字元無效
,
請輸入一個字元
'M'
或
'D'
或
'F'!"<<endl;
continue;
}
}
}
else//
不合法,分兩種不合法
{
if(check_kuohao()
==
0
&&
check_char()
==
1)
{
cout<<"
您所輸入的表達式括弧不匹配
,
請重新輸入
:"<<endl;
input();//
輸入表達式
}
else
{
cout<<"
您所輸入的表達式不合法
,
請重新輸入
:"<<endl;
input();//
輸入表達式
}
}
}
void
tackle_fuhao()//
處理負號
{
node
*root,
*head,
*p,
*q,
*p1;
root
=
head
=
new
node;
head->next
=
NULL;
int
i;
for(i
=
0;
line[i]
!=
'\0';
i++)//
建立鏈表
{
p
=
new
node;
p->data
=
line[i];
p->next
=
head->next;
head->next
=
p;
head
=
p;
}
//
delete
p;
q
=
(node*)malloc(sizeof(node));
head
=
root;
if(root->next->data
==
'+'
||
root->next->data
==
'-')//
處理第一個字元
{
p
=
new
node;
p->data
=
'0';
p->next
=
head->next;
head->next
=
p;
}
if(root->next
!=
NULL)
{
for(q
=
root->next;
q;
q
=
q->next)
{
if(q->data
==
'('
&&
(q->next->data
==
'-'
||
q->next->data
==
'+'))
{
p
=
new
node;
p->data
=
'0';
p->next
=
q->next;
q->next
=
p;
}
}
}
//
delete
q;
p1
=
new
node;
int
qi
=
-1;
for(p1
=
root->next;
p1;
p1
=
p1->next)
{
line[++qi]
=
p1->data;
}
line[++qi]
=
'\0';
}
void
input()//
輸入
{
cin>>line;
if(biao
==
0)
tackle_fuhao();//
處理負號
check();//
檢查表達式是否合法
}
void
introce()//
對計算器的符號功能的簡要介紹
{
cout<<"
計算器簡要介紹
"<<endl;
cout<<"C(cos)
S(sin)
T(tan)
a(arccos)
c(arcsin)
"<<endl;
cout<<"7
8
9
/
on
t(arctan)
"<<endl;
cout<<"4
5
6
*
%
L(log)"<<endl;
cout<<"1
2
3
-
M(M+)
Q(sqrt)
"<<endl;
cout<<"0
.
+
^(
乘方
)
F(off)
Enter(=)
"<<endl;
cout<<"
對於對數輸入
L2_5
表示以
2
為底
5
的對數
"<<endl;
cout<<"M(
在前面結果的基礎上繼續計算,
如:
上次結果為
10
,
現輸入
+10.5*2)"<<endl;
cout<<"D(
清零並繼續輸入
)"<<endl;
cout<<"F(
計算機關閉
)"<<endl;
cout<<"
輸入
P
就代表輸入圓周率
,
輸入
E
代表輸入自然對數
"<<endl<<endl;
}
void
print()
{
system("color
2");
cout<<"
歡迎使用本計算器
"<<endl;
cout<<"
輸入一個字元串
on,
計算器開始啟動
"<<endl;
}
void
if_start()//
是否啟動計算器
{
string
start;
print();
while(cin>>start)
{
if(start
!=
"on")
{
cout<<"
您所輸入的字元無效
,
請按照介紹的繼續輸入
:"<<endl;
continue;
}
else
break;
}
if(start
==
"on")
{
system("color
5");//
顏色的處理
system("cls");//
刷屏
}
introce();//
對計算器的簡要介紹
cout<<"
現在
,
請輸入您所要計算的表達式
"<<endl;
input();//
輸入所要計算的表達式
}
int
main()
{
if_start();//
調用是否啟動計算器函數
return
0;
}
r
=
acos(one);
else
if(cc
==
's')
r
=
asin(one);
else
if(cc
==
't')
r
=
atan(one);