Please use C language, Show the outout and comment the code.I am having a lot of
ID: 3859529 • Letter: P
Question
Please use C language, Show the outout and comment the code.I am having a lot of trouble with this problem and need to understand how to do this.
Please do not post random stuff as a solution this is my second time posting this question.
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 - Struct definition and related function declarations
Playlist.c - Related function definitions
main.c - 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.
Private data members
char uniqueID[50]
char songName[50]
char artistName[50]
int songLength
PlaylistNode* nextNodePtr
Related functions
CreatePlaylistNode() (1 pt)
InsertPlaylistNodeAfter() (1 pt)
Insert a new node after node
SetNextPlaylistNode() (1 pt)
Set a new node to come after node
GetNextPlaylistNode()
Return location pointed by nextNodePtr
PrintPlaylistNode()
Ex. of PrintPlaylistNode output:
(2) In main(), prompt the user for the title of the playlist. (1 pt)
Ex:
(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:
(4) Implement "Output full playlist" menu option. If the list is empty, output: Playlist is empty (3 pts)
Ex:
(5) Implement the "Add song" menu item. New additions are added to the end of the list. (2 pts)
Ex:
(6) Implement the "Remove song" function. Prompt the user for the unique ID of the song to be removed.(4 pts)
Ex:
(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:
(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:
(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:
Explanation / Answer
Answer:
#include "globals.h" //some global variables are included here
#include <cstdlib> //standard c library
#include "mediaItem.h" //the mediaItem class (you need to write a class that extends this class)
#include "song.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream infile;
song mySong[MAX_SONGS];
int NumberOfSongs;
int myPlaylist[MAX_PLAYLIST];
int PlaylistSize; //counter for size of playlist in array
song *newPlaylist[MAX_PLAYLIST];
bool loadSongList(string filename)
{
infile.open(filename);
string tempArtist, tempTitle, tempLocation;
int i = 0;
if (infile.fail())
{
cout << "The file could not be opened." << endl;
return false;
}
else
{
cout << "File opened successfully." << endl;
infile >> NumberOfSongs;
infile.ignore(1);
while (!infile.eof())
{
getline(infile, tempArtist);
getline(infile, tempTitle);
getline(infile, tempLocation);
mySong[i].setArtist(tempArtist);
mySong[i].setTitle(tempTitle);
mySong[i].setLocation(tempLocation);
i++;
}
infile.close();
return true;
}
}
int getNumberOfSongsInSongList()
{
return NumberOfSongs;
}
string getSongNameFromSongList(int songNum)
{
string tempArtist, tempTitle;
tempArtist = mySong[songNum].getArtist();
tempTitle = mySong[songNum].getTitle();
return tempArtist + " - " + tempTitle;
}
string getSongNameFromPlaylist(int playlistSpot)
{
string tempArtist, tempTitle;
tempArtist = mySong[myPlaylist[playlistSpot]].getArtist();
tempTitle = mySong[myPlaylist[playlistSpot]].getTitle();
return tempArtist + " - " + tempTitle;
}
void addSongToPlaylist(int songNum)
{
mySong[myPlaylist[PlaylistSize]].setArtist(mySong[songNum].getArtist());
mySong[myPlaylist[PlaylistSize]].setTitle(mySong[songNum].getTitle());
mySong[myPlaylist[PlaylistSize]].setLocation(mySong[songNum].getLocation());
mySong[myPlaylist[PlaylistSize]] = mySong[songNum];
newPlaylist[PlaylistSize] = &mySong[songNum];
PlaylistSize++;
}
int getNumberOfSongsInPlaylist()
{
return PlaylistSize;
}
void moveSongDownInPlaylist(int playlistSpot)
{
int temp;
if (playlistSpot >= PlaylistSize - 1)
return;
temp = myPlaylist[playlistSpot + 1];
myPlaylist[playlistSpot + 1] = myPlaylist[playlistSpot];
myPlaylist[playlistSpot] = temp;
}
void removeSongFromPlaylist(int playlistSpot)
{
for (int i = playlistSpot; i < PlaylistSize; i++)
moveSongDownInPlaylist(i);
myPlaylist[PlaylistSize - 1] = 0;
PlaylistSize--;
}
void clearPlaylist()
{
for (int i = 0; i < PlaylistSize; i++)
myPlaylist[i] = 0;
PlaylistSize = 0;
}
void moveSongUpInPlaylist(int playlistSpot)
{
int temp;
if (playlistSpot == 0)
return;
temp = myPlaylist[playlistSpot - 1];
myPlaylist[playlistSpot - 1] = myPlaylist[playlistSpot];
myPlaylist[playlistSpot] = temp;
}
void playSongFromPlaylist(int playlistSpot)
{
mySong[myPlaylist[playlistSpot]].playMedia();
}
void pauseSongFromPlaylist(int playlistSpot)
{
mySong[myPlaylist[playlistSpot]].pauseMedia();
}
void stopSongFromPlaylist(int playlistSpot)
{