Expression Recorder on C++

1 300 руб. за проект
06 декабря 2022, 22:59 • 3 отклика • 69 просмотров
C++

Define an "Expression" class that manages expression info: operand1 (integer), operand2 (integer), and the expression operator (char).

It must provide at least the following method:
- toString() to return a string containing all the expression info such as
50 + 50 = 100

Write a command-driven program named "ListExpressions" that will accept the following commands:
add, listall, listbyoperator, listsummary, exit.

  • "add" command will read the expression and save it away in the list
  • "listall" command will display all the expressions
  • "listbyoperator" command will read in the operator and display only expressions with that given operator
  • "listsummary" command will display the total number of expressions, the number of expressions for each operator, the largest and smallest expression values
  • "exit" command will exit the program
Define a "NamedExpression" class that manages named expression info: name (string), operand1 (integer), operand2 (integer), and the expression operator (char).

It must provide at least the following method:
- toString() to return a string containing all the expression info such as
10 + 20 = 30 NAME(exp1)

Write a command-driven program named "ListNamedExpressions" that will accept the following commands:
*add, *listall, *listbyoperator, *listsummary, *exit.

*"add" command will read the expression and save it away in the list
The expression can be entered in either a named or unnamed format.
For example, the user can enter:
10 + 20
or
exp1 = 10 + 20
(where "exp1" is the name of that expression)

Other commands are inherited from "ListExpressions".

Requirements:

-Classes must not store the expression result as a data member because it can be calculated when needed.
- Each expression must be stored in its own Expression object or NamedExpression object.
- It must be using the vector object to manage the list of pointers that can either point to Expression or NamedExpression objects.
- There should be one list of object pointers that point to either Expression or NamedExpression objects (both Expression and NamedExpression objects should be in the same list).
- The expressions must be listed in the same order that the user has entered.

- The program should handle error conditions when the user enters invalid operators, invalid operands, and invalid commands. In addition, the name of the expression must start with an alphabet character (upper or lower case).
- It should display "There is no expression." when no expression is in the list.
- When the user enters "listbyoperator" command and there is no matched expression, it should display a "No expression is found with the operator: <search-operator>" message such as "No expression is found with the operator: @".
- The user should be able to enter either named or unnamed expressions. If there is an error, it should display an informational message to describe the exact error.

- There should be no global variables.
- No - scanf and printf, please use cin, cout, and C++ formatting.
- There should be no multiple return statements in one function or method.
- There must be at least 6 functions in the program.

Expected output attached.
Файлы