View the step-by-step solution to:

class Computer { public: void retail Price(void) { int p = 2* manufactureCost(); printf( "$%d / n", p); // Print p } private:

class Computer {
public:
void retail Price(void) {
int p = 2* manufactureCost();
printf( "$%d / n", p); // Print p
}
private:
virtual int manufactureCost(void) {return 1000;}
};
class IBMComputer: public Computer {
private:
virtual int manufactureCost(void) {return 1500;}
};
int main(void) {
Computer *cPtr = new Computer();
IBMComputer *ibmPtr = new IBMComputer();
Computer *cibmPtr = new IBMComputer();
cPtr->retailPrice();
ibmPtr->retailPrice();
cibmPtr->retailPrice();
return 0;
}
This question asks about how the function calls to retailPrice() are evaluated.
a. Explain which version of manufactureCost() is used in the call cibmPtr-> retailPrice() and why.
b. If the virtual keyword is omitted from the declaration of manufacture Cost in the derived class IBMComputer,
the preceding code will still compile without error and execute. Will manufacture Cost be implemented as a
virtual function in class IBMComputer? Use your knowledge of how C++ is implemented to explain why or
why not.

c.It is possible for the private base-class function to be declared public in the derived class. Does this conflict
with subtyping principles? Explain why or why not in a few words.

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question