关于收藏CD性质的C++程序编写

来源:百度知道 编辑:UC知道 时间:2024/06/08 13:11:59
建立一个class描述一个CD。 其中包括要建立另外的一个class来描述cd中的歌曲(string 作者, 歌曲名字) 歌曲为array。 Overload the insertion operation to write out a description of a CD. 然后 需要一个add 方法来添加新的歌曲(包括信息)到 CD。In the main function demonstrate the use of the class.
请高手给出完整的程序,谢谢了~!
这是一个C++基础的程序, 就是说 CD 是一个class, 里面有几个固定的歌曲(歌曲song是另一个class),在写一个方法 add 来添加 新的歌曲需要用Add来添加,其中(歌曲内容 包括 歌曲的名字,歌曲的作者),用array(好像叫数组)来存贮所有的歌曲。~~

感谢各位高人~

见注释:

#include<vector>
#include<string>
#include<iostream>
using namespace std;
class SONG
{
public:
SONG(){}
// 带参数的构造函数
SONG(char* name, char* writer):m_Name(name), m_Writer(writer){}
~SONG(){}
void Set(char* name, char* writer){// 设置歌曲
m_Name.clear();
m_Name.assign(name);
m_Writer.clear();
m_Writer.assign(writer);
}
string GetName(void){return m_Name;}
string GetWriter(void){return m_Writer;}
private:
string m_Name; // 歌曲名
string m_Writer; // 歌曲作者
};
class CD
{
public:
CD(){}
CD(char* name):m_NameCD(name){} // 带参数的构造函数
~CD(){}
void InsertCD(void){// 加载插入CD,列出CD信息描述及曲目明细
cout << "The Name of the CD is: " << m_NameCD << endl;
cout << "There are " << m_vSongs.size() << " songs in the CD, and they are listed as follows