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
Get step-by-step solutions from verified subject matter experts
