Question 5 C++ only

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Question 5 C++ only
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.
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.
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Table
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education