I need c++ code
Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp, you will complete the class declaration and class implementation. The following member functions are required:
A description of all of these functions is available in the textbook's chapter 16 (which you should have already studied).
NOTE: Your linked list class should NOT be templated.
Example: If the input is:
3 Linda Ronstadt You're no good 2.30 Rock Elton John Rocket Man 4.41 Rock Antonin Leopold Dvorak Songs my mother taught me 2.24 Classical
where 3 is the number of songs, and each subsequent four lines is an (artist, title, length, genre) record, the output is:
Antonin Leopold Dvorak, Songs my mother taught me, 2.24, Classical Elton John, Rocket Man, 4.41, Rock Linda Ronstadt, You're no good, 2.3, Rock
#ifndef PLAYLIST_H
#define PLAYLIST_H
#include <iostream>
#include <string>
enum class genre_t {ROCK, COUNTRY, POP, CLASSICAL, POLKA};
struct song
{
std::string artist;
std::string title;
float length;
genre_t genre;
song* next;
};
class playlist
{
public:
// TODO: add the required member functions and operator
private:
song* head;
};
#endif
_________________________________________________________________
#include "playlist.h"
// TODO: implement the class member functions and overloaded operator
Output:
Code:
Playlist.h:
Playlist.cpp:
main.cpp:
Updated Output:
Code:
Playlist.h
#ifndef PLAYLIST_H
#define PLAYLIST_H
#include <iostream>
#include <string>
enum genre_t
{
ROCK,
COUNTRY,
POP,
CLASSICAL,
POLKA
};
struct song
{
std::string artist;
std::string title;
float length;
genre_t genre;
song* next;
// added methods for construction and destruction.
song();
void print();
};
class playlist
{
public:
playlist();
playlist(const playlist& play);
playlist& operator=(const playlist& play); // overloaded =
operator.
void addSong(song tune);
void displayList();
private:
void deepCopySongs(const playlist& play);
void destroyList();
private:
song* head;
song* tail;
};
#endif
Playlist.cpp
#include "playlist.h"
using namespace std;
song::song()
{
next = 0;
}
void song::print()
{
std::string genres[7] = {"Rock", "Country", "Pop", "Classical",
"Polka"};
std::cout << artist << "," << title << ","
<< length << "," << genres[genre] <<
endl;
}
// constructor.
playlist::playlist()
{
head = 0;
tail = 0;
}
// copy constructor deep copies the input playlist.
playlist::playlist(const playlist& play)
{
head = 0;
tail = 0;
deepCopySongs(play);
}
// overloaded assignment operetor deep copies the input playlist.
playlist& playlist::operator=(const playlist& play)
{
destroyList(); // destroy the present the list
deepCopySongs(play); // copy the input list.
return *this;
}
// appends the song to the playlist
//void playlist::addSong(song tune)
//{
// song *q = new song();
// q->artist = tune.artist;
// q->title = tune.title;
// q->length = tune.length;
// q->genre = tune.genre;
// if(!head)
// {
// head = q;
// tail = q;
// return;
// }
// tail->next= q;
// tail = q;
//}
// prepends to the list
void playlist::addSong(song tune)
{
song *q = new song();
q->artist = tune.artist;
q->title = tune.title;
q->length = tune.length;
q->genre = tune.genre;
q->next = head;
head = q;
}
// display list of songs
void playlist::displayList()
{
song* p = head;
while(p)
{
p->print();
p = p->next;
}
}
// private method to deep copy the songs as is.
//void playlist::deepCopySongs(const playlist& play)
//{
// song* p = play.head;
// song* q = head, *k = 0;
// while(p)
// {
// q = new song();
// q->artist = p->artist;
// q->title = p->title;
// q->length = p->length;
// q->genre = p->genre;
// p = p->next;
// if(!head)
// {
// head = q;
// k = q;
// continue;
// }
// k->next = q;
// k = q;
// }
//
//}
// adds the songs to the list which would prepend the songs to
the list.
void playlist::deepCopySongs(const playlist& play)
{
song* p = play.head;
song* q = 0, *k = 0;
while(p)
{
addSong(*p);
p = p->next;
}
}
// private method to destroy the list
void playlist::destroyList()
{
song* p = head, *q = 0;
while(p)
{
q = p;
p = p->next;
delete q;
}
head = 0;
tail = 0;
}
Main.cpp:
#include "playlist.h"
using namespace std;
int main()
{
playlist p;
int songs;
std::string genre, artist, title, length;
song s;
s.artist = "Linda Ronstadt";
s.title = "You're no good";
s.length = 2.30;
s.genre = ROCK;
p.addSong(s);
s.artist = "Elton John";
s.title = "Rocket Man";
s.length = 4.41;
s.genre = ROCK;
p.addSong(s);
s.artist = "Antonin Leopold Dvorak";
s.title = "Songs my mother taught me";
s.length = 2.24;
s.genre = CLASSICAL;
p.addSong(s);
p.displayList();
playlist q = p;
playlist r;
r.addSong(s);
r = p;
cout << endl;
cout << "Copy Costructor.." << endl;
q.displayList();
cout << endl;
cout << "assignment operator..." << endl;
r.displayList();
return 0;
}
I need c++ code Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp,...
THE ENTIRE CODE SHOULD BE IN JAVA Playlist (output linked list) Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers...
Program: Playlist (C++) I'm having difficulty figuring out how to get the header file to work. You will be building a linked list. Make sure to keep track of both the head and tail nodes. (1) Create three files to submit. Playlist.h - Class declaration Playlist.cpp - Class definition main.cpp - main() function Build the PlaylistNode class per the following specifications. Note: Some functions can initially be function stubs (empty functions), to be completed in later steps. Default constructor (1...
JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers Johnson Title: The Dude Length: 337 Artist: Quincy Jones...
lab 11 Do not change main.cpp, i need c++ code for queue.h and queue.cpp Given the complete main() function, partial queue class header queue.h, and queue.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor enqueue() dequeue() You may elect to create the following helper functions: isFull() isEmpty() A description of these ADT operations are available in this Zybook and in the textbook's chapter 17. Example: If the input is: 3 Led Zepplin...