0 ifqty book minorder discount01 ifqtybook shipping

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: e want to implement the same rule for Book and AudioBook volume discount. •  We can implement 2 iden.cal member func.ons for each of the 2 classes. •  Alterna.vely, we can implement only 1 func.on that takes Book* as the explicit parameter: double VolumeDiscount(int qty, Book* book) { double discount=0.0; if(qty > book->minOrder()) discount+=0.1; if(qty*book->shipping()> book->shippingDis()) discount += 0.1; return discount; } •  Declare minOrder(), shipping() and shippingDis() as virtual func.ons. 2 10/12/12 C++ vs. Java in Dynamic Binding •  C++ manipulates object itself for computa.on. •  Dynamic binding only applies to virtual func.ons on object pointers : AudioBook b(...); Book a=b; //ok a.shipping(); //call Book::shipping() Book* ap=&b; ap->shipping(); //call AudioBook::shipping() •  Java manipulates object reference for computa.on. •  All overriding fu...
View Full Document

Ask a homework question - tutors are online