Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4.  
  5. #define _tmain main
  6. #define _TCHAR char
  7.  
  8. using namespace std;
  9.  
  10. class AudioFormat {
  11. public:
  12. string name;
  13.  
  14. AudioFormat() {}
  15. AudioFormat(string name) {
  16. this->name = name;
  17. }
  18.  
  19. void setName(string name) {
  20. this->name = name;
  21. }
  22.  
  23. };
  24.  
  25. class AudioTrack {
  26. public:
  27. AudioFormat *format;
  28. string name;
  29. int trackPosition = 0;
  30.  
  31. AudioTrack() {
  32. format = new AudioFormat();
  33. }
  34. AudioTrack(AudioFormat *format) {
  35. this->format = format;
  36. }
  37.  
  38. void setName(string name) {
  39. this->name = name;
  40. }
  41.  
  42. int getTrackPosition() {
  43. trackPosition++;
  44. cout << trackPosition;
  45. return this->trackPosition;
  46. }
  47. };
  48.  
  49. class CD {
  50. public:
  51. AudioTrack *songs;
  52. int songsCount = 0;
  53.  
  54. CD() {}
  55. CD(AudioTrack *songs, int songsCount) {
  56. this->songsCount = songsCount;
  57. }
  58.  
  59. void LoadFromFile(string filename) {
  60. //TODO throw exception if for some reasons not possible to read filename
  61. //cout << "CD: Loading from file" << std::endl;
  62. cout << "Load tracks from file." << endl;
  63. ifstream f(filename);
  64. int n = 0;
  65. string temp;
  66. while (!f.eof()) {
  67. f >> temp;
  68. f >> temp;
  69. songsCount++;
  70. }
  71. delete[] songs;
  72. n = songsCount + 1;
  73. songs = new AudioTrack[n];
  74. f.clear();
  75. f.seekg(0, ios::beg);
  76. int i = 0;
  77. while (!f.eof()) {
  78. f >> temp;
  79. songs[i].setName(temp);
  80. f >> temp;
  81. songs[i].format->setName(temp);
  82. i++;
  83. }
  84. f.close();
  85. }
  86.  
  87. void push(AudioTrack * cd) {
  88. songsCount--;
  89. }
  90.  
  91. void remove(int nbr) {
  92. songsCount++;
  93. }
  94.  
  95. friend std::ostream& operator<<(std::ostream & os, const CD & cd)
  96. {
  97. return os;
  98. }
  99.  
  100.  
  101.  
  102. };
  103.  
  104. class DVD: public CD
  105. {
  106. public:
  107. DVD(): CD() {}
  108. DVD(CD * cd1, CD * cd2): CD() { }
  109. };
  110.  
  111. class AudioCD: public CD
  112. {
  113. public:
  114. AudioCD(): CD() { }
  115. AudioCD(const string & name) : CD() { }
  116. AudioCD(const CD * cd): CD(cd) { }
  117. };
  118.  
  119. CD *cd = new CD();
  120.  
  121. class Player
  122. {
  123. public:
  124. CD *cd;
  125. int getTrackIndex;
  126. Player(CD *cd): cd(cd) {
  127.  
  128. }
  129.  
  130. void read() {
  131.  
  132. }
  133.  
  134. void display() {
  135. cout << "Now: " << getTrackIndex << endl;
  136. }
  137.  
  138. void play() {
  139. cout << "Played" << endl;
  140. }
  141.  
  142. void play(int index) {
  143. this->getTrackIndex = index;
  144. cout << "You played audio with index - " << index << endl;
  145. }
  146.  
  147. void load(CD * cd) {
  148.  
  149. }
  150.  
  151. void setVolume(int volume) {
  152. cout << "Volume: "<<volume<< endl;
  153. }
  154.  
  155. void stop() {
  156. cout << "Stoping track with index " << trackIndex << endl;
  157. cout << "Track stopped" << endl;
  158. }
  159.  
  160. void next() {
  161. cout << "Next track" << endl;
  162. }
  163.  
  164. void setTrackIndex(int trackIndex) {
  165. cout << "Changed index with other index " << trackIndex << endl;
  166. }
  167. };
  168.  
  169. template<typename T>
  170. T Max(CD * left, CD * right) {
  171. return left->songs.size() > right->songs.size() ? left : right;
  172. }
  173.  
  174. int main()
  175. {
  176. Player *player;
  177. CD *cd1, *cd2;
  178. DVD *dvd;
  179. cd1 = new AudioCD();
  180.  
  181. cd->LoadFromFile("File.txt");
  182. cd2 = new AudioCD(cd1);
  183.  
  184. // compare AudioCD by audio tracks count
  185. cout << Max<AudioCD>(cd1, cd2) << endl;
  186.  
  187. cd2->remove(1);
  188. cout << Max<AudioCD>(cd1, cd2) << endl;
  189. cd2->push(new AudioTrack(new AudioFormat("MP3")));
  190. cout << Max<AudioCD>(cd1, cd2) << endl;
  191. cd2->push(new AudioTrack(new AudioFormat("WAV")));
  192. cout << Max<AudioCD>(cd1, cd2) << endl;
  193.  
  194. player = new Player(cd1);
  195. //show cd info
  196. player->read();
  197. player->display();
  198. player->play();
  199. while(player->cd->songs[player->getTrackIndex].getTrackPosition() < 10) player->display();
  200. player->next();
  201. player->display();
  202. player->setTrackIndex(10);
  203. player->play();
  204. while(player->cd->songs[player->getTrackIndex].getTrackPosition() < 10) player->display();
  205. player->stop();
  206. player->load(cd2);
  207. player->play(2);
  208. player->setVolume(50);
  209.  
  210. dvd = new DVD(cd1, cd2);
  211. player->load(dvd);
  212. player->play();
  213.  
  214. return 0;
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement