设计一个cd播放器CDPlayer(C++)
发布日期:2021-05-10 08:25:45 浏览次数:12 分类:精选文章

本文共 2254 字,大约阅读时间需要 7 分钟。

#include 
#include
#include
using namespace std;class CD {public: CD(string name, string songs[]) { singer = name; for (int i = 0; i < 6; i++) { this->songs[i] = songs[i]; } } string getSinger(); string getSong(int index); void listSongs() { cout << "Singer's Name : " << singer << endl; for (int i = 0; i < 6; i++) { cout << i + 1 << '.' << songs[i] << endl; } }private: string singer; string songs[6];};class CDPlayer {public: void showMenu() { cout << setfill('*') << setw(24) << '*' << endl; cout << '*' << "1. ������CD" << setfill(' ') << setw(14) << '*' << endl; cout << '*' << "2. ������CD" << setfill(' ') << setw(14) << '*' << endl; cout << '*' << "3. ������CD" << setfill(' ') << setw(14) << '*' << endl; cout << '*' << "0. ������" << setfill(' ') << setw(16) << '*' << endl; cout << setfill('*') << setw(24) << '*' << endl; } void insertCD(CD* cd) { if (cdIn) { cout << "���������CD"; } else { cout << "���������������������CD......" << endl; this->cd = cd; cdIn = 1; } } CD* ejectCD() { if (cd) { cout << "���������������������CD......" << endl; return cd; } else return NULL; } void play() { if (!cdIn) cout << "Please insert CD first" << endl; else { cout << "������������������������CD......" << endl; cd->listSongs(); } }private: CD* cd; bool cdIn = 0;};int main() { string name; string songs[6]; cout << "������CD......" << endl; cout << "Singer's Name:" << endl; cin >> name; for (int i = 0; i < 6; i++) { cout << "song " << (i + 1) << ":" << endl; cin >> songs[i]; } CD cd(name, songs); cd.listSongs(); CDPlayer player; player.showMenu(); player.play(); player.insertCD(&cd); player.play(); CD* ejectedCd = player.ejectCD();}

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

上一篇:标签中引用文件的绝对路径和相对路径
下一篇:编写购物车结算程序(C++)

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2025年04月15日 20时38分55秒