questionclass computer publicvoid retail


Question

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 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 derived class IBMComputer, 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 clarify why or
why not.

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

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: questionclass computer publicvoid retail
Reference No:- TGS0444801

Expected delivery within 24 Hours