Sams Teach Yourself C++ in 21 Days
476 Day 14 98: break; 99: case 1: sp = new Circle(5); 100: break; 101: case 2: sp = new Rectangle(4,6); 102: break; 103: case 3: ...
Polymorphism 477 14 Squarederives from Rectanglein lines 64–71, and it, too, overrides the GetPerim() method, inheriting the res ...
478 Day 14 5: Shape(){} 6: ~Shape(){} 7: virtual long GetArea() = 0; 8: virtual long GetPerim()= 0; 9: virtual void Draw() = 0; ...
Polymorphism 479 14 It is possible, however, to provide an implementation to a pure virtual function. The function can then be c ...
480 Day 14 35: { 36: cout << “Circle drawing routine here!\n”; 37: Shape::Draw(); 38: } 39: 40: 41: class Rectangle : publ ...
Polymorphism 481 14 83: Square::Square(int len, int width): 84: Rectangle(len,width) 85: 86: { 87: if (GetLength() != GetWidth() ...
482 Day 14 (1)Circle (2)Rectangle (3)Square (0)Quit: 3 x x x x x x x x x x x x x x x x x x x x x x x x x Abstract drawing mechan ...
Polymorphism 483 14 4: 5: enum COLOR { Red, Green, Blue, Yellow, White, Black, Brown } ; 6: 7: class Animal // common base to bo ...
484 Day 14 53: 54: class Horse : public Mammal 55: { 56: public: 57: Horse(int age, COLOR color ): 58: Mammal(age), itsColor(col ...
Polymorphism 485 14 101: switch (choice) 102: { 103: case 1: pAnimal = new Dog(5,Brown); 104: break; 105: case 2: pAnimal = new ...
486 Day 14 advantage of Mammalian reproduction (and a good thing, too!). Fishdoes this in lines 47–48. Mammalclasses no longer h ...
Polymorphism 487 14 You also learned what abstract classes are and how to create abstract classes using pure virtual functions. ...
488 Day 14 Q When should the destructor be made virtual? A The destructor should be made virtual any time you think the class wi ...
Polymorphism 489 14 Exercises .................................................................................................. ...
...
In Review The Week in Review program for Week 2 brings together many of the skills you’ve acquired over the past fortnight and p ...
492 Week 2 LISTINGR2.1 Week 2 in Review Listing 0: // ************************************************** 1: // 2: // Title: Week ...
In Review 493 48: class CarPart : public Part 49: { 50: public: 51: CarPart():itsModelYear(94){} 52: CarPart(int year, int partN ...
494 Week 2 79: } 80: private: 81: int itsEngineNumber; 82: }; 83: 84: AirPlanePart::AirPlanePart(int EngineNumber, int PartNumbe ...
In Review 495 119: PartNode * PartNode::GetNext() const 120: { 121: return itsNext; 122: } 123: 124: Part * PartNode::GetPart() ...
«
21
22
23
24
25
26
27
28
29
30
»
Free download pdf