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 pt)
Parameterized constructor (1 pt)
Public member functions
InsertAfter() (1 pt)
SetNext() - Mutator (1 pt)
GetID() - Accessor
GetSongName() - Accessor
GetArtistName() - Accessor
GetSongLength() - Accessor
GetNext() - Accessor
PrintPlaylistNode()
Private data members
string uniqueID - Initialized to "none" in default constructor
string songName - Initialized to "none" in default constructor
string artistName - Initialized to "none" in default constructor
int songLength - Initialized to 0 in default constructor
PlaylistNode* nextNodePtr - Initialized to 0 in default constructor
Ex. of PrintPlaylistNode output:
Unique ID: S123 Song Name: Peg Artist Name: Steely Dan Song Length (in seconds): 237
(2) In main(), prompt the user for the title of the playlist. (1
pt)
Ex:
Enter playlist's title: JAMZ
(3) Implement the PrintMenu() function. PrintMenu() takes the
playlist title as a parameter and outputs a menu of options to
manipulate the playlist. Each option is represented by a single
character. Build and output the menu within the function.
If an invalid character is entered, continue to prompt for a
valid choice. Hint: Implement Quit before implementing other
options. Call PrintMenu() in the main() function. Continue to
execute the menu until the user enters q to Quit. (3 pts)
Ex:
JAMZ PLAYLIST MENU a - Add song d - Remove song c - Change position of song s - Output songs by specific artist t - Output total time of playlist (in seconds) o - Output full playlist q - Quit Choose an option:
(4) Implement "Output full playlist" menu option. If the list is
empty, output: Playlist is empty (3 pts)
Ex:
JAMZ - OUTPUT FULL PLAYLIST 1. Unique ID: SD123 Song Name: Peg Artist Name: Steely Dan Song Length (in seconds): 237 2. Unique ID: JJ234 Song Name: All For You Artist Name: Janet Jackson Song Length (in seconds): 391 3. Unique ID: J345 Song Name: Canned Heat Artist Name: Jamiroquai Song Length (in seconds): 330 4. Unique ID: JJ456 Song Name: Black Eagle Artist Name: Janet Jackson Song Length (in seconds): 197 5. Unique ID: SD567 Song Name: I Got The News Artist Name: Steely Dan Song Length (in seconds): 306
(5) Implement the "Add song" menu item. New additions are added to
the end of the list. (2 pts)
Ex:
ADD SONG Enter song's unique ID: SD123 Enter song's name: Peg Enter artist's name: Steely Dan Enter song's length (in seconds): 237
(6) Implement the "Remove song" function. Prompt the user for the
unique ID of the song to be removed.(4 pts)
Ex:
REMOVE SONG Enter song's unique ID: JJ234 "All For You" removed
(7) Implement the "Change position of song" menu option. Prompt the
user for the current position of the song and the desired new
position. Valid new positions are 1 - n (the number of
nodes). If the user enters a new position that is less than 1, move
the node to the position 1 (the head). If the user enters a new
position greater than n, move the node to position
n (the tail). 6 cases will be tested:
Moving the head node (1 pt)
Moving the tail node (1 pt)
Moving a node to the head (1 pt)
Moving a node to the tail (1 pt)
Moving a node up the list (1 pt)
Moving a node down the list (1 pt)
Ex:
CHANGE POSITION OF SONG Enter song's current position: 3 Enter new position for song: 2 "Canned Heat" moved to position 2
(8) Implement the "Output songs by specific artist" menu option.
Prompt the user for the artist's name, and output the node's
information, starting with the node's current position. (2
pt)
Ex:
OUTPUT SONGS BY SPECIFIC ARTIST Enter artist's name: Janet Jackson 2. Unique ID: JJ234 Song Name: All For You Artist Name: Janet Jackson Song Length (in seconds): 391 4. Unique ID: JJ456 Song Name: Black Eagle Artist Name: Janet Jackson Song Length (in seconds): 197
(9) Implement the "Output total time of playlist" menu option.
Output the sum of the time of the playlist's songs (in seconds). (2
pts)
Ex:
OUTPUT TOTAL TIME OF PLAYLIST (IN SECONDS) Total time: 1461 seconds
Here is the code.
compile : g++ Playlist.cpp main.cpp
Playlist.h
#ifndef PLAYLIST_H
#define PLAYLIST_H
#include <iostream>
using namespace std;
class PlaylistNode
{
private:
string uniqueID;
string songName;
string artistName;
int songLength;
PlaylistNode* nextNodePtr;
public:
PlaylistNode();
PlaylistNode(string id, string song, string artist, int len);
PlaylistNode* InsertAfter(string id, string song, string artist,
int len);
void SetNext(PlaylistNode *next);
string GetID();
string GetSongName();
string GetArtistName();
int GetSongLength();
PlaylistNode* GetNext();
void PrintPlaylistNode();
};
#endif
Playlist.cpp
#include "Playlist.h"
#include <iostream>
using namespace std;
PlaylistNode::PlaylistNode()
{
uniqueID = "none";
songName = "none";
artistName = "none";
songLength = 0;
nextNodePtr = 0;
}
PlaylistNode::PlaylistNode(string id, string song, string
artist,int len)
{
uniqueID = id;
songName = song;
artistName = artist;
songLength = len;
nextNodePtr = 0;
}
PlaylistNode* PlaylistNode::InsertAfter(string id, string song,
string artist,int len)
{
nextNodePtr=new PlaylistNode(id,song,artist,len);
return nextNodePtr;
}
void PlaylistNode::SetNext(PlaylistNode *next)
{
nextNodePtr = next;
}
string PlaylistNode::GetID()
{
return uniqueID;
}
string PlaylistNode::GetSongName()
{
return songName;
}
string PlaylistNode::GetArtistName()
{
return artistName;
}
int PlaylistNode::GetSongLength()
{
return songLength;
}
PlaylistNode* PlaylistNode::GetNext()
{
return nextNodePtr;
}
void PlaylistNode::PrintPlaylistNode()
{
cout<<"Unique ID: "<<uniqueID<<endl;
cout<<"Song Name: "<<songName<<endl;
cout<<"Artist Name: "<<artistName<<endl;
cout<<"Song Length(in seconds):
"<<songLength<<endl;
}
main.cpp
#include "Playlist.h"
#include <iostream>
using namespace std;
void PrintMenu(string listName);
void SongsByArtist(PlaylistNode* head);
void TotalTime(PlaylistNode* head);
void OutputFullList(string listname, PlaylistNode *head);
//all below function take head and tail by reference and modify
their values
void AddSong(PlaylistNode* &head, PlaylistNode*
&tail);
void RemoveSong(PlaylistNode* &head, PlaylistNode*
&tail);
void ChangePosition(PlaylistNode* &head, PlaylistNode*
&tail);
int main()
{
string listname;
cout<<"Entr playlist's title: ";
cin>>listname;
PrintMenu(listname);
}
void PrintMenu(string listname)
{
string option;
PlaylistNode *head=0, *tail=0;
while(true)
{
cout<< listname << " PLAYLIST MENU"<<endl;
cout<<"a - Add song"<<endl;
cout<<"d - Remove song"<<endl;
cout<<"c - Change position of song"<<endl;
cout<<"s - Output songs by specific
artist"<<endl;
cout<<"t - Output total time of playlist (in
seconds)"<<endl;
cout<<"o - Output full playlist"<<endl;
cout<<"q - Quit"<<endl;
cout<<"Enter your choice: ";
cin>>option;
if(option =="A" || option == "a")
{
AddSong(head,tail);
cout<<"Finished adding."<<endl;
}
else if (option == "d" || option =="D")
{
RemoveSong(head, tail);
}
else if(option =="c" || option == "C")
{
ChangePosition(head, tail);
}
else if(option =="s" || option=="S")
{
SongsByArtist(head);
}
else if(option =="t" || option =="T")
{
TotalTime(head);
}
else if(option =="o" || option == "O")
{
OutputFullList(listname,head);
}
else if(option == "q" || option =="Q")
{
break;
}
else
{
cout<<"Invalid menu choice!"<<endl;
}
cout<<endl;
}
}
void OutputFullList(string listname, PlaylistNode *head)
{
int i=1;
PlaylistNode *p=head;
cout<<listname << " - OUTPUT FULL
PLAYLIST"<<endl;
while(p != NULL)
{
cout<<i<<"."<<endl;
p->PrintPlaylistNode();
cout<<endl<<endl;
p = p->GetNext();
i++;
}
}
void AddSong(PlaylistNode* &head, PlaylistNode*
&tail)
{
string id, song, artist;
int len;
cout<<"ADD SONG"<<endl;
cout<<"Enter song's unique ID: ";
cin>>id;
getchar();
cout<<"Enter songs's name: ";
getline(cin, song);
cout<<"Enter artist's name: ";
getline(cin, artist);
cout<<"Enter song's length(in seconds): ";
cin>>len;
if(tail == 0)
{
head = tail = new PlaylistNode(id,song,artist,len);
}
else
tail=tail->InsertAfter(id, song, artist, len);
}
void RemoveSong(PlaylistNode* &head, PlaylistNode*
&tail)
{
string id;
PlaylistNode *p= head, *prev=NULL;
cout<<"REMOVE SONG";
cout<<"Enter song's unique ID: ";
cin>>id;
while(p != NULL)
{
if(p->GetID() == id)
{
if(p == head) // removing head node
{
head = p->GetNext();
if(tail == p) //removing the single node whihc is head ad
tail
tail = 0;
}
else
{
prev->SetNext(p->GetNext());
if(tail == p)
tail = prev;
}
cout<<"\"" << p->GetSongName() << "\"
removed."<<endl;
delete p;
return;
}
prev = p;
p = p->GetNext();
}
}
void ChangePosition(PlaylistNode* &head, PlaylistNode*
&tail)
{
int old_pos, new_pos;
PlaylistNode *p=head, *prev=0, *n;
if(head == tail)
{
cout<<"List has less than 2 elements. Can't change
position."<<endl;
return;
}
cout<<"CHANGE POSITION OF SONG"<<endl;
cout<<"Enter song's current position: ";
cin>>old_pos;
cout<<"Enter new position for song: ";
cin>>new_pos;
for(int i=1;p != 0 && i < old_pos; i++)
{
prev = p;
p = p->GetNext();
cout<<p->GetSongName()<<endl;
}
if(p == 0)
return;
if(head == p)
head = p->GetNext();
else
{
prev->SetNext(p->GetNext());
if(tail == p)
tail = prev;
}
p->SetNext(0);
n = p;
p = head;
prev = 0;
//new_pos--;//reduce the location by 1 since we have removed 1 node
for(int i=1; p != 0 && i< new_pos; i++)
{
prev = p;
p = p->GetNext();
}
if(prev == 0)
{
n->SetNext(head);
head = n;
}
else
{
n->SetNext(prev->GetNext());
prev->SetNext(n);
if(tail == prev)
tail = n;
}
}
void SongsByArtist(PlaylistNode *head)
{
int pos = 1;
string name;
PlaylistNode *p=head;
cout<<"OUTPUT SONGS BY SPECIFIC ARTIST"<<endl;
getchar();
cout<<"Enter artist's name: ";
getline(cin, name);
while(p != 0)
{
if(p->GetArtistName() == name)
{
cout<<pos<<"."<<endl;
p->PrintPlaylistNode();
}
p = p->GetNext();
pos++;
}
}
void TotalTime(PlaylistNode *head)
{
int total = 0;
PlaylistNode *p=head;
cout<<"OUTPUT TOTAL TIME OF PLAYLIST (IN SECONDS)";
while(p != 0)
{
total += p->GetSongLength();
p = p->GetNext();
}
cout<<"Total time: "<<total<<" seconds
"<<endl;
}
Program: Playlist (C++) I'm having difficulty figuring out how to get the header file to work....
Ch 8 Program: Playlist (Java)You will be building a linked list. Make sure to keep track of both the head and tail nodes.(1) Create two files to submit.SongEntry.java - Class declarationPlaylist.java - Contains main() methodBuild the SongEntry class per the following specifications. Note: Some methods can initially be method stubs (empty methods), to be completed in later steps.Private fieldsString uniqueID - Initialized to "none" in default constructorstring songName - Initialized to "none" in default constructorstring artistName - Initialized to "none"...
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: constructor copy constructor destructor addSong(song tune) adds a single node to the front of the linked list no return value displayList() displays the linked list as formatted in the example below no return value overloaded assignment operator A description of all of these functions is available in the textbook's...
Introduction In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist. The Base Class, Derived Class and Test Client Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need...
8.7 LAB*: Program: Online shopping cart (Part 2)Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input.This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized...
4.18 Ch 7 Program: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (solution from previous lab assignment is provided in Canvas). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by the quantity, price, and subtotal PrintItemDescription() -...
11.12 LAB*: Program: Online shopping cart (continued)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class to contain a new attribute. (2 pts)item_description (string) - Set to "none" in default constructorImplement the following method for the ItemToPurchase class.print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter.Ex. of print_item_description() output:Bottled Water: Deer Park, 12 oz.(2) Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs...
Introduction Welcome to Rad.io, you've been hired to work on our music streaming app, think of it as Spotify only more rad! You're in charge of handling our customer’s song list. When a user selects a playlist it will load into the list a number of songs. Users can skip to the next song, move to the previous, they can select a song to play next or select a song to add to the end of their list. Objective You...
Please use C programming to write the code to solve the following problem. Also, please use the instructions, functions, syntax and any other required part of the problem. Thanks in advance. Use these functions below especially: void inputStringFromUser(char *prompt, char *s, int arraySize); void songNameDuplicate(char *songName); void songNameFound(char *songName); void songNameNotFound(char *songName); void songNameDeleted(char *songName); void artistFound(char *artist); void artistNotFound(char *artist); void printMusicLibraryEmpty(void); void printMusicLibraryTitle(void); const int MAX_LENGTH = 1024; You will write a program that maintains information about your...
Ch 7 Program: Online shopping cart (continued) (Java)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt)Public member methodssetDescription() mutator & getDescription() accessor (2 pts)printItemCost() - Outputs the item name followed by the quantity, price, and subtotalprintItemDescription() - Outputs the...
Need three seperate files. ShoppingCartManager.java ShoppingCart.java ItemsToPurchase.java These are from part 1 what do you mean by deep study 7.25 LAB*: Program: Online shopping cart (Part 2) Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input This program extends the earlier Online shopping cart program (Consider...