xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 10KB
    文件類型: .cpp
    金幣: 1
    下載: 0 次
    發布日期: 2021-06-15
  • 語言: C/C++
  • 標簽: ??

資源簡介

利用棧求表達式的值,可供小學生作業,并能給出分數。 要求:建立試題庫文件,隨機產生n個題目;題目涉及加減乘除,帶括弧的混合運算;隨時可以退出;保留歷史分數,能回顧歷史,給出與歷史分數比較后 的評價。

資源截圖

代碼片段和文件信息

#include?
#include?
#include?
int?N;??//定義全局變量,表示試題庫試題數量
typedef?struct
{
????char?a[100];
????int?result;
}Shiti;??//試題數據類型
typedef?struct
{
????int?*base*top;
????int?size;
}Num;?//數字棧
typedef?struct
{
????char?*base*top;
????int?size;
}Oper;??//運算符棧

int?NumInitStack(Num?*S1)??//構造數字棧
{
????S1->base=(int?*)malloc(100*sizeof(int));
????if(!S1->base)
????{
????????printf(“申請內存失敗!\n“);
????????return?0;
????}
????S1->top=S1->base;
????S1->size=100;
????return?1;
}

int?OperInitStack(Oper?*S2)??//構造運算符棧
{
????S2->base=(char?*)malloc(100*sizeof(char));
????if(!S2->base)
????{
????????printf(“申請內存失敗!\n“);
????????return?0;
????}
????S2->top=S2->base;
????S2->size=100;
????return?1;
}

int?NumGetTop(Num?*S1)??//得到數字棧棧頂元素
{
????int?e1;
????if((*S1).top==(*S1).base)
????????return?0;
????e1=*((*S1).top-1);
????????return?e1;
}

char?OperGetTop(Oper?*S2)??//得到運算符棧棧頂元素
{
????char?e2;
????if((*S2).top==(*S2).base)
????????return?0;
????e2=*((*S2).top-1);
????????return?e2;
}

void?NumPush(Num?*S1int?e1)??//數字棧壓棧
{
????*(*S1).top++=e1;
}

void?OperPush(Oper?*S2char?e2)??//運算符棧壓棧
{
????*(*S2).top++=e2;
}

int?NumPop(Num?*S1)??//數字棧彈棧
{
????int?e1;
????if((*S1).top==(*S1).base)
????????return?0;
????e1=*--(*S1).top;
????????return?e1;
}

char?OperPop(Oper?*S2)??//運算符棧彈棧
{
????char?e2;
????if((*S2).top==(*S2).base)
????????return?0;
????e2=*--(*S2).top;
????????return?e2;
}

char?Precede(char?achar?b)??//判斷運算符優先級
{
????int?ij;
????char?Table[8][8]={{‘?‘‘+‘‘-‘‘*‘‘/‘‘(‘‘)‘‘=‘}
???????????????????{‘+‘‘>‘‘>‘‘<‘‘<‘‘<‘‘>‘‘>‘}
???????????????????{‘-‘‘>‘‘>‘‘<‘‘<‘‘<‘‘>‘‘>‘}
???????????????????{‘*‘‘>‘‘>‘‘>‘‘>‘‘<‘‘>‘‘>‘}
???????????????????{‘/‘‘>‘‘>‘‘>‘‘>‘‘<‘‘>‘‘>‘}
???????????????????{‘(‘‘<‘‘<‘‘<‘‘<‘‘<‘‘=‘‘?‘}
???????????????????{‘)‘‘>‘‘>‘‘>‘‘>‘‘?‘‘>‘‘>‘}
???????????????????{‘=‘‘<‘‘<‘‘<‘‘<‘‘<‘‘?‘‘=‘}};??//優先級表格
????for(i=0;i<8;i++)
????????if(Table[0][i]==a)??//縱坐標尋找
????????????break;
????for(j=0;j<8;j++)??//橫坐標尋找
????????if(Table[j][0]==b)
????????????break;
????return?Table[j][i];
}

int?Operate(int?achar?thetaint?b)??//計算二元表達式的值
{
????int?c;
????if(theta==‘+‘)
????????c=a+b;
????else?if(theta==‘-‘)
????????c=a-b;
????else?if(theta==‘*‘)
????????c=a*b;
????else
????????c=a/b;
????return?c;
}

int?IsOper(char?ch)??//判斷字符ch是否為運算符
{
????char?ptr[10]={‘+‘‘-‘‘*‘‘/‘‘(‘‘)‘‘=‘};
????int?i;
????for(i=0;i<7;i++)
????{
????????if(ch==ptr[i])
????????????return?1;
????}
????return?0;
}

int?Result(char?a[]Num?*numOper?*oper)??//計算表達式的結果
{
????char?theta;
????int?bdk=0i=0j=0num2=0;
????NumInitStack(num);??//構造數字棧
????OperInitStack(oper);??//構造運算符棧
????OperPush(oper‘=‘);??//將“=“壓到棧底
????while(a[i]!=‘=‘||OperGetTop(oper)!=‘=‘)
????{
????????//對表達式a進行計算
????????if(a[i]>=‘0‘&&a[i]<=‘9‘)
????????{
????????????//字符是數字
??????

評論

共有 條評論