Question
Make an abstract class Number that allows the rest of the code to work correctly. Code: #include using namespace std; //Do not modify anything on
Make an abstract class Number that allows the rest of the code to work correctly.
Code:
#include
using namespace std;
//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);
Number* temp = &n1; //point at the Int
cout << temp->getValue() << endl;
temp = &n2; //point at the Double
cout << temp->getValue() << endl;
}
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