首页 > > 详细

辅导Expression Calculation、讲解C/C++编程、C/C++语言调试、辅导infix 辅导留学生Prolog|辅导Web开发

The Final Laboratory Reports
1. Title
The Application of Stack in Expression Calculation
2. Introduction
When you write an expression A+B*(C-D)-E/F (which is also called the infix expression, since
the operators are located at the middle of two numbers) in your code, the compiling program will
convert it into a suffix expression ABCD-*+EF/- where operators are located at the end of numbers.
The value of the expression A+B*(C-D)-E/F is then calculated via its corresponding suffix
expression ABCD-*+EF/-, which can simplify the calculation because we do not have to consider
the brackets. The Stack data structure [1] is widely applied to convert an infix expression into its
corresponding suffix expression and also used to calculate the value of a suffix expression. Refer
to [1][2][3][4] to understand how to use the stack to convert an infix expression into a suffix expression,
and how to calculate the value of a suffix expression via stack.
3. Tasks
In the final laboratory report, you are required to write a C program to complete following tasks:
(1) Implement the stack data structure using pointers and structure;
*Tips: in this task you are required to implement following functions of stack
/////////////////////////////////////function pre-defination for STACK_CHAR/////////
int isCharStackEmpty(STACK_CHAR *S);//check a char stack is empty or not
int isCharStackFull(STACK_CHAR *S);//check a char stack is full or not
STACK_CHAR *createCharStack();//create a char stack
void disposeCharStack(STACK_CHAR *S);// delete a char stack
void pushCharStack(STACK_CHAR *S,char e);// push a char element into stack
char getCharStackTop(STACK_CHAR *S);// get the top element of stack
void popCharStack(STACK_CHAR *S);// pop an element from the stack
char popAndReturnTopChar(STACK_CHAR *S);//pop an element from the stack and return
the element
///////////////////////////////////function pre-defination for STACK_DOUBLE/////////
int isDOUBLEStackEmpty(STACK_DOUBLE *S);//check a double stack is empty or not
int isDOUBLEStackFull(STACK_DOUBLE *S);//check a char stack is full or not
STACK_DOUBLE *createDOUBLEStack();//create a double stack
void disposeDOUBLEStack(STACK_DOUBLE *S);// delete a double stack
void pushDOUBLEStack(STACK_DOUBLE *S, double e);// push a double element into
stack
double getDOUBLEStackTop(STACK_DOUBLE *S);//get the top element of stack
void popDOUBLEStack(STACK_DOUBLE *S);//pop an element from the stack
double popAndReturnTopDOUBLE(STACK_DOUBLE *S);//pop an element from the stack
and return the element
(2) Get any legal infix expression from keyboard, convert the input expression into its corresponding
suffix expression using the stack and output the suffix expression.
*Tips: in this task you are going to use a stack consisting of char type data to convert an infix
expression into corresponding suffix expression. /*
* define a stack consists of char elements
*/
typedef struct stackCharRecord
{
int capacity;//capacity of stack
int stackTop;//the top of stack
char *base;
}STACK_CHAR;
/////////////////////function pre-definition for converting infix to suffix/////////////////////////
char* convertInfix2Suffix(char *infix,int len);//convert Infix expression into a Suffix one
int getPriority(char c);//get the priorty of operators
bool isVariable(char c);//check c is a number or not
(3) Calculate the value of the suffix expression via the stack, output the calculated result, and
check whether you get the right answer.
*Tips: in this task you are also going to use a stack consisting of double type data to calculate
the value of suffix expression.
/*
* define a stack consists of double elements
*/
typedef struct stackDoubleRecord
{
int capacity;//capacity of stack
int stackTop;//the top of stack
double *base;
}STACK_DOUBLE;
//calculate expression value given suffix expression
double calculateSuffixExpression(char *suffix,int len,double *number);
(4) Write a Laboratory report. The format of the Laboratory Report can be found in Appendix A.
*Tips: you are strongly advised to refer to the labReports-V3.pdf file to learn how to write the
lab report.
4. References
[1] LI Cheng, DING Guo-dong.The Application of Stack in Expression's Calculation, Computer
Knowledge and Technology, 2014.
[2]M. A. Weiss, Data Structure and Algorithm Analysis in C (2nd edition), Chine Machine Express,
1996.
[4] https://wenku.baidu.com/view/780c1c3b31126edb6f1a1008.htmlAppendix A.
The C Programming Language
Laboratory Reports
2018.xx.xx Expression Calculation via Stack
Author (Name), Student ID, Affiliations
Abstract
1. Objectives
2. Method
2.1 Implement of Stack
2.2 Converting Infix Expression into Suffix Expression
2.3 Calculating Suffix Expression
3. Results
*Tips: in this part, apply at least 3 test cases to your code, and show the output of running
your code.
References
Appendix. Source Code in C
* Tips;Attach your source code as an appendix, do not copy the screen, type in and
edit your code. Try to keep you code as clear and nice as possible.

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!