Question: PLEASE write album.h and album.cpp in c++ IsPlayable - an abstract base class that describes the form of the play() query that must be defined

PLEASE write album.h and album.cpp in c++

IsPlayable - an abstract base class that describes the form of the play() query that must be defined for every concrete class derived from this interface

class IsPlayable {

public: virtual ostream& play(ostream &os) = 0;

};

The play() query receives as its only parameter a reference to anostreamobject and returns a reference to the object received.

  • Song - a class derived from the abstract base class that holds a single song

class Song: public IsPlayable {

private: char *data;

public: void load(ifstream &ifs, int bytes) { data = new char[bytes + 1];

ifs.read (data,bytes); data[bytes] = '\0'; }

ostream& play(ostream &os) { os

};

Your Song class includes, aside from the functions required, a member function named load(). This function receives as its first parameter a reference to an ifstream object and as its second parameter the number of bytes in the song. This function extracts the bytes from the file object and stores them in the Song object.

  • Album - a class derived from the abstract base class that holds an album of songs

Upon instantiation, an Album object receives the name of the file that contains the album of songs. This file has been written in binary format. The data in this file has been written in the following order:

  • the first four bytes hold an unsigned value that specifies the number of songs in the album.
  • the next set of four bytes each holds unsigned values specifying the byte offset from the start of the file to each song in the file and finally to the byte immediately following the last song in the file. For four songs, there are five values of four bytes each.
  • the next set of bytes holds char values representing the notes in the songs in the album. The songs are concatenated to one another with no separator.

Your Album class, aside from the functions required, overloads the subscripting operator to return a reference to the Song identified by the zero-based index received by the operator. If such a song has not been loaded, your function acts appropriately as shown in the example above.

#include "Album.h"

int main(int argc, char* argv[]) {

if (argc > 1) {

Album album(argv[1]);

album.play(cout);

cout

album[5].play(cout);

}

else

cout

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!