一,根據UML圖編寫具體程序,實現類與類,類與接口之間的聯繫。
二,UML類圖
三,代碼
#define _UMLCLASS_H__
#ifdef _UMLCLASS_H__
//氧氣類
class Oxygen
{
};
//水類
class Water
{
};
//動物類
class Animal
{
private :
bool isLife;
public:
void Metabolism(Oxygen oxygen, Water water);
void Breed();
};
//鳥類
class Brid
{
private:
bool isFeather;
bool isBeak;
public:
void LayingEgg();
};
//雁羣類
class Geese
{
private:
Dayan arrayDayan[]; //大雁數組
public:
void VFly();
void OneFly();
};
//飛行接口
__interface IFly
{
void Fly();
};
//大雁類
class Dayan : public Brid,IFly
{
public:
void LayingEgg();
void Fly();
};
//鴨類
class Duck : public Brid
{
public:
void LayingEgg();
};
//說人話接口
__interface ISpeek
{
void Speek();
};
//唐老鴨類
class DonalDuck : public Duck, ISpeek
{
public :
void Speek();
};
//氣候類
class Climate
{
};
//企鵝類
class Penguin : public Brid
{
private:
Climate climate;
public :
void LayingEgg();
};
#endif /*_UML_CLASS_H__*/