Hey I was wondering if someone could answer this question for me in C++ All that
ID: 663816 • Letter: H
Question
Hey I was wondering if someone could answer this question for me in C++
All that's needed is a header file (.h file)
Inherit from the Number class to create a new class named ComplexNumber.
This class will add an additional protected variable (for the imaginary
part). Add setImaginary and getImaginary functions to this class. These
functions will do the same thing as the getValue and setValue functions, but
for the imaginary part that only the ComplexNumber has.
Important concept: You can NOT override the getNumber and setNumber functions
to, for example, add an additional parameter to setNumber for the imaginary
component. This would change the function signature so you would just be
making a new function.
The idea of a template class inheriting from another template class may be
confusing; the syntax will look like this:
template<typename T>
class ComplexNumber : public Number<T> {
};
Explanation / Answer
template<typename T>
class ComplexNumber : public Number<T> {
protected:
double imaginary;
public:
void setImaginary(double im);
double getImaginary();
};