#include
#include
using namespace std;
class PlayList
{
public:
PlayList()
{
list=new string[3];
MaxCount=0;
count=0;
}
PlayList(int maxcount)
{
list=new string[2*maxcount];
MaxCount=maxcount;
count=0;
}
string* list;
int count;
int MaxCount;
void AddSong(string player,string song)
{
list[2*count]=player;
list[2*count+1]=song;
count++;
}
void DelSong(int index)
{
for(int i=index;i
list[2*i]=list[2*(i+1)];
list[2*i+1]=list[2*(i+1)+1];
}
count--;
}
void GetSong(int index){};
string GetString(int index)
{
return list[index];
}
int GetCount()
{
return count;
}
bool IsEmpty()
{
return (count==0);
}
PlayList& operator=(PlayList&playlist)
{
if(&playlist!=this)
{
delete []list;
// list=new string[playlist.MaxCount];
list=playlist.list;
MaxCount=playlist.MaxCount;
count=playlist.count;
return *this;
}else
return *this;
}
};
class JukeBox
{
public:
JukeBox(){};
PlayList PList;
void AddSong()
{
if(PList.GetCount()
cout<<"输入歌曲名称和歌手名字 –";
string temp1,temp2;
cin>>temp1>>temp2;
PList.AddSong(temp1,temp2);
cout<<"*** 加入歌曲 ***"<
cout<<"*** 不能增加,歌曲表已满 ***"<
void Prompt()
{
cout<<"[1] 增加歌曲"<
void PlayFirstSong()
{
if(!PList.IsEmpty())
{
cout<<"***现在播放 ***"<
}else
{
cout<<"*** 没有歌曲 *** "<
};
void ShowList()
{
if(!PList.IsEmpty())
{
cout<<"***当前歌曲列表 ***"<
cout<
}else
cout<<"*** 没有歌曲 *** "<
void Exit()
{
cout<<"*** 欢迎再次光临,再见 ***"<
};
int main()
{
JukeBox jukebox;
cout<<"*** 点歌台 ***"<
cin>>maxcount;
jukebox.PList=PlayList(maxcount);
int choose;
int state=1;
do
{
jukebox.Prompt();
cin>>choose;
switch(choose) {
case 1:
jukebox.AddSong();
break;
case 2:
jukebox.PlayFirstSong();
break;
case 3:
jukebox.ShowList();
break;
case 4:
jukebox.Exit();
state=0;
break;
default:
cout<<"*** 无效操作 ***"<
}
}while(state==1);
return 0;
}
好多哦~
你好意思。。。