If you are developing an address book program with a multimedia function. In addition to storing the usual text information such as name, address, telephone number, this address book can also store photos and sounds (give them the correct pronunciation of their names).
To implement this communication, you can design this:
class Image { // 用于图像数据
public:
Image(const string& imageDataFileName);
...
};
class AudioClip { // 用于声音数据
public:
AudioClip(const string& audioDataFileName);
...
};
class PhoneNumber { ... }; // 用于存储电话号码
class BookEntry { // 通讯录中的条目
public:
BookEntry(const string& name,
const string& address = "",
const string& imageFileName = "",
const string& audioClipFileName = "");
~BookEntry();
// 通过这个函数加入电话号码
void addPhoneNumber(const PhoneNumber& number);
...
private:
string theName; // 人的姓名
string theAddress; // 他们的地址
list thePhones; // 他的电话号码
Image *theImage; // 他们的图像
AudioClip *theAudioClip; // 他们的一段声音片段
};
Each entry in the Address Book has a name data, so you need a constructor with a parameter (see clause 3), but other content (address, image, and sound file names) are optional. Note You should use a Chain list class (list) to store the phone number, which is a container class (container classes) in the standard C + + class library (STL). (see effective C + + clause 49 and the terms of this book 35)