int main () { pet dog(”Dog”), cat(”Cat”); food cookie( ”cookies” ), chocolate( ”chocolate”, 7); person dan, danna; dan.buy(&chocolate, 10); dan.buy(&cookie, 5); danna.buy(&chocolate, 2); dog.get( &cookie ); dog.eat(); cat.get( &chocolate ); cat.eat(); cat.eat(); cookie.show(); chocolate.show(); dog.show(); cat.show(); person::show(); return 0; }
|
class food { int count; string name; public: food( string ); food( string, int ); void add( int ); void show(); }; class pet { food ∗ jar; int count; string name; public: pet( string ); void get(food ∗); void eat(); void show(); }; class person { static int count; public: person(); void buy(food ∗ , int); static void show(); };
|
+---------------------+
| +-----+ |
| food | | |
dog | +-----+ *jar |
| +-----+ |
| name | | |
| +-----+ string|
| +-----+ |
| count | | |
| +-----+ int |
+---------------------+ pet
+---------------------+
| +-----+ |
| food | | |
cat | +-----+ *jar |
| +-----+ |
| name | | |
| +-----+ string|
| +-----+ |
| count | | |
| +-----+ int |
+---------------------+ pet
+---------------------+
| +-----+ |
cookie | name | | |
| +-----+ string|
| +-----+ |
| count | | |
| +-----+ int |
+---------------------+ food
+---------------------+
| +-----+ |
chocolate | name | | |
| +-----+ string|
| +-----+ |
| count | | |
| +-----+ int |
+---------------------+ food
+-------------------+
dan | |
+-------------------+ person
+-------------------+
danna | |
+-------------------+ person
+------ person -----+
| +------+ |
| int | | |
| +------+ |
+-------------------+
|