Giter VIP home page Giter VIP logo

expressiontree's Introduction

Factory Pattern

Author: Brian Crites (@brrcrites)

You must work in a group of two for this lab

In this lab you will create a factory which can take in user input and generate a correct expression tree, represented by a Base* root node which will be returned to the caller. Your factory should have a single public method Base* parse(char** input, int length). You will need to parse the inputs to generate the corresponding expression tree, and can assume there are no parenthesies and spaces between each number and operator. You also do not need to consider precedence for the operations and can assume they should be executed from left to right. For example, the input 3 + 2 * 6 would result in (3 + 2) * 6 = 30 rather than the normal 3 + (2 * 6) = 15 In the case that the input is invalid you should print an error and return back a nullptr to the caller.

Main

For this lab you should have both a main executable and a test executable. Your main executable should be named calculator and should take the char** argv and the int argc input to main and pass it to the factory. The factory should then convert it to an expression tree, and then you should print the stringify() and evaluate() values of the generated expression tree back to the user.

Note: When you run something like ./calculator 4 * 3 or ./calculator 4 ** 3, Bash will see the * and treat it as a wildcard operator. To avoid this issue, just prepend the * character with \ on the command line. So, you should run ./calculator 4 \* 3 or ./calculator 4 \*\* 3 instead of the commands above.

Unit Testing

When creating unit tests for the factory you can generate mock user input similar to the way it was created in the unit testing lab. Make sure to test that all combinations of operators are being parsed correctly and that it can generate trees with various numbers of operators and operands. You should also test that your factory correctly returns a nullptr when invalid input is provided.

Submission

To receive credit for this lab you must show an example program to your TA that demonstrates the full functionality of this pattern, including any interactions with other patterns. You must also show your TA the tests that you have created for validating that your classes are functioning correctly.

expressiontree's People

Contributors

andreidimaano avatar reem-ali avatar slagu002 avatar

Watchers

 avatar

Forkers

mteng008

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.