计算器-结构体版本

Tree Comprehensive Experiment

Experiment Date:2019年11月30日

One. Experimental purpose

1、Do linear list operations by using basic operations of tree or binary tree.

2、Handle file operations.

3、Deep the understanding of tree and binary tree, gradually develop the programming ability to solve practical problems.

Two. Experimental environment

A computer with Visual Studio.

This experiment has 4 class hours in all.

Three. Experiment content

(Choose one of the following two:)

1、 The directory structure of the specified directory file system is given, you should write into the file dir_structure.txt by the indentation method, and calculate the storage area of the directory.。(The indentation method is shown in P93)

2、 design a “automatic calculator” as follows:

(1)The expression that needs to be calculated is stored in the text file in the TXT text;

(2)Each line in the text is an expression;

(3)Expressions include operands, operators such as addition, subtraction, multiplication and division, and parentheses;

​ For example: (34-72.3)*54.7-82.4

(4)“Automatic calculator” calculates each expression in the text file according to the input file name, and writes every expression of the result to the original file name in the _out.txt, you should use the method of covering and when saving the records. The format of each row is:

​ expression = result。

​ For example:the original file is: A1.txt

​ The file for output is: A1_out.txt

​ The format of the text in A1_out.txt is:

​ (34-72.3)*54.7-82.4 = -2177.41

​ For all the calculated results, you’d keep 4 digits after the decimal point if it is decimal.

(5)Generate a statistical document after the calculation, its content is:

​ Execution time:xxxx-xx-xx hh:mm:ss

​ The total number of expressions is:XXX

​ The number of correct expressions is:XXX

​ The number of error expressions is:XXX

​ Naming rules for filenames:original file name :_log.txt,Write files with append write method。

​ For example:A1.txt corresponding to the statistical file:A1_log.txt

Special remind:★The calculation process requires transform the infix expression to the postfix expression and then transform the postfix expression to expression tree. Finally get the result by calculating the expressions.

(If you are getting into trouble in calculating decimal, you can only consider integer calculation.)

Four.Important data structures

Importantdata structures:
typedef struct Node {			//结构体数组:用来存储读取文件串以后的数据和字符
	double num;					//采用分离的方法,数据为数据、符号为符号
	char op;			
	bool Judge;					//是数字就为ture
}Node;

typedef struct B_Tree			//构建树的时候使用,其实可以使用一个结构体
{
	char op;
	double value;
	bool Judge;
	B_Tree*R;
	B_Tree*L;
}B_Tree;
The main function
int main()
{
	The_Big_Function();
	return 0;
}
The Global function
extern stack<Node> s;			//为了后缀表达式的使用,使用了结构体数组其实就不用转后缀表达式
extern stack<Node> S_ans;		//为了计算最后结果的使用栈,其实可以直接使用第一个栈,因为第一次已经使用完毕了
extern queue<Node> q;			//队列,一开始用串去处理的时候使用的是 数组替代了队列,此时需要多一个全局变量k去计数,但是一样可以操作
extern queue<Node> q2;			
extern stack<B_Tree*> T_Tree;	//指针树栈
extern struct B_Tree* root;		//根节点

Five.Implementation analysis

Program Execution Structure Diagram
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值