Declare a class template called NumericValueClass. This class will have a privat
ID: 3621183 • Letter: D
Question
Declare a class template called NumericValueClass. This class will have a privatemember variable value of the type T and the following public members:
1. A default constructor that will set value to zero.
2. A constructor that will set value to its argument.
3. A setValue function that will set value to its argument if it is greater than zero,
otherwise it will throw a NegativeValue exception .
4. A getValue function that will return value .
5. A NegativeValue class that has a private member variable negVal of the type T
and the following public members:
a. A constructor that will set negVal to its argument.
b. A getValue function that will return negVal.
In the main, ask the user to enter i or d. If the user enters i, create an array with 5 elements
where each element is a NumericValueClass with int as the datatype. Ask the user to
enter positive integers and use them as the argument for the setValue function (called 5
times for each element). Catch the exception that setValue may throw by displaying the
invalid negative value and using the exit(0) function to get out of the program. Next use a
vector of int that will call its push_back member function five times with the return value
of getValue (member function of the array elements) as its argument. Then use the STL
sort algorithm to sort only the last three elements of the vector and display it.
If the user enters d, do exactly the same thing as above except use double as the datatype
and use the STL sort algorithm to sort only the first three elements of the vector.
Explanation / Answer
You should consult the book How to Program C++ by Deitel and Deitel 4th Edition.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.