| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 617 人关注过本帖
标题:哥哥姐姐们 ,星期四交作业啊。麻烦你们了
只看楼主 加入收藏
xuehuanv
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-11-25
收藏
 问题点数:0 回复次数:2 
哥哥姐姐们 ,星期四交作业啊。麻烦你们了
Part 2:
Design and implement an interactive notation conversion program that is based on an expression tree. The expression tree consists of a series of expression tree nodes (exp_tree_node class). You have to implement two classes: one for the expression tree node and the other for the expression tree.

    expression tree node class
The expression tree node class has the following two nodes:
1.    Leaf nodes, which contain a number as their entry;
2.    Nonleaf nodes, which contain one of the “+-*/” operators as their entry, and have exactly two children.

For this assignment, you need to design and implement a template expression tree node class (exp_tree_node class) for expression trees, including operations for building expression trees. Also, include a recursive function to evaluate a non-empty expression tree using these rules:
1.    If the tree has only one node (which must be a leaf), then the evaluation of the tree returns the number that is the node’s entry;
2.    If the tree has more than one node, and the root contains ‘+’, then first evaluates the left subtree, then evaluates the right subtree, and adds the results. Other operators ‘-‘, ‘*’ and ‘/’ work in a similar way.

In addition, include recursive functions (infix, postfix and prefix) to print corresponding infix, postfix and prefix notations of the expression tree. Finally, include a print function to print out the expression tree to the standard output (cout) so that users can see the tree visually.

The exp_tree_node class consists of four private data members:
    op_field: stores one of operators if it is a non-leaf node;
   stores “l” if it is a leaf-node.
    data_field: stores a data value.
    left_field: pointer to the left child.
    right_field: pointer to the right child.

Please refer to “exp_tree_node-template.h” for details. Students are required to complete this file and need to write a template implementation of this file.

    expression tree node:
You also need to design and implement a template expression class (expression class) that consists of a series of expression tree nodes. It is a certain type (tree type) of linked list of the exp_tree_node class.

A header file “expression.h” is provided and students are required to implement “expression.template” file.

    The structure of assignment is as follows:


Reading:
    Chapter 10 especially, project 1 in programming projects.

File that you must write: exp_tree_node.h: A template header file defining a simple expression tree node.在这个头文件中定义一个简单的算术表达式的tree 的指针
1.    exp_tree_node.template: An implementation of the template expression tree node class.这个文件是用于控制指针的
2.    expression.template: An implementation of the tree expression class.用于计算的


expression1.rar (84.33 KB)
搜索更多相关主题的帖子: 作业 麻烦 
2008-11-25 21:54
xuehuanv
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-11-25
收藏
得分:0 
附件就是,作业文件,麻烦哥哥们了。
2008-11-25 21:55
xuehuanv
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-11-25
收藏
得分:0 
哥哥姐姐麻烦你们了啊
2008-11-25 22:39
快速回复:哥哥姐姐们 ,星期四交作业啊。麻烦你们了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020767 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved