Write a function named "containsigh BoolVariable object pointers and a search string. It will return the list of BoolVariable objects that have the variable names containing that given search string (case-insensitive). In addition, it will also return the count of all the variable objects that have the exact match (equal to the search string). Please note that the list can contain pointers to BoolVariable objects as well as any of its derived class objects such as IntVariable objects.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter10: Object-oriented Programming
Section: Chapter Questions
Problem 7RQ
icon
Related questions
Question
C++ only Question 4
Please answer the following questions.
1. Define a class named "BoolVariable" that manages a variable name (string)
and a boolean value (true or false). It should not have default constructor.
The class must at least provide the following methods:
o toString() method that can return a string in the following format:
variable-name(variable-boolean-value) such as isSuccessful(true)
o containsIgnoreCase() that accepts a search string and it will return true if
its variable name contains that string (case-insensitive) and false
otherwise.
Show how this class being used to create objects and call all its methods and show
how they work.
2. Define a new exception class named "VarNameException" that must inherit
from the C++ runtime error class. This class will capture the error case for a
variable name when it is empty, only blanks or starting with a number.
For example, if the user tries to create with a variable name of ",
"Iname", it will generate an exception and this class should capture the reason
and the error value.
*, or
3. Write a new class named "IntVariable" that must inherit from the
"BoolVariable" class. This class manages a variable name (string) and a value
(integer). Please note that this class must make use of inheritance.
The class must at least provide the following methods:
o toString() method that can return a string in the following format:
variable-name(variable-integer-value) such as count(100)
o isGreater() method that accepts another IntVariable object and returns true
if its own integer value is greater than the integer value of the given object
and false otherwise.
Its constructor will generate exception with the right error information
using the VarNameException class whenever it is given a variable name
that can be empty, all blanks or starting with a number.
Transcribed Image Text:Please answer the following questions. 1. Define a class named "BoolVariable" that manages a variable name (string) and a boolean value (true or false). It should not have default constructor. The class must at least provide the following methods: o toString() method that can return a string in the following format: variable-name(variable-boolean-value) such as isSuccessful(true) o containsIgnoreCase() that accepts a search string and it will return true if its variable name contains that string (case-insensitive) and false otherwise. Show how this class being used to create objects and call all its methods and show how they work. 2. Define a new exception class named "VarNameException" that must inherit from the C++ runtime error class. This class will capture the error case for a variable name when it is empty, only blanks or starting with a number. For example, if the user tries to create with a variable name of ", "Iname", it will generate an exception and this class should capture the reason and the error value. *, or 3. Write a new class named "IntVariable" that must inherit from the "BoolVariable" class. This class manages a variable name (string) and a value (integer). Please note that this class must make use of inheritance. The class must at least provide the following methods: o toString() method that can return a string in the following format: variable-name(variable-integer-value) such as count(100) o isGreater() method that accepts another IntVariable object and returns true if its own integer value is greater than the integer value of the given object and false otherwise. Its constructor will generate exception with the right error information using the VarNameException class whenever it is given a variable name that can be empty, all blanks or starting with a number.
4. Write a function named "containsIgnoreCase" that accepts a vector of
BoolVariable object pointers and a search string. It will return the list of
BoolVariable objects that have the variable names containing that given search
string (case-insensitive). In addition, it will also return the count of all the variable
objects that have the exact match (equal to the search string). Please note that the
list can contain pointers to BoolVariable objects as well as any of its derived class
objects such as IntVariable objects.
5. Write a function named “createVariable" that will read in the variable name and
a value (either "true" or "false" or an integer) from the user and create a dynamic
BoolVariable or IntVariable object (using new) depending the value that the user
entered and return its pointer. You can assume the user will enter "true" or "false"
or correct integer value. No error handling for the value is required.
Please note that this function can use cin and cout.
This function must handle all error cases for invalid variable names entered by the
user: empty, all blanks or starting with a number by handling exception using
try-catch. It will print out proper error message and continue to ask the user for
the new value until it is correct name.
Please show how this function is being tested and
print out the correct variable information.
Transcribed Image Text:4. Write a function named "containsIgnoreCase" that accepts a vector of BoolVariable object pointers and a search string. It will return the list of BoolVariable objects that have the variable names containing that given search string (case-insensitive). In addition, it will also return the count of all the variable objects that have the exact match (equal to the search string). Please note that the list can contain pointers to BoolVariable objects as well as any of its derived class objects such as IntVariable objects. 5. Write a function named “createVariable" that will read in the variable name and a value (either "true" or "false" or an integer) from the user and create a dynamic BoolVariable or IntVariable object (using new) depending the value that the user entered and return its pointer. You can assume the user will enter "true" or "false" or correct integer value. No error handling for the value is required. Please note that this function can use cin and cout. This function must handle all error cases for invalid variable names entered by the user: empty, all blanks or starting with a number by handling exception using try-catch. It will print out proper error message and continue to ask the user for the new value until it is correct name. Please show how this function is being tested and print out the correct variable information.
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Function Arguments
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 Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage