當前位置:首頁 » 課程大全 » c簡單計算器課程設計報告doc

c簡單計算器課程設計報告doc

發布時間: 2021-01-30 23:19:14

㈠ 用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#做計算器的課程設計報告

已發了個給你

㈢ c語言課程設計(設計一個簡單的計算器)

KTV魔女咯摸摸哦哦弄

㈣ C語言課程設計,簡單計算器

#include<stdio.h>
voidmain()
{
inta,b;
charch;
scanf("%d%c%d",&a,&ch,&b);
switch(ch)
{
case'+':printf("%d",a+b);break;
case'-':printf("%d",a-b);break;
case'*':printf("%d",a*b);break;
case'/':
{
if(b==0)printf("算式無抄意義");
elseprintf("%f",float(a)/b);
break;
}
default:printf("輸入的運算符有誤!");
}
}

㈤ 大一c語言編程實現計算器功能實驗報告

#include"stdio.h"
intmain()
{
inta,b,c;
do
{
system("cls");
printf("計算器菜單 ");
printf("======================== ");
printf("1:計算a+b ");
printf("2:計算a-b ");
printf("3:計算a*b ");
printf("4:計算a/b ");
printf("5:計算a%b ");
printf("0:退出 ");
printf("請選擇(0-5):");
scanf("%d",&c);
if(c!=0)
{
printf("請輸入a:");
scanf("%d",&a);
printf("請輸入b:");
scanf("%d",&b);
switch(c)
{
case1:printf("a+b=%d",a+b);break;
case2:printf("a-b=%d",a-b);break;
case3:printf("a*b=%d",a*b);break;
case4:printf("a/b=%d",a/b);break;
case5:printf("a%b=%d",a%b);break;
default:break;
}
printf(" 按任意鍵繼續......");
getch();
}
}
while(c!=0);
return0;
}

㈥ C語言程序設計 簡單計算器

分太少,加到50分,幫你做了

㈦ c語言課程設計一個簡單計算器

//名字記不太清了,這個叫遞歸下降演算法,但這個演算法肯定是首先在編回譯原理中的,主要答用在
//各種編譯器中。就是現掃描整個表達式字元串,把其中的運算符找出來,判斷它們的優先順序
//然後按從左到右的順序先計算把優先順序低的運算符和它兩邊的數據壓入,這樣循環做過以後
//再從頭取出一個一個計算,表達式的結構類似與二叉樹,遍歷二叉樹後把結果存在連表中供
//計算。

熱點內容
武漢大學學生會輔導員寄語 發布:2021-03-16 21:44:16 瀏覽:612
七年級學生作文輔導學案 發布:2021-03-16 21:42:09 瀏覽:1
不屑弟高考成績 發布:2021-03-16 21:40:59 瀏覽:754
大學畢業證會有成績單 發布:2021-03-16 21:40:07 瀏覽:756
2017信陽學院輔導員招聘名單 發布:2021-03-16 21:40:02 瀏覽:800
查詢重慶2018中考成績查詢 發布:2021-03-16 21:39:58 瀏覽:21
結業考試成績怎麼查詢 發布:2021-03-16 21:28:40 瀏覽:679
14中醫醫師資格筆試考試成績查分 發布:2021-03-16 21:28:39 瀏覽:655
名著賞析課程標准 發布:2021-03-16 21:27:57 瀏覽:881
北京大學商業領袖高端培訓課程 發布:2021-03-16 21:27:41 瀏覽:919