n 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 w

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
100%

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.

Welcome to the named 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): quit
Unsupported command. Please try again.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
10 + 20
10
20
30
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
3 * 40
3
40
120
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
exp1 = 100 - 5
100
5
95 NAME (exp1)
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
40 / 5
40
/
5
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
exp2= 300 - 1
300
1
299 NAME(exp2)
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
2-1
2
1
Please enter a command (add, listall,
All expressions:
10
+
3
100
40
300
100
300
+
NAME (exp2)
2
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator
Please enter the operator:
10
2
100
100
40
300
20
40
5
5
2
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator
Please enter the operator:
45
15
5
1
10
30
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
exp3= 15+5
20
15
20
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall
All expressions:
100
40
300
2
15
20
40
expressions: 1
*
express
expressions:
expres
Number of *%* expressions: 0
Largest expression:
299
1
Smallest expression:
20
5
Largest expression:
Smallest expression:
299
1
20 NAME (exp3)
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator
Please enter the operator:
8
40
40
300
1
10
15
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary
Total number of expressions: 7
Number of + expressions: 2
Number of '-' expressions: 3
Number of ***
Number of '/'
listbyoperator, listsummary, and exit): listall
5
30
120
95 NAME(exp1)
20
Number of '+' expressions: 2
Number of '-' expressions: 3
Number of *** expressions: 2
Number of '/' expressions: 1
Number of '%' expressions:
+
0
299
1
299
1
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
50 * 5
95 NAME (exp1)
NAME (exp2)
299
1
50
250
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall
All expressions:
10
501
1
30
120
95 NAME(exp1)
NAME(exp2)
20
5
30
20 NAME (exp3)
30
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary
Total number of expressions: 8
Largest expression:
Smallest expression:
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
exp4 = 500 + 1
500
501 NAME (exp4)
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary
Total number of expressions: 9
Number of '+
expressions: 3
Number of '-' expressions: 3
Number of *** expressions: 2
Number of '/' expressions: 1
Number of '%' expressions:
mbon
n
30
120
95 NAME (exp1)
299 NAME(exp2)
1
20 NAME (exp3)
250
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
10 - 20
10
20
-10
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall
All expressions:
10
3
100
30
120
95 NAME (exp1)
299 NAME (exp2)
1
2
2
15
50
500
10
Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary
Total number of expressions: 10
Number of '+' expressions: 3
Number of expressions: 4
Number of *** expressions: 2
Number of '/' expressions: 1
Number of '%' expressions: 0
²
501
Largest expression:
Smallest expression:
-10
20 NAME (exp3)
250
501 NAME(exp4)
-10
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
abc + 1
Invalid operand. Number is expected.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
1 + + abc
Invalid operand. Number is expected.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
exp10 = abc
= abc + 1
Invalid operand. Number is expected.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
exp10 = 1 + abc
Invalid operand. Number is expected.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
encer
10exp = 10 + 20
ZOEAP
SAP
Invalid expression name. Name must start out with an alphabet character.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
1exp = 1 + 2
Invalid expression name. Name must start out with an alphabet character.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
122
Unsupported expression operator.
Please enter a command (add, listall, listbyoperator, listsummary, and exit): add
Please enter an expression:
= 1?2
exp1
Unsupported expression operator.
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): exit
Thank you. Goodbye.
Transcribed Image Text:Welcome to the named 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): quit Unsupported command. Please try again. Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 10 + 20 10 20 30 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 3 * 40 3 40 120 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: exp1 = 100 - 5 100 5 95 NAME (exp1) Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 40 / 5 40 / 5 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: exp2= 300 - 1 300 1 299 NAME(exp2) Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 2-1 2 1 Please enter a command (add, listall, All expressions: 10 + 3 100 40 300 100 300 + NAME (exp2) 2 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator Please enter the operator: 10 2 100 100 40 300 20 40 5 5 2 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator Please enter the operator: 45 15 5 1 10 30 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: exp3= 15+5 20 15 20 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall All expressions: 100 40 300 2 15 20 40 expressions: 1 * express expressions: expres Number of *%* expressions: 0 Largest expression: 299 1 Smallest expression: 20 5 Largest expression: Smallest expression: 299 1 20 NAME (exp3) Please enter a command (add, listall, listbyoperator, listsummary, and exit): listbyoperator Please enter the operator: 8 40 40 300 1 10 15 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary Total number of expressions: 7 Number of + expressions: 2 Number of '-' expressions: 3 Number of *** Number of '/' listbyoperator, listsummary, and exit): listall 5 30 120 95 NAME(exp1) 20 Number of '+' expressions: 2 Number of '-' expressions: 3 Number of *** expressions: 2 Number of '/' expressions: 1 Number of '%' expressions: + 0 299 1 299 1 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 50 * 5 95 NAME (exp1) NAME (exp2) 299 1 50 250 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall All expressions: 10 501 1 30 120 95 NAME(exp1) NAME(exp2) 20 5 30 20 NAME (exp3) 30 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary Total number of expressions: 8 Largest expression: Smallest expression: Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: exp4 = 500 + 1 500 501 NAME (exp4) Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary Total number of expressions: 9 Number of '+ expressions: 3 Number of '-' expressions: 3 Number of *** expressions: 2 Number of '/' expressions: 1 Number of '%' expressions: mbon n 30 120 95 NAME (exp1) 299 NAME(exp2) 1 20 NAME (exp3) 250 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 10 - 20 10 20 -10 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listall All expressions: 10 3 100 30 120 95 NAME (exp1) 299 NAME (exp2) 1 2 2 15 50 500 10 Please enter a command (add, listall, listbyoperator, listsummary, and exit): listsummary Total number of expressions: 10 Number of '+' expressions: 3 Number of expressions: 4 Number of *** expressions: 2 Number of '/' expressions: 1 Number of '%' expressions: 0 ² 501 Largest expression: Smallest expression: -10 20 NAME (exp3) 250 501 NAME(exp4) -10 Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: abc + 1 Invalid operand. Number is expected. Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 1 + + abc Invalid operand. Number is expected. Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: exp10 = abc = abc + 1 Invalid operand. Number is expected. Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: exp10 = 1 + abc Invalid operand. Number is expected. Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: encer 10exp = 10 + 20 ZOEAP SAP Invalid expression name. Name must start out with an alphabet character. Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 1exp = 1 + 2 Invalid expression name. Name must start out with an alphabet character. Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: 122 Unsupported expression operator. Please enter a command (add, listall, listbyoperator, listsummary, and exit): add Please enter an expression: = 1?2 exp1 Unsupported expression operator. 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): exit Thank you. Goodbye.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Operations of Linked List
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