Question
add a global function (not a member function of your class) called doPrint that accepts a Number and prints out its value followed by a
add a global function (not a member function of your class) called doPrint that accepts a Number and prints out its value followed by a newline.
code:
#include
using namespace std;
class Number{
public:
virtual double getValue() const = 0;
};
//Do not modify anything on or above the line below this
//YOUR_CODE_BELOW
//YOUR_CODE_HERE
//YOUR_CODE_ABOVE
//Do not modify anything on or below the line above this
class Int : public Number {
private:
int value;
public:
Int(int i) { value = i; }
double getValue() const { return value; }
};
class Double : public Number {
private:
double value;
public:
Double(double d) { value = d; }
double getValue() const { return value; }
};
int main()
{
Int n1(2);
Double n2(1.5);
doPrint(n1);
doPrint(n2);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started