Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago

Question

Different types of Grading?

Answered: 1 week ago