当前位置:首页 » 课程大全 » 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