計算器,計算多項式
#include #include "stack.h"
#include // 判斷是否入棧
bool jud(stack *s, int ope)
return true;
default:
break; }
return false; }
// 計算
void calc(stack *s_opes, stack *s_nums)
push(s_nums, res); // 結果入棧
}// 操作符處理函式
void deal_ope(stack *s_opes, stack *s_nums, int ope)
else // 不入棧,需要計算,可能涉及多個符號的運算
// 符號需要入棧
if (')' != ope)
push(s_opes, ope); }}
int main()
push(&s_nums, num); // 運算元入棧
continue;
} deal_ope(&s_opes, &s_nums, *p); // 處理操作符
p++; }
// 計算剩餘的數
while (!empty(&s_opes))
int res = gettop(&s_nums);
printf ("結果:%d\n", res);
return 0;
}
功能函式
#include "stack.h"
#include #include void init(stack *s)
bool empty(stack *s)
void push(stack *s, data data)
void pop(stack *s)
data gettop(stack *s)
return s->top->data;
}
標頭檔案:
#ifndef _stack_h_
#define _stack_h_
#define size 10
typedef enum bool;
typedef int data;
typedef struct node
node;
typedef struct stack
stack;
// 初始化棧
void init(stack *s);
// 判斷空棧
bool empty(stack *s);
// 入棧
void push(stack *s, data data);
// 出棧
void pop(stack *s);
c 多項式計算器
include include include include include include using namespace std class xiang ostream operator ostream os,xiang t xiang operator const xiang a,const...
基於C 的多項式計算器
一 實驗環境 1.1 程式語言和開發工具 語言採用ansi c c 11 開發工具 vim,g git,visual stdio 用於生成exe檔案 1.2 編碼規範 編碼規範中所有沒有涉及到的內容,參見googlestyle c 類名 類名採用開頭大寫的方式命名 變數 區域性變數採用小駝峰法命名 ...
多項式計算
計算多項式的值 3x2 1 輸入 多項式係數的個數,x的值 輸出 表示式的值 include stdafx.h include iomanip.h include iostream.h define maxsize 100 此多項式是的係數是按照從a0的係數開始輸入的 當x n前的係數為0時,就輸入...