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 Requirements: - It must be using the array of pointers to Expression objects to manage the list of Expression objects. Please predefine the size of the array to start at 10. Every time, the array is full, please allocate a new array with 10 more, copy the original array to the new one and free the original one. - There should be no global variables. - No - scanf and printf, please use cin, cout and C++ formatting) - Should handle error conditions when the user enters invalid operators, invalid operands, and invalid commands. - 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: " message such as "No expression is found with the operator: @" - Each expression must be stored in its own Expression object. The expected output is attached.

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter9: Sequential Access Files And Menus
Section: Chapter Questions
Problem 11E
icon
Related questions
Question

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

Requirements:
- It must be using the array of pointers to Expression objects to manage the list of Expression objects. Please predefine the size of the array to start at 10. Every time, the array is full, please allocate a new array with 10 more, copy the original array to the new one and free the original one.
- There should be no global variables.
- No - scanf and printf, please use cin, cout and C++ formatting)
- Should handle error conditions when the user enters invalid operators, invalid operands, and invalid commands.
- 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: @"
- Each expression must be stored in its own Expression object.

The expected output is attached.

Welcome to expression management program.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall
There is no expression.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator
There is no expression.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary
There is no expression.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): list
Unsupported command. Please try again.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): quit
Unsupported command. Please try again.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
10+ 20
10
30
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
1 * 0
1
*
0
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall
All expressions:
10
20
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary
Total number of expressions: 2
Number of '+ expressions: 1
Number of '-' expressions: 0
Number of '*' expressions: 1
Number of '/' expressions:
0
Number of '%' expressions:
0
30
0
20
e
Largest expression:
Smallest expression:
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
9 * 5
9
5
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
2011
201
1
200
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
11 % 3
11
%
3
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
201
11
abc + 5
Invalid operand. Number is expected.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
5 * abc
0
Invalid operand. Number is expected.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
1 % 2
30
0
1
%
2
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
1 ? 2
%
Unsupported expression operator.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
1 $2
Unsupported expression operator.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall
All expressions:
10
1
9
20
0
45
3
2
2
0
5
Largest expression:
Smallest expression:
1
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator
Please enter the operator:
3
2
1
1
9
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator
Please enter the operator:
%
Number of '+ expressions: 1
expressions: 1
Number of '-'
Number of '*' expressions: 2
Number of '/' expressions: e
Number of '%' expressions: 2
200
0
201
1
200
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator
Please enter the operator:
%
30
0
45
200
2
1
11
1
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator
Please enter the operator:
20
0
5
0
45
?
No expression is found with the operator: ?
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator
Please enter the operator:
$
No expression is found with the operator: $
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary
Total number of expressions: 6
2
1
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
-1 1
-1
1
-1
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
300 * 1
300
1
300
Please enter a command (add, listall, listbyoperator, listsummary, and exit): list
Unsupported command. Please try again.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall
All expressions:
10
1
9
201
11
1
-1
300
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary
Total number of expressions: 8
Number of '+' expressions: 1
Number of expressions: 1
Number of *** expressions: 4
Number of '/' expressions:
Number of '%' expressions: 2
Largest expression:
Smallest expression:
300
-1
Please enter a command (add, listall, listbyoperator, listsummary, and exit): quit
30
0
45
200
2
1
-1
300
Unsupported command. Please try again.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): exit
Thank you. Goodbye.
Transcribed Image Text:Welcome to expression management program. Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall There is no expression. Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator There is no expression. Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary There is no expression. Please enter a command (add, listall, listbyoperator, listsummary, and exit): list Unsupported command. Please try again. Please enter a command (add, listall, listbyoperator, listsummary, and exit): quit Unsupported command. Please try again. Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 10+ 20 10 30 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 1 * 0 1 * 0 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall All expressions: 10 20 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary Total number of expressions: 2 Number of '+ expressions: 1 Number of '-' expressions: 0 Number of '*' expressions: 1 Number of '/' expressions: 0 Number of '%' expressions: 0 30 0 20 e Largest expression: Smallest expression: Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 9 * 5 9 5 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 2011 201 1 200 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 11 % 3 11 % 3 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 201 11 abc + 5 Invalid operand. Number is expected. Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 5 * abc 0 Invalid operand. Number is expected. Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 1 % 2 30 0 1 % 2 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 1 ? 2 % Unsupported expression operator. Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 1 $2 Unsupported expression operator. Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall All expressions: 10 1 9 20 0 45 3 2 2 0 5 Largest expression: Smallest expression: 1 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator Please enter the operator: 3 2 1 1 9 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator Please enter the operator: % Number of '+ expressions: 1 expressions: 1 Number of '-' Number of '*' expressions: 2 Number of '/' expressions: e Number of '%' expressions: 2 200 0 201 1 200 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator Please enter the operator: % 30 0 45 200 2 1 11 1 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator Please enter the operator: 20 0 5 0 45 ? No expression is found with the operator: ? Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator Please enter the operator: $ No expression is found with the operator: $ Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary Total number of expressions: 6 2 1 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: -1 1 -1 1 -1 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 300 * 1 300 1 300 Please enter a command (add, listall, listbyoperator, listsummary, and exit): list Unsupported command. Please try again. Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall All expressions: 10 1 9 201 11 1 -1 300 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary Total number of expressions: 8 Number of '+' expressions: 1 Number of expressions: 1 Number of *** expressions: 4 Number of '/' expressions: Number of '%' expressions: 2 Largest expression: Smallest expression: 300 -1 Please enter a command (add, listall, listbyoperator, listsummary, and exit): quit 30 0 45 200 2 1 -1 300 Unsupported command. Please try again. Please enter a command (add, listall, listbyoperator, listsummary, and exit): exit Thank you. Goodbye.
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning