.


:




:

































 

 

 

 





C++ . . .

( ) ; . Item, Shape Item Box Circle Shape:

class Item

{

public:

virtual void cut ();

virtual void move (Length deltax, Length deltay) = 0;

virtual Boolean pick (Length px, Length py) = 0;

virtual void ungroup () = 0;

};

class Shape: public Item

{

protected:

Length x;

Length y;

public:

void cut ();

void draw () {write (COLOR_FOREGROUND);};

void erase (); {write (COLOR_BACKGROUND);};

void move (Length deltax, Length deltay);

Boolean pick (Length px, Length py) = 0;

void ungroup () { };

virtual void write (Color color) = 0;

};

class Box: public Shape

{

protected:

Length width;

Length height;

public:

Box (Length x0, Length y0, Length width0, Length height0);

Boolean pick (Length px, Length py);

void write (Color color);

};

class Circle: public Shape

{

protected:

Length radius;

public:

Circle (Length x0, Length y0, Length radius0);

Boolean pick (Length px, Length py);

void write (Color color);

};

( ) (, , ). , private, ; , protected public. , , () , (virtual). , write Shape Box Circle, ; , . 0 (virtual void write (Color color) = 0;), ( ). , , . ( ). , , () , .

C++ : .

C++ . , --- Item Group :

class Item{

public:

virtual void cut ();

virtual void move (Length deltax, Length deltay) = 0;

virtual Boolean pick (Length px, Length py) = 0;

virtual void ungroup () = 0;

private:

Group* group;

friend Group::add_item (Item*);

friend Group::remove_item (Item*);

public:

Group* get_group () {return group;};

};

class Group: public Item

{

public:

void cut ();

void move (Length deltax, Length deltay);

Boolean pick (Length px, Length py) = 0;

void ungroup () { };

private:

ItemSet* items;

public:

void add_item (Item*);

void remove_item (Item*);

ItemSet* get_items () {return items;}

};

, ( ) , :

void Group::add_item (Item* item)

{

item->group = this;

items->add (item);

}

void Group::remove_item (Item* item);

{

item->group = 0;

items->remove (item);

}

Group::add_item Group::remove_item (private) Item, Group, (friends) Item.

:

- : ;

- - : .

() . ItemSet ( ):

class ItemSet

{

public:

ItemSet(); //

~ItemSet(); //

void add(Item*); //

void remove(Item*); //

Boolean includes(Item*); //

int size(Item*); //

};

. , .. , .

( ). .

 

5.3.6. C++

C++ ( ). () , , ( , ).

C++ (template). C++ : - -.

- , . - . - - , , , .

C++ STL (Standard Template Library). C++. D.R.Musser, A.Saini STL Tutorial and Reference Guide. C++ Programming with the Standard Template Library Addison-Wesley, 1996 ( http://www.aw.com/cp/musser-saini.html). STL http://weber.u.washington.edu/~bytewave/bytewave_stl.html http://www.ualberta.ca/~nyu/stl/stl.html. , STL ftp://ftp.cs.rpi.edu/pub/stl.





:


: 2016-10-06; !; : 279 |


:

:

, .
==> ...

1357 - | 1183 -


© 2015-2024 lektsii.org - -

: 0.016 .