10 polymorphism
TRANSCRIPT
- 1. - 2 10. . 2
2. Challenges
- ( StackAggregatingArray ,StackDerivedFromArray ,StackOnList)
- / ( DoubleList, CyclicList)
- Mixin() : ( PeekBack , Iterated)
3.
- classParallelogram
- {
- protected :
- double _ height;
- double _ width;
- double _ angle;
- public :
- Parallelogram ( doubleh,doublew,doublea);
- doublearea()const ;
- doubleheight()const ;
- doublewidth()const ;
- doubleangle()const ;
- };
4.
- ( )
- classRhombus:publicParallelogram
- {
- public :
- Rhombus ( doubleh,doublea) :
- Parallelogram (h, h, a){ };
- };
5.
- classRectangle:publicParallelogram
- {
- public :
- static constdouble pi = 3.1415926535897932;
- Rectangle ( doubleh,doublew) :
- Parallelogram (h, w, pi/2){ };
- doublearea()double
- {
- return_height *_ width;
- }
- };
6. 7.
- ,
- Rhombus rh(10, pi/4);
- rh.area(); rh.height(); rh.width(); rh.angle();
- Rectangle rec(10,20);
- //
- rec.area();
- //
- Parallelogram :: rec.area();
- rec.height(); rec.width(); rec.angle();
8.
- classRectangle:publicParallelogram
- {
- private :
- using Parallelogram ::area();
- public :
- static constdouble pi = 3.1415926535897932;
- Rectangle ( doubleh,doublew) :
- Parallelogram (h, w, pi/2){ };
- doublearea()double ;
- };
9. Mixin() :
- classPredator
- {
- private :
- string _name;
- string _favoritePray;
- public :
- Predator (string name, pray);
- };
10. Mixin:
- classPet
- {
- private :
- string _name;
- string _favoriteToy;
- public :
- Pet (string name, string toy);
- };
11. Mixin:
- classCat:publicPredator,publicPet
- {
- private :
- static unsigned int _freeID;
- unsigned int_myCatID;
- public :
- Cat (string name, string toy, string prey):
- _myCatID (_freeID++),
- Predator (name, prey), Pet (name, toy){ };
- };
12. Mixin:
- classCat:publicPredator, p ublicPet
13. Consistency()
- '?
- const string&Predator :: rename (string newname)
- {
- returnname = newname;
- }
- voidcat::show()const {
- coutwhoAmI();
32.
- ( )
- ' , ',
- Parallelogram par=Rectangle(10, 20);
33.
- ()
- classStack
- {
- public :
- virtual ~Stack () {} ;
- virtual constElem& top() const =0;
- virtual voidpop() =0;
- virtual voidpush( const Elem &value) =0;
- };
34.
- ,
- ,
- ' (?)
35.
- classStackAggregatingArray: publicStack
- {
- public :
- StackAggregatingArray ( size_t );
- ~StackAggregatingArray ();
- constElem& top() const;
- voidpop() ;
- voidpush( const Elem &value) ;
- private :
- static constsize_t_ bos;
- size_t _top;
- Array _array ;
- };
36.
- classStackAggregatingArray: publicStack
- {
- public :
- StackAggregatingArray ( size_t );
- virtual~StackAggregatingArray ();
- virtualconstElem& top() const;
- virtualvoidpop() ;
- virtualvoidpush( const Elem &value) ;
- private :
- static constsize_t_ bos;
- size_t _top;
- Array _stackArray ;
- };
37. 38.
- ()
- , ,
39.
- voidprocess(Stack & stack)
- {
- cout