计算器
主要功能
- 实现表达式计算('+' '-' '*' '/' '%' '√' '(' ')')
- 界面
- 多位数运算
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <time.h>
#include<math.h>
#include <stdlib.h>
#define OK 1
#define ERROR 0
typedef struct node
{
int data;
struct node* next;
}Node;
typedef struct stack
{
Node* top;
int count;
}Stack;
int Priority(char s);
int InitStack(Stack* S);
int EmptyStack(Stack* S);
int GetTop(Stack* S);
int Push(Stack* S, int e);
int Pop(Stack* S);
void Paint();
double dis(int x1, int y1, int x2, int y2);
int main()
{
Paint();
}
int Priority(char s)
{
switch (s)
{
case '(':
return 3;
case '*':
case '/':
case '%':
case '^':
return 2;
case '+':
case '-':
return 1;
default:
return 0;
}
}
int InitStack(Stack* S)
{
S->top = NULL;
S->count = 0;
return OK;
}
int EmptyStack(Stack* S)
{
return (S->count == 0) ? OK : ERROR;
}
int GetTop(Stack* S)
{
if (NULL == S -> top)
return ERROR;
return (S -> top -> data);
}
int Push(Stack* S, int e)
{
Node* p = (Node*)malloc(sizeof(Node));
if (p == NULL)
{
return ERROR;
}
p->data = e;
p->next = S->top;
S->top = p;
S->count++;
return OK;
}
int Pop(Stack* S)
{
int e;
if (NULL == S->top)
return ERROR;
Node* p = S->top;
e = p->data;
S->top = p->next;
free(p);
S->count--;
return e;
}
void Paint() {
int number;
initgraph(300, 600);
setbkcolor(RGB(51, 51, 51));
int c;
for (int y = 0; y < 20; y++) {
setcolor(RGB(51, 51, 51));
line(0, y, 400, y);
}
settextcolor(WHITE);
settextstyle(20, 10,<