Question: When you run my following program, there is a difference between the expected answer and what I receive. all of it must run in multifiles
When you run my following program, there is a difference between the expected answer and what I receive. all of it must run in multifiles and must implement the following main.cpp. no changes cna be made to that.
thank you.
I feel like the basis of my program is right but please check what needs to be fixed in order to get the right answer. and please tell me what was missing in my code.
Here is the answer when my code runs gets

Here is the expected answer and you can see the slight differences in my code. Especially the last line when you run my code it says
End of PlayList
0
When the right answer should be
end of playlist
1

main.cpp to use
int main() {
//**********Test Song************//
//instantiate 5 songs
Song song1;
song1.setTitle("title 1");
song1.setAuthor("author 1");
song1.setAlbum("album 1");
Song song2("title 2", "author 2", "album 2");
Song song3("title 3", "author 3", "album 3");
Song song4("title 4", "author 4", "album 4");
Song song5("title 5", "author 5", "album 5");
//output song information
cout
cout
cout
cout
//************* Test PlayList*************//
//instantiate PlayList and add Songs to it
PlayList myPlayList(song1);
myPlayList.addSong(song2);
myPlayList.addSong(song3);
myPlayList.displayPlayList();
cout
myPlayList.addSong(song1);
myPlayList.displayPlayList();
cout
myPlayList.addSong(song4);
myPlayList.displayPlayList();
cout
myPlayList.addSong(song5);
myPlayList.displayPlayList();
cout
myPlayList.removeSong(song2);
myPlayList.displayPlayList();
cout
myPlayList.removeSong(song3);
myPlayList.displayPlayList();
cout
myPlayList.clearPlayList();
myPlayList.displayPlayList();
cout
return 0;
}
setinterface.h (this is an abstract class and set implements this method)
#ifndef SET_INTERFACE_H_
#define SET_INTERFACE_H_
#include
template
class SetInterface
{
public:
/** Gets the current number of entries in this set.
@return The integer number of entries currently in the set. */
virtual int getCurrentSize() const = 0;
/** Checks whether this set is empty.
@return True if the set is empty, or false if not. */
virtual bool isEmpty() const = 0;
/** Adds a new entry to this set.
@post If successful, newEntry is stored in the set and
the count of items in the set has increased by 1.
@param newEntry The object to be added as a new entry.
@return True if addition was successful, or false if not. */
virtual bool add(const ItemType& newEntry) = 0;
/** Removes a given entry from this set,if possible.
@post If successful, anEntry has been removed from the set
and the count of items in the set has decreased by 1.
@param anEntry The entry to be removed.
@return True if removal was successful, or false if not. */
virtual bool remove(const ItemType& anEntry) = 0;
/** Removes all entries from this set.
@post set contains no items, and the count of items is 0. */
virtual void clear() = 0;
/** Tests whether this set contains a given entry.
@param anEntry The entry to locate.
@return True if set contains anEntry, or false otherwise. */
virtual bool contains(const ItemType& anEntry) const = 0;
/** Fills a vector with all entries that are in this set.
@return A vector containing all the entries in the set. */
virtual std::vector
}; // end SetfInterface
#endif /* SET_INTERFACE_H_ */
set.cpp
#include "Set.h"
#include
template
Set
{
} // end default constructor
template
int Set
{
return item_count_;
} // end getCurrentSize
template
bool Set
{
return item_count_ == 0;
} // end isEmpty
template
bool Set
{
bool has_room_to_add = (item_count_
if (has_room_to_add)
{
items_[item_count_] = newEntry;
item_count_++;
} // end if
return has_room_to_add;
} // end add
template
bool Set
{
int located_index = getIndexOf(anEntry);
bool can_remove_item = !isEmpty() && (located_index > -1);
if (can_remove_item)
{
item_count_--;
items_[located_index] = items_[item_count_];
} // end if
return can_remove_item;
} // end remove
template
void Set
{
item_count_ = 0;
} // end clear
template
bool Set
{
return getIndexOf(anEntry) > -1;
} // end contains
template
std::vector
{
std::vector
for (int i = 0; i
bag_contents.push_back(items_[i]);
return bag_contents;
} // end toVector
// private
template
int Set
{
bool found = false;
int result = -1;
int search_index = 0;
// If the bag is empty, item_count_ is zero, so loop is skipped
while (!found && (search_index
{
if (items_[search_index] == target)
{
found = true;
result = search_index;
}
else
{
search_index++;
} // end if
} // end while
return result;
} // end getIndexOf
set.h
#ifndef SET_
#define SET_
#include "SetInterface.h"
template
class Set : public SetInterface
{
private:
static const int DEFAULT_SET_SIZE = 4; // Small size to test for a full bag
ItemType items_[DEFAULT_SET_SIZE]; // Array of bag items
int item_count_; // Current count of bag items
int max_items_; // Max capacity of the bag
// Returns either the index of the element in the array items that
// contains the given target or -1, if the array does not contain
// the target.
int getIndexOf(const ItemType& target) const;
public:
Set();
int getCurrentSize() const;
bool isEmpty() const;
bool add(const ItemType& newEntry);
bool remove(const ItemType& anEntry);
void clear();
bool contains(const ItemType& anEntry) const;
std::vector
};
#include "Set.cpp"
#endif
Song.cpp
#include "Song.h" #include
Song::Song():author_(""), album_(""){ }
Song::Song(const string& title, const string& author, const string& album){
title_ = title;
author_ = author;
album_ = album;
}
void Song::setTitle(string title){ //"set" in setTitle here means "give a value" and has nothing
title_ = title ;
}
void Song::setAuthor(string author){
author_ = author;
}
void Song::setAlbum(string album){
album_ = album;
}
string Song::getTitle() const{
return title_;
}
string Song::getAuthor() const{
return author_;
}
string Song::getAlbum() const{
return album_;
}
bool operator==(const Song& lhs, const Song& rhs){
if(lhs.getTitle()==rhs.getTitle() && lhs.getAlbum()==rhs.getAlbum() && lhs.getAuthor()==rhs.getAuthor()){
return true;
}
return false;
}
song.h
#ifndef SONG_H_
#define SONG_H_
#include
using namespace std;
class Song{ private: std::string title_; std::string author_; std::string album_;
public: Song(); Song(const std::string& title, const std::string& author = "", const std::string& album = ""); void setTitle(std::string title); //"set" in setTitle here means "give a value" and has nothing
// to do with the Set class. Similarly for setAuthor and setAlbum void setAuthor(std::string author); void setAlbum(std::string album); std::string getTitle() const; std::string getAuthor() const; std::string getAlbum() const; friend bool operator==(const Song& lhs, const Song& rhs);
}; // end ArrayBag
#endif
playlist.cpp
#include "PlayList.h" #include
PlayList::PlayList(){ }
PlayList::PlayList(const Song& a_song){ playlist_.add(a_song); }
int PlayList::getNumberOfSongs() const{ return playlist_.getCurrentSize();
}
bool PlayList::isEmpty() const{ return (playlist_.isEmpty() == 0);
}
bool PlayList::addSong(const Song& new_song){ playlist_.add(new_song);
return true;
}
bool PlayList::removeSong(const Song& a_song){ playlist_.remove(a_song); return true;
}
void PlayList::clearPlayList(){ playlist_.clear();
}
void PlayList::displayPlayList() const{
cout
std::vector
for (vector
cout
cout
}
Playlist.h
#ifndef PLAYLIST_H_ #define PLAYLIST_H_
#include "Set.h" #include "Song.h"
using namespace std;
class PlayList{ private: Set
};
#endif //comment
Received output: The first song is: title 1, author 1, album 1 The second song is: title 2, author 2, album 2 The third song is: title 3, author 3, album 3 The fourth song is: title 4, author 4, album 4 Playlist contains: * Title: title 1 Author: author 1 Album: album 1* * Title: title 2 Author: author 2 Album: album 2 * Title: title 3 * Author: author 3 Album : album 3 * End of playlist Playlist now holds 3 songs Paytle citte 1si Author: author Album: album *Title: title 2 Author: author 2 Album: album 2 Title: title 3 Title: title1Author: author 1 * Album: album 1 Author: author 3 Abum: abum 3 End of playlist Playlist contains: * Title: title 1 Author: author 1 Album: album 1* Title: title 2 *Author; author 2 Album album 2 * Title: title 3Author: author 3 Album: album 3* Titl: title1Author: author 1 End of playlist ALbum: abum 1 Playlist contains: *Title: title 1 Author: author 1*Album: album 1 * Title:-title 2 Author: author 2 Album: album 2 Title: title 3 * Author: author 3 * Albun: aLbum 3 Title: tite 1 Author: author 1Album: album 1 * End of playlist Playlist contains: : Title: title 1 *Author: author 1 E Album: album 1 * Title: title 1 Author: author I ALbum: album 1 * Title: title 3 Author: author 3 ALbum: album 3 End of playlist Playlist contains: Title: title 1Author: author 1 Title: titte 1w Author: author 1 Album : album 1 Album: album 1 End of pLaylist Playlist contains: End of playlist xpected
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
