1.结对编程题目是:面向小学生,随机生成30个100以内的四则运算,并且用户可以录入结果,检查用户录入的结果是否是正确的。
2.结对编程对象:叶小娟,代码共计:326行
3.
4.代码
#include <stdio.h> //计算器 #include <malloc.h> #include <stdlib.h> #define STACK_SIZE 100 //max size of the stack #define STACK_INCREMENT 10 //realloc size typedef struct FStack //stack of int { float* base; float* top; int stacksize; }FStack; void Init(FStack* s) { s->base = (float*)malloc(STACK_SIZE * sizeof(FStack)); if (!s->base) { printf("overflow! "); return; } s->top = s->base; s->stacksize = STACK_SIZE; } bool isEmpty(FStack* s) { if (s->top == s->base) { return true; } else { return false; } } void Push(FStack* s, float e) { if (s->top - s->base >= s->stacksize) { printf("stack is full! realloc %d ", STACK_INCREMENT); s->base = (float*)realloc(s->base, (s->stacksize + sizeof(FStack))); if (!s->base) { printf("overflow! "); return; } s->top = s->base + s->stacksize; s->stacksize += STACK_INCREMENT; } *(s->top) = e; (s->top)++; } float GetTop(FStack* s) { if (s->top == s->base) { printf("stack is empty! "); return 0; } float e = *(s->top - 1); return e; } void Pop(FStack* s) { if (s->top == s->base) { printf("stack is empty! "); return; } s->top--; } typedef struct CStack //stack of char { char* base; char* top; int stacksize; }CStack; void Init(CStack* s) { s->base = (char*)malloc(STACK_SIZE * sizeof(CStack)); if (!s->base) { printf("overflow! "); return; } s->top = s->base; s->stacksize = STACK_SIZE; } bool isEmpty(CStack* s) { if (s->top == s->base) { return true; } else { return false; } } void Push(CStack* s, int e) { if (s->top - s->base >= s->stacksize) { printf("stack is full! realloc %d ", STACK_INCREMENT); s->base = (char*)realloc(s->base, (s->stacksize + sizeof(CStack))); if (!s->base) { printf("overflow! "); return; } s->top = s->base + s->stacksize; s->stacksize += STACK_INCREMENT; } *(s->top) = e; (s->top)++; } char GetTop(CStack* s) { if (s->top == s->base) { printf("stack is empty! "); return 0; } char e = *(s->top - 1); return e; } void Pop(CStack* s) { if (s->top == s->base) { printf("stack is empty! "); return; } s->top--; } bool isOper(char ch) { if (ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '%') { return true; } else { return false; } } int Priority(char ch) { int p; switch (ch) { case '(': p = 0; break; case '+': case '-': p = 1; break; case '*': case '/': case '%': p = 2; break; } return p; } float Calculate(float f1, float f2, char oper) { float f3; switch (oper) { case '+': f3 = f1 + f2; break; case '-': f3 = f1 - f2; break; case '*': f3 = f1 * f2; break; case '%': f3 = (float)((int)f1 % (int)f2); break; case '/': if (f2 == 0) { printf(" Devided by zero!"); exit(1); } else { f3 = f1 / f2; } break; } return f3; } float StrtoFloat(char* str, int* pos) { float fRes; int i = *pos; int k; char n[50]; for (k = 0; str[i] >= '0' && str[i] <= '9' || str[i] == '.'; i++, k++) { n[k] = str[i]; } n[k] = '