当前位置:天才代写 > C++/C代写,c语言代写代考-100%安全,包过 > 代写CS 留学生Homework 13 :计算二进制表达式的值Calculating the value of a binary expression

代写CS 留学生Homework 13 :计算二进制表达式的值Calculating the value of a binary expression

2018-03-24 08:00 星期六 所属: C++/C代写,c语言代写代考-100%安全,包过 浏览:718

Homework 13

 

The goal of this homework is to practice the builder pattern and visitor pattern. In the lecture, you are given an example of parsing a string of a binary expression using the builder patter. In that example, all nodes are of the same class Node, which has two pointers, m_leftChild and m_rightChild. This causes memory waste because all terminal nodes also have these two data members although they have no children. Also, it does not have a visitor that can calculate the value of the binary expression.

 

In this project, you need to design and implement classes to implement the following functionalities:

 

1. Using the builder pattern, given a binary expression as a string, your program can construct a binary expression tree using two types of nodes: terminal nodes, which have no children data members, and nonterminal nodes, which have children data members. You can refer to the example code in the lecture and Homework 12.

 

2. You need to develop a visitor that can calculate the value of a binary expression tree. You may need to use a stack. You may need a function such as istringstream() to convert a string to a value.

 

3. You need to develop classes so that the following main() function will produce the following output. Note that both the terminal node class and the nonterminal class need to have print operations so that they can be used to print out the binary expression tree.

 

int main(int argc, char** argv) { ExpBuilder builder; ExpParser parser;
 
parser.setBuilder(&builder);
 
string input="(((30+500)*70)-(60/50))"; parser.parse(input);
 
Node* root = builder.getExpression(); cout<<input<print();
 
StackBasedCalVisitor sbsv; root->Accept(&sbsv);
 
cout<<endl<<"StackBasedSumVisitor Result: "<<sbsv.getResult()<<endl; return 0;
}

 

 

Output:

 

  (((30+500)*70)-(60/50))
 
(((30+500)*70)-(60/50)) StackBasedSumVisitor Result: 37098.8

 

Due: March 22, 11:59PM, 2018.

 

Turn in one file via handin: the zip file of your whole NetBean directory. No UML. The

 

name of your zip file should be: LastName_FirstName.zip. For example, if your name

 

is 

代写CS&Finance|建模|代码|系统|报告|考试

编程类:C++,JAVA ,数据库,WEB,Linux,Nodejs,JSP,Html,Prolog,Python,Haskell,hadoop算法,系统 机器学习

金融类统计,计量,风险投资,金融工程,R语言,Python语言,Matlab,建立模型,数据分析,数据处理

服务类:Lab/Assignment/Project/Course/Qzui/Midterm/Final/Exam/Test帮助代写代考辅导

  u=199783060,2774173244&fm=58&s=188FA15AB1206D1108400056000040F6&bpow=121&bpoh=75.jpgalipay_pay_96px_533896_easyicon.net.pngpaypal_96px_533937_easyicon.net.pngchina_union_pay_96px_533911_easyicon.net.pngmastercard_pay_96px_533931_easyicon.net.pngasia_pay_96px_533902_easyicon.net.png

本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝或者Upwork交易!

E-mail:850190831@qq.com   微信:BadGeniuscs  工作时间:无休息工作日-早上8点到凌晨3点


如果您用的手机请先保存二维码到手机里面,识别图中二维码。如果用电脑,直接掏出手机果断扫描。

qr.png

 

    关键字:

天才代写-代写联系方式