// CIS 235 #include using std::cout; using std::endl; #include "invent.h" #include "pen.h" #include "book.h" invent makeInvent( long cd, long n, double cst, double pr); void main() { makeInvent(100, 3, 3.45, 5.40).print(cout); pen p; p.kinput().print(cout); cout << "The cost of the pen is " << p.getCost() << endl; pen qqq(3,56,2.3,4.54,"RED"); pen second(p); cout << "Second is \n"; second.print(cout); book b; b.kinput().print(cout); // Use inherited functions to raise the price 10% b.setPrice( 1.1 * b.getPrice()); cout << "The data in b \n"; b.print(cout); // test identify functions cout << p.identify() << endl; // although static, called with a member cout << b.identify() << endl; // *************************************************************** // How to call inherited overridden methods book myBook(1234,25,12.50,24.30,'Y'); myBook.print(cout); // 1 - scoping myBook.invent::print(cout); // 2 - base class alias, does NOT apply to virtual methods invent & aliasMyBook = myBook ; aliasMyBook.print(cout); // 3 - cast the object - ONLY USE TO CALL CONST MEMBER FUNCTIONS static_cast(myBook).print(cout); // 4 - base class pointer, does NOT apply to virtual methods invent * ptr; ptr = & myBook; ptr->print(cout); (*ptr).print(cout); cout << endl; return; } invent makeInvent( long cd, long n, double cst, double pr) { return invent(cd, n, cst, pr); } /* Code: 100 Quantity: 3 Cost: 3.45 Price: 5.4 Inventory object leaving at address 0012FD14 *** return value of makeInvent Enter data for a pen Enter code, number, cost, price 456 200 .85 2.10 Enter the pen color blue Code: 456 Quantity: 200 Cost: 0.85 Price: 2.1 Color: blue The cost of the pen is 0.85 Second is Code: 456 Quantity: 200 Cost: 0.85 Price: 2.1 Color: blue Enter data for a book Enter code, number, cost, price 7894 10 34.00 57.50 Enter y if hardback y Code: 7894 Quantity: 10 Cost: 34 Price: 57.5 Type: Hardback The data in b Code: 7894 Quantity: 10 Cost: 34 Price: 63.25 Type: Hardback pen book Code: 1234 Quantity: 25 Cost: 12.5 Price: 24.3 Type: Hardback Code: 1234 Quantity: 25 Cost: 12.5 Price: 24.3 Code: 1234 Quantity: 25 Cost: 12.5 Price: 24.3 Code: 1234 Quantity: 25 Cost: 12.5 Price: 24.3 Inventory object leaving at address 0012FD84 *** from casting myBook Code: 1234 Quantity: 25 Cost: 12.5 Price: 24.3 Code: 1234 Quantity: 25 Cost: 12.5 Price: 24.3 Book object leaving at address 0012FE7C *** book myBook - last object created Inventory object leaving at address 0012FE7C Book object leaving at address 0012FEA4 *** book b - 4th object created Inventory object leaving at address 0012FEA4 Pen object leaving at address 0012FECC *** pen second - 3rd object created Inventory object leaving at address 0012FECC Pen object leaving at address 0012FEFC *** pen qqq - 2nd object created Inventory object leaving at address 0012FEFC Pen object leaving at address 0012FF2C *** pen p - first object created Inventory object leaving at address 0012FF2C Press any key to continue . . . */