Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: Solve problem, design solution and implement using C + + classes and objects Learn how to manipulate a list of C + + objects

Objectives:
Solve problem, design solution and implement using C++ classes and objects
Learn how to manipulate a list of C++ objects using vector class
Use C++ stream to read in data and format output
Description:
Write a command-driven program named "ManageVariableObjects" that will accept the following commands:
=
list
exit
=
save away the variable and its value in the list (array).
If the variable has been assigned before, it simply updates with the new value
Note: the variable-value can now be another variable name.
If the value is another variable name, it will look up and save its value into the new variable.
display the current value of the variable in the following format () such as count(10)
or "undefined"
"list" command will display all the variables and its count
"exit" command will exit the program
Requirements:
1. The program must produce the same expected output as provided.
2. There should be no global variables. Please use only local variables and parameters instead
3. Scanf and printf are not allowed (Please use C++ cin and cout and C++ formatting)
4. It should display "Undefined" when the variable is not assigned yet
5. You must define at least two more C++ classes:
- Variable class that manages variable information such as name and value
- VariableListManager class that manages a list of Variable object pointers (not objects) using the vector class.
It means that the Variable object is outside the vector object and you must create the objects using "new" operator.
6. Simple error check for variable names: cannot start with a digit.
7. There must be at least 5 functions including main()
8. Please do not use arrays. You must use the C++ vector class to manage the list of object pointers.
9. The vector must be a private data member in the "VariableListManager" class. No vector class and object
can be referenced or used outside the VariableListManager class.
10. Please minimize redundant code. Please write functions if you need to perform the same tasks multiple times.
11. There should be at most one return statement in each function.
12. Please do not iterate through the list in the vector more than once for each task and please do not iterate to the end of the list unnecessarily.
13. You should not define the maximum size limit and not to keep track of its actual number of variables separately because the vector object has its size.
14. You can assume that the user enters the variable assignment correctly (e.g. correct '=' operator and integer value separated by blanks)
15. All data members must be declared private in the class.
16. The "Variable" class must not provide the default constructor.
Sample output of a program run:
Please note that the output of the project #1 will continue to work and display the same result.
Here is the new additional run and output:
C:\> ManageVariableObjects
Please enter variable assignment, variable name only or list or exit:
1count
Undefined
count
Undefined
count =10
count(10)
count
count(10)
list
count(10)
Number of variables: 1
total =15
total(15)
list
count(10)
total(15)
Number of variables: 2
duplicate
Undefined
count = duplicate
Undefined
duplicate = count
duplicate(10)
count =12
count(12)
list
count(12)
total(15)
duplicate(10)
Number of variables: 3
total = count
total(12)
list
count(12)
total(12)
duplicate(10)
Number of variables: 3
count
count(12)
total
total(12)
duplicate
duplicate(10)
quantity =25
quantity(25)
list
count(12)
total(12)
duplicate(10)
quantity(25)
Number of variables: 4
count = quantity
count(25)
1count
Undefined
price
Undefined
price = quantity
price(25)
list
count(25)
total(12)
duplicate(10)
quantity(25)
price(25)
Number of variables: 5
duplicate = temp
Undefined
temp = duplicate
temp(10)
quit
Undefined
1count =10
Invalid variable name. Cannot start with a digit.
exit
Exiting...

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions