Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #define _tmain main
- #define _TCHAR char
- using namespace std;
- class AudioFormat {
- public:
- string name;
- AudioFormat() {}
- AudioFormat(string name) {
- this->name = name;
- }
- void setName(string name) {
- this->name = name;
- }
- };
- class AudioTrack {
- public:
- AudioFormat *format;
- string name;
- int trackPosition = 0;
- AudioTrack() {
- format = new AudioFormat();
- }
- AudioTrack(AudioFormat *format) {
- this->format = format;
- }
- void setName(string name) {
- this->name = name;
- }
- int getTrackPosition() {
- trackPosition++;
- cout << trackPosition;
- return this->trackPosition;
- }
- };
- class CD {
- public:
- AudioTrack *songs;
- int songsCount = 0;
- CD() {}
- CD(AudioTrack *songs, int songsCount) {
- this->songsCount = songsCount;
- }
- void LoadFromFile(string filename) {
- //TODO throw exception if for some reasons not possible to read filename
- //cout << "CD: Loading from file" << std::endl;
- cout << "Load tracks from file." << endl;
- ifstream f(filename);
- int n = 0;
- string temp;
- while (!f.eof()) {
- f >> temp;
- f >> temp;
- songsCount++;
- }
- delete[] songs;
- n = songsCount + 1;
- songs = new AudioTrack[n];
- f.clear();
- f.seekg(0, ios::beg);
- int i = 0;
- while (!f.eof()) {
- f >> temp;
- songs[i].setName(temp);
- f >> temp;
- songs[i].format->setName(temp);
- i++;
- }
- f.close();
- }
- void push(AudioTrack * cd) {
- songsCount--;
- }
- void remove(int nbr) {
- songsCount++;
- }
- friend std::ostream& operator<<(std::ostream & os, const CD & cd)
- {
- return os;
- }
- };
- class DVD: public CD
- {
- public:
- DVD(): CD() {}
- DVD(CD * cd1, CD * cd2): CD() { }
- };
- class AudioCD: public CD
- {
- public:
- AudioCD(): CD() { }
- AudioCD(const string & name) : CD() { }
- AudioCD(const CD * cd): CD(cd) { }
- };
- CD *cd = new CD();
- class Player
- {
- public:
- CD *cd;
- int getTrackIndex;
- Player(CD *cd): cd(cd) {
- }
- void read() {
- }
- void display() {
- cout << "Now: " << getTrackIndex << endl;
- }
- void play() {
- cout << "Played" << endl;
- }
- void play(int index) {
- this->getTrackIndex = index;
- cout << "You played audio with index - " << index << endl;
- }
- void load(CD * cd) {
- }
- void setVolume(int volume) {
- cout << "Volume: "<<volume<< endl;
- }
- void stop() {
- cout << "Stoping track with index " << trackIndex << endl;
- cout << "Track stopped" << endl;
- }
- void next() {
- cout << "Next track" << endl;
- }
- void setTrackIndex(int trackIndex) {
- cout << "Changed index with other index " << trackIndex << endl;
- }
- };
- template<typename T>
- T Max(CD * left, CD * right) {
- return left->songs.size() > right->songs.size() ? left : right;
- }
- int main()
- {
- Player *player;
- CD *cd1, *cd2;
- DVD *dvd;
- cd1 = new AudioCD();
- cd->LoadFromFile("File.txt");
- cd2 = new AudioCD(cd1);
- // compare AudioCD by audio tracks count
- cout << Max<AudioCD>(cd1, cd2) << endl;
- cd2->remove(1);
- cout << Max<AudioCD>(cd1, cd2) << endl;
- cd2->push(new AudioTrack(new AudioFormat("MP3")));
- cout << Max<AudioCD>(cd1, cd2) << endl;
- cd2->push(new AudioTrack(new AudioFormat("WAV")));
- cout << Max<AudioCD>(cd1, cd2) << endl;
- player = new Player(cd1);
- //show cd info
- player->read();
- player->display();
- player->play();
- while(player->cd->songs[player->getTrackIndex].getTrackPosition() < 10) player->display();
- player->next();
- player->display();
- player->setTrackIndex(10);
- player->play();
- while(player->cd->songs[player->getTrackIndex].getTrackPosition() < 10) player->display();
- player->stop();
- player->load(cd2);
- player->play(2);
- player->setVolume(50);
- dvd = new DVD(cd1, cd2);
- player->load(dvd);
- player->play();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement