C++ 编程试题,跪请高手帮忙(2)

来源:百度知道 编辑:UC知道 时间:2024/05/30 07:49:08
具体要求:创建两个类PlayList 和 JukeBox.。PlayList类用数组放一组字符串,还记录了当前字符串的个数。这个类中要设计方法完成以下功能:增加一个字符串,删除一个字符串,获得指定位置的字符串,获得当前字符串的个数,检查字符串数组是否为空,是否已满。其他内容见UML图:

JukeBox类用来测试PlayList类,,它模拟点歌操作。每一个字符串代表歌名。
程序首先提示用户输入歌曲的最大个数,然后创建Pllayist对象。接着程序允许用户选择:

[1] 增加一首歌曲
[2] 播放第一首
[3] 显示歌曲列表
[4] 退出

选项 1, 输入歌曲的名字和歌手的名字
选项 2 显示第一首歌的名字,然后删除
选项 3 显示当前所有歌曲列表
选项4:显示:再见,退出程序

程序运行示例:

*** 点歌台 ***
歌曲最大个数: 2
[1] 增加歌曲
[2] 播放第一首
[3] 显示歌曲列表
[4] 退出
选择 [1-4]: 3
*** 没有歌曲 ***
[1] 增加歌曲
[2] 播放第一首
[3] 显示歌曲列表
[4] 退出
选择 [1-4]: 1
输入歌曲名称和歌手名字 – 周杰伦:听妈妈的话
*** 加入歌曲 ***
周杰伦:听妈妈的话
[1] 增加歌曲
[2] 播放第一首
[3] 显示歌曲列表
[4] 退出
选择 [1-4]: 1
输入歌曲名称和歌手名字 – S.H.E:Super Star
*** 加入歌曲 ***
S.H.E:Super Star
[1] 增加歌曲
[2] 播放第一首
[3] 显示歌曲列表
[4] 退出
选择 [1-4]: 1
*** 不能增加,歌曲表已满 ***
[1] 增加歌曲
[2] 播放第一首
[3] 显示歌曲列表
[4] 退出

#include<iostream>
#include<string>
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<count-1;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)
{
i