SlideShare a Scribd company logo
1 of 8
Download to read offline
Program 02
Based on the previous problem, you should implement this second problem in the same file a05.c.
Find the places in the code marked with the ToDo label and complete the work. You should not
change any other part of the code. This includes do not add any global variables or any other
function. For this problem, we are reusing the same struct from problem 1, but adding a pointer to
the struct to be able to create a linked list. In this problem, you must use linked list to create a user
playlist (play_list).
The struct is holding the information of a song: ID, Name, Singer, Genre, Year, and the pointer
Next (the pointer to the struct).
There should be the following functions. In the similar way we have done in previous assignments,
complete the following functions:
Add a song to the play_list - always inserted at the end of the list. Search song by name - given
the name of the song, return the struct with the data of the song.
Edit a song - given the name of the song, find it in the play_list and modify any of the fields of the
song (ID cannot be edited, and all fields should have a valid value). Return -1 if the song was not
found.
Delete a song - given the name of the song, find it, delete the song from the play_list (i.e.,
disconnect the node from the list). Return -1 if the song was not found, 1 if it was deleted.
// Problem 2
// struct to hold information about a song
struct Song
{
int id;
char name[MAX_SONG_NAME_LENGTH];
char singer[MAX_SINGER_NAME_LENGTH];
genreType genre;
int year;
struct Song *next;
};
// Function declarations
struct Song *createSong(int id, char *name, char *singer, char *genre, int year);
void printPlaylist(struct Song *playlist);
void add_song(struct Song **playlist, struct Song *newSong);
struct Song *search_song(struct Song *playlist, char *name);
int edit_song(struct Song *playlist, char *name, char *singer, char *genre, int
year);
int delete_song(struct Song *playlist, char *name);
// function to create a new song
struct Song *createSong(int id, char *name, char *singer, char *genre, int year)
{
struct Song *newSong = (struct Song *)malloc(sizeof(struct Song));
newSong->id = id;
strcpy(newSong->name, name);
strcpy(newSong->singer, singer);
if (strcmp(genre, "Pop") == 0)
newSong->genre = 1;
else if (strcmp(genre, "Rock") == 0)
newSong->genre = 2;
else if (strcmp(genre, "Reggae") == 0)
newSong->genre = 3;
else if (strcmp(genre, "Country") == 0)
newSong->genre = 4;
else if (strcmp(genre, "Blues") == 0)
newSong->genre = 5;
else if (strcmp(genre, "Balad") == 0)
newSong->genre = 6;
else
newSong->genre = 0;
newSong->year = year;
newSong->next = NULL;
return newSong;
}
// function to print the playlist
void printPlaylist(struct Song *playlist)
{
struct Song *current = playlist;
while (current != NULL)
{
printf("%dt%st%st%dt%dn", current->id, current->name, current->singer,
current->genre, current->year);
current = current->next;
}
}
// function to add a song to the end of the playlist
void add_song(struct Song **playlist, struct Song *newSong)
{
// TODO: Implement function
}
// function to search for a song by name
struct Song *search_song(struct Song *playlist, char *name)
{
// TODO: Implement function
}
// function to edit a song by name
int edit_song(struct Song *playlist, char *name, char *singer, char *genre, int
year)
{
// TODO: Implement function
}
// function to delete a song by name
int delete_song(struct Song *playlist, char *name)
{
// TODO: Implement function
}
void flushSngIn()
{
char c;
do
c = getchar();
while (c != 'n' && c != EOF);
}
int main()
{
// Problem 1
int choice = 0;
int songCount = 0;
char songName_input[MAX_SONG_NAME_LENGTH],
singerName_input[MAX_SINGER_NAME_LENGTH];
char genre_input[20];
unsigned int year_input, add_result = 0;
struct musicRepository music[20];
struct musicRepository *song = NULL;
initializeRepository(music, 20);
music[0].ID = numSongs + 1; numSongs++;
strcpy(music[0].songName,"Shape of You");
strcpy(music[0].singerName,"Ed Sheeran");
music[0].genre=1;
music[0].year=2017;
songCount++;
music[1].ID = numSongs + 1; numSongs++;
strcpy(music[1].songName,"Despacito");
strcpy(music[1].singerName,"Luis Fonsi");
music[1].genre=1;
music[1].year=2017;
songCount++;
music[2].ID = numSongs + 1; numSongs++;
strcpy(music[2].songName,"Uptown Funk");
strcpy(music[2].singerName,"Mark Ronson ft. Bruno Mars");
music[2].genre=1;
music[2].year=2014;
songCount++;
printf("Number of Songs: %d", songCount);
do
{
printf("n");
printf("1. Add a song to the repositoryn");
printf("2. Search song by namen");
printf("3. Print a songn");
printf("4. Edit a songn");
printf("5. Delete a songn");
printf("6. Print full list of songsn");
printf("7. Exitn");
printf("Enter your choice: ");
scanf("%d", &choice);
flushSngIn();
switch (choice)
{
case 1:
printf("nEnter song name: ");
fgets(songName_input, sizeof(songName_input), stdin);
songName_input[strlen(songName_input) - 1] = '0';
// flushSngIn();
// printf("Song name: %sn", songName_input);
printf("Enter singer name: ");
fgets(singerName_input, sizeof(singerName_input), stdin);
singerName_input[strlen(singerName_input) - 1] = '0';
// flushSngIn();
printf("Enter genre ( Pop , Rock , Reggae , Country , Blues , Balad or
unclassified ):");
fgets(genre_input, sizeof(genre_input), stdin);
genre_input[strlen(genre_input) - 1] = '0';
// flushSngIn();
printf("Enter release year: ");
scanf("%d", &year_input);
flushSngIn();
add_result = addSong(music, songName_input, singerName_input,
genre_input, year_input, songCount);
if (add_result == 1)
{
printf("Song added successfullyn");
songCount++;
// printf("Number of Songs: %d", songCount);
// flushSngIn();
printRepository(music, songCount);
break;
}
case 2:
printf("Enter song name: ");
fgets(songName_input, sizeof(songName_input), stdin);
songName_input[strlen(songName_input) - 1] = '0';
flushSngIn();
song = searchSong(music, songName_input, songCount);
printf("Song found: %s, %s, %d, %d", song->songName, song->singerName,
song->genre, song->year);
flushSngIn();
break;
case 3:
if (songCount > 0)
{
int songIndex;
printf("Enter the ID of the song to print (0 to %d): ", songCount -
1);
scanf("%d", &songIndex);
printSong(music, songIndex);
flushSngIn();
break;
}
case 4:
printf("Enter song name: ");
fgets(songName_input, sizeof(songName_input), stdin);
songName_input[strlen(songName_input) - 1] = '0';
flushSngIn();
editSong(music, songCount, songName_input);
break;
case 5:
printf("Enter song name: ");
fgets(songName_input, sizeof(songName_input), stdin);
songName_input[strlen(songName_input) - 1] = '0';
flushSngIn();
deleteSongByName(music, songName_input, songCount);
songCount--;
printRepository(music, songCount);
break;
case 6:
printRepository(music, songCount);
break;
case 7:
printf("Exiting the programn");
break;
default:
printf("Invalid choicen");
break;
}
} while (choice != 7);
// Problem 2
// create some sample songs
struct Song *s1 = createSong(1, "Shape of You", "Ed Sheeran", "Pop", 2017);
struct Song *s2 = createSong(2, "Despacito", "Luis Fonsi", "Pop", 2017);
struct Song *s3 = createSong(3, "Uptown Funk", "Mark Ronson ft. Bruno Mars",
"Pop", 2014);
// create the playlist and add the sample songs
struct Song *playList = NULL;
add_song(&playList, s1);
add_song(&playList, s2);
add_song(&playList, s3);
// print the playlist
printf("Initial Playlist:n");
printPlaylist(playList);
// add a new song to the playlist
struct Song *s4 = createSong(4, "Sorry", "Justin Bieber", "Pop", 2015);
printf("nAdding new song to playlist:n");
add_song(&playList, s4);
printPlaylist(playList);
// delete a song from the playlist
printf("nDeleting a song from the playlist:n");
struct Song *sToDelete = search_song(playList, "Despacito");
if (sToDelete != NULL)
{
delete_song(playList, sToDelete->name);
printf("Playlist after deletion:n");
printPlaylist(playList);
}
else
{
printf("Song not found in playlist.n");
}
// search for a song that doesn't exist in the playlist
printf("nSearching for a song that doesn't exist in the playlist:n");
struct Song *searchResult = search_song(playList, "Non-existent Song");
if (searchResult != NULL)
{
printf("Found song:n");
printf("Song ID: %d, Song Name: %s, Singer Name: %s, Genre: %s, Year: %d",
searchResult->id, searchResult->name, searchResult->singer, searchResult->genre,
searchResult->year);
}
else
{
printf("Song not found in playlist.n");
}
// search for a song that exists in the playlist
printf("nSearching for a song that exists in the playlist:n");
searchResult = search_song(playList, "Uptown Funk");
if (searchResult != NULL)
{
// printf("Found song:n");
// printSong(searchResult);
}
else
{
printf("Song not found in playlist.n");
}
// edit a song in the playlist
printf("nEditing a song in the playlist:n");
int editResult = edit_song(playList, "Shape of You", "Ed Sheeran", "Pop",
2018);
if (editResult == -1)
{
printf("Song not found in playlist.n");
}
else
{
printf("Playlist after edit:n");
printPlaylist(playList);
}
return 0;
}

More Related Content

Similar to Program 02 Based on the previous problem you should impleme.pdf

Write a program in C++ language that implements a music play.pdf
Write a program in C++ language that implements a music play.pdfWrite a program in C++ language that implements a music play.pdf
Write a program in C++ language that implements a music play.pdficonsystemsslm
 
I need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdfI need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdfarihanthtextiles
 
It's not working what am I doing wrong- Given main()- complete the Son.pdf
It's not working what am I doing wrong- Given main()- complete the Son.pdfIt's not working what am I doing wrong- Given main()- complete the Son.pdf
It's not working what am I doing wrong- Given main()- complete the Son.pdfaanyajoshi90
 
Need help with this java project, as the methods are proving to be p.pdf
Need help with this java project, as the methods are proving to be p.pdfNeed help with this java project, as the methods are proving to be p.pdf
Need help with this java project, as the methods are proving to be p.pdfprajeetjain
 
Given main(), complete the SongNode class to include the printSong.pdf
Given main(), complete the SongNode class to include the printSong.pdfGiven main(), complete the SongNode class to include the printSong.pdf
Given main(), complete the SongNode class to include the printSong.pdfillyasraja7
 
Amazing SQL your django ORM can or can't do
Amazing SQL your django ORM can or can't doAmazing SQL your django ORM can or can't do
Amazing SQL your django ORM can or can't doLouise Grandjonc
 
816 LAB Playlist output linked list Hey I have most of.pdf
816 LAB Playlist output linked list Hey I have most of.pdf816 LAB Playlist output linked list Hey I have most of.pdf
816 LAB Playlist output linked list Hey I have most of.pdfsastaindin
 
Here is app.js, artist.js and songs.js file. Can you look at the my .pdf
Here is app.js, artist.js and songs.js file. Can you look at the my .pdfHere is app.js, artist.js and songs.js file. Can you look at the my .pdf
Here is app.js, artist.js and songs.js file. Can you look at the my .pdfaggarwalshoppe14
 
Many of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdfMany of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdffazanmobiles
 
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdfIn C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdfshreeaadithyaacellso
 
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise GrandjoncAmazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise GrandjoncCitus Data
 
Here is the code.compile g++ Playlist.cpp main.cppPlaylist.h.pdf
Here is the code.compile  g++ Playlist.cpp main.cppPlaylist.h.pdfHere is the code.compile  g++ Playlist.cpp main.cppPlaylist.h.pdf
Here is the code.compile g++ Playlist.cpp main.cppPlaylist.h.pdfANANDSALESINDIA105
 
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdfIn C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdfshreeaadithyaacellso
 
1817 LAB Playlist output linked list Given main compl.pdf
1817 LAB Playlist output linked list Given main compl.pdf1817 LAB Playlist output linked list Given main compl.pdf
1817 LAB Playlist output linked list Given main compl.pdfspshotham
 
C++ Programming Search A Linked ListThe Content of songlist.txt.pdf
C++ Programming Search A Linked ListThe Content of songlist.txt.pdfC++ Programming Search A Linked ListThe Content of songlist.txt.pdf
C++ Programming Search A Linked ListThe Content of songlist.txt.pdfherminaherman
 
Structuring Music Using Linked Lists
Structuring Music Using Linked ListsStructuring Music Using Linked Lists
Structuring Music Using Linked ListsCynthia Marcello
 
maincpp include ltiostreamgt include ltstringgt.pdf
maincpp  include ltiostreamgt include ltstringgt.pdfmaincpp  include ltiostreamgt include ltstringgt.pdf
maincpp include ltiostreamgt include ltstringgt.pdfmukulsingh0025
 
Cover Page & Table of Contents
Cover Page & Table of ContentsCover Page & Table of Contents
Cover Page & Table of ContentsMichael Peterson
 
You are required to implement all the classes as specified by UML di.pdf
You are required to implement all the classes as specified by UML di.pdfYou are required to implement all the classes as specified by UML di.pdf
You are required to implement all the classes as specified by UML di.pdfarorasales234
 
I need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdfI need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdfmail931892
 

Similar to Program 02 Based on the previous problem you should impleme.pdf (20)

Write a program in C++ language that implements a music play.pdf
Write a program in C++ language that implements a music play.pdfWrite a program in C++ language that implements a music play.pdf
Write a program in C++ language that implements a music play.pdf
 
I need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdfI need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdf
 
It's not working what am I doing wrong- Given main()- complete the Son.pdf
It's not working what am I doing wrong- Given main()- complete the Son.pdfIt's not working what am I doing wrong- Given main()- complete the Son.pdf
It's not working what am I doing wrong- Given main()- complete the Son.pdf
 
Need help with this java project, as the methods are proving to be p.pdf
Need help with this java project, as the methods are proving to be p.pdfNeed help with this java project, as the methods are proving to be p.pdf
Need help with this java project, as the methods are proving to be p.pdf
 
Given main(), complete the SongNode class to include the printSong.pdf
Given main(), complete the SongNode class to include the printSong.pdfGiven main(), complete the SongNode class to include the printSong.pdf
Given main(), complete the SongNode class to include the printSong.pdf
 
Amazing SQL your django ORM can or can't do
Amazing SQL your django ORM can or can't doAmazing SQL your django ORM can or can't do
Amazing SQL your django ORM can or can't do
 
816 LAB Playlist output linked list Hey I have most of.pdf
816 LAB Playlist output linked list Hey I have most of.pdf816 LAB Playlist output linked list Hey I have most of.pdf
816 LAB Playlist output linked list Hey I have most of.pdf
 
Here is app.js, artist.js and songs.js file. Can you look at the my .pdf
Here is app.js, artist.js and songs.js file. Can you look at the my .pdfHere is app.js, artist.js and songs.js file. Can you look at the my .pdf
Here is app.js, artist.js and songs.js file. Can you look at the my .pdf
 
Many of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdfMany of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdf
 
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdfIn C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
 
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise GrandjoncAmazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
 
Here is the code.compile g++ Playlist.cpp main.cppPlaylist.h.pdf
Here is the code.compile  g++ Playlist.cpp main.cppPlaylist.h.pdfHere is the code.compile  g++ Playlist.cpp main.cppPlaylist.h.pdf
Here is the code.compile g++ Playlist.cpp main.cppPlaylist.h.pdf
 
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdfIn C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
 
1817 LAB Playlist output linked list Given main compl.pdf
1817 LAB Playlist output linked list Given main compl.pdf1817 LAB Playlist output linked list Given main compl.pdf
1817 LAB Playlist output linked list Given main compl.pdf
 
C++ Programming Search A Linked ListThe Content of songlist.txt.pdf
C++ Programming Search A Linked ListThe Content of songlist.txt.pdfC++ Programming Search A Linked ListThe Content of songlist.txt.pdf
C++ Programming Search A Linked ListThe Content of songlist.txt.pdf
 
Structuring Music Using Linked Lists
Structuring Music Using Linked ListsStructuring Music Using Linked Lists
Structuring Music Using Linked Lists
 
maincpp include ltiostreamgt include ltstringgt.pdf
maincpp  include ltiostreamgt include ltstringgt.pdfmaincpp  include ltiostreamgt include ltstringgt.pdf
maincpp include ltiostreamgt include ltstringgt.pdf
 
Cover Page & Table of Contents
Cover Page & Table of ContentsCover Page & Table of Contents
Cover Page & Table of Contents
 
You are required to implement all the classes as specified by UML di.pdf
You are required to implement all the classes as specified by UML di.pdfYou are required to implement all the classes as specified by UML di.pdf
You are required to implement all the classes as specified by UML di.pdf
 
I need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdfI need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdf
 

More from addtechglobalmarketi

Pundits have stated that the recent tax cut mainly benefits .pdf
Pundits have stated that the recent tax cut mainly benefits .pdfPundits have stated that the recent tax cut mainly benefits .pdf
Pundits have stated that the recent tax cut mainly benefits .pdfaddtechglobalmarketi
 
Pt is 76 year old with pneumonia and malnutrition Patient i.pdf
Pt is 76 year old with pneumonia and malnutrition Patient i.pdfPt is 76 year old with pneumonia and malnutrition Patient i.pdf
Pt is 76 year old with pneumonia and malnutrition Patient i.pdfaddtechglobalmarketi
 
Punto 13 Punto 13 Mindy se adapt rpidamente a su puesto en.pdf
Punto 13 Punto 13 Mindy se adapt rpidamente a su puesto en.pdfPunto 13 Punto 13 Mindy se adapt rpidamente a su puesto en.pdf
Punto 13 Punto 13 Mindy se adapt rpidamente a su puesto en.pdfaddtechglobalmarketi
 
Pulse can be palpated on a number of arteries around the bod.pdf
Pulse can be palpated on a number of arteries around the bod.pdfPulse can be palpated on a number of arteries around the bod.pdf
Pulse can be palpated on a number of arteries around the bod.pdfaddtechglobalmarketi
 
Punnett Squares se puede extender ms all de un simple cruc.pdf
Punnett Squares se puede extender ms all de un simple cruc.pdfPunnett Squares se puede extender ms all de un simple cruc.pdf
Punnett Squares se puede extender ms all de un simple cruc.pdfaddtechglobalmarketi
 
pular Madde 5 Aadaki durumda orijinal kaynak materyal b.pdf
pular  Madde 5  Aadaki durumda orijinal kaynak materyal b.pdfpular  Madde 5  Aadaki durumda orijinal kaynak materyal b.pdf
pular Madde 5 Aadaki durumda orijinal kaynak materyal b.pdfaddtechglobalmarketi
 
Puede crear numerosas vistas personalizadas para usar con to.pdf
Puede crear numerosas vistas personalizadas para usar con to.pdfPuede crear numerosas vistas personalizadas para usar con to.pdf
Puede crear numerosas vistas personalizadas para usar con to.pdfaddtechglobalmarketi
 
publie elass h 1 pahlte clamsia axcends A pablie clann Main .pdf
publie elass h 1 pahlte clamsia axcends A pablie clann Main .pdfpublie elass h 1 pahlte clamsia axcends A pablie clann Main .pdf
publie elass h 1 pahlte clamsia axcends A pablie clann Main .pdfaddtechglobalmarketi
 
Puede una empresa ser buena en responsabilidad social corpo.pdf
Puede una empresa ser buena en responsabilidad social corpo.pdfPuede una empresa ser buena en responsabilidad social corpo.pdf
Puede una empresa ser buena en responsabilidad social corpo.pdfaddtechglobalmarketi
 
public class Monster protected String clanAffiliation pro.pdf
public class Monster  protected String clanAffiliation pro.pdfpublic class Monster  protected String clanAffiliation pro.pdf
public class Monster protected String clanAffiliation pro.pdfaddtechglobalmarketi
 
Provide three evidences with scholar reference that support.pdf
Provide three evidences with scholar  reference that support.pdfProvide three evidences with scholar  reference that support.pdf
Provide three evidences with scholar reference that support.pdfaddtechglobalmarketi
 
Provincial Government The name of the representative of the .pdf
Provincial Government The name of the representative of the .pdfProvincial Government The name of the representative of the .pdf
Provincial Government The name of the representative of the .pdfaddtechglobalmarketi
 
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdfPrpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdfaddtechglobalmarketi
 
Provide three evidences with reliable reference that suppor.pdf
Provide three evidences with reliable  reference that suppor.pdfProvide three evidences with reliable  reference that suppor.pdf
Provide three evidences with reliable reference that suppor.pdfaddtechglobalmarketi
 
Provide the Independent variables Dependent variables a.pdf
Provide the Independent variables Dependent variables a.pdfProvide the Independent variables Dependent variables a.pdf
Provide the Independent variables Dependent variables a.pdfaddtechglobalmarketi
 
Provide your example of a firm or a small business from the .pdf
Provide your example of a firm or a small business from the .pdfProvide your example of a firm or a small business from the .pdf
Provide your example of a firm or a small business from the .pdfaddtechglobalmarketi
 
Provide the steps for the following In order to install sof.pdf
Provide the steps for the following In order to install sof.pdfProvide the steps for the following In order to install sof.pdf
Provide the steps for the following In order to install sof.pdfaddtechglobalmarketi
 
Provide land use land cover images and photos using shape.pdf
Provide land use land cover images and photos  using shape.pdfProvide land use land cover images and photos  using shape.pdf
Provide land use land cover images and photos using shape.pdfaddtechglobalmarketi
 
Provide SQL that creates two database tables Employee and D.pdf
Provide SQL that creates two database tables Employee and D.pdfProvide SQL that creates two database tables Employee and D.pdf
Provide SQL that creates two database tables Employee and D.pdfaddtechglobalmarketi
 

More from addtechglobalmarketi (20)

Pundits have stated that the recent tax cut mainly benefits .pdf
Pundits have stated that the recent tax cut mainly benefits .pdfPundits have stated that the recent tax cut mainly benefits .pdf
Pundits have stated that the recent tax cut mainly benefits .pdf
 
Pt is 76 year old with pneumonia and malnutrition Patient i.pdf
Pt is 76 year old with pneumonia and malnutrition Patient i.pdfPt is 76 year old with pneumonia and malnutrition Patient i.pdf
Pt is 76 year old with pneumonia and malnutrition Patient i.pdf
 
Punto 13 Punto 13 Mindy se adapt rpidamente a su puesto en.pdf
Punto 13 Punto 13 Mindy se adapt rpidamente a su puesto en.pdfPunto 13 Punto 13 Mindy se adapt rpidamente a su puesto en.pdf
Punto 13 Punto 13 Mindy se adapt rpidamente a su puesto en.pdf
 
Pulse can be palpated on a number of arteries around the bod.pdf
Pulse can be palpated on a number of arteries around the bod.pdfPulse can be palpated on a number of arteries around the bod.pdf
Pulse can be palpated on a number of arteries around the bod.pdf
 
Puntaje Puntaje.pdf
Puntaje            Puntaje.pdfPuntaje            Puntaje.pdf
Puntaje Puntaje.pdf
 
Punnett Squares se puede extender ms all de un simple cruc.pdf
Punnett Squares se puede extender ms all de un simple cruc.pdfPunnett Squares se puede extender ms all de un simple cruc.pdf
Punnett Squares se puede extender ms all de un simple cruc.pdf
 
pular Madde 5 Aadaki durumda orijinal kaynak materyal b.pdf
pular  Madde 5  Aadaki durumda orijinal kaynak materyal b.pdfpular  Madde 5  Aadaki durumda orijinal kaynak materyal b.pdf
pular Madde 5 Aadaki durumda orijinal kaynak materyal b.pdf
 
Puede crear numerosas vistas personalizadas para usar con to.pdf
Puede crear numerosas vistas personalizadas para usar con to.pdfPuede crear numerosas vistas personalizadas para usar con to.pdf
Puede crear numerosas vistas personalizadas para usar con to.pdf
 
publie elass h 1 pahlte clamsia axcends A pablie clann Main .pdf
publie elass h 1 pahlte clamsia axcends A pablie clann Main .pdfpublie elass h 1 pahlte clamsia axcends A pablie clann Main .pdf
publie elass h 1 pahlte clamsia axcends A pablie clann Main .pdf
 
Puede una empresa ser buena en responsabilidad social corpo.pdf
Puede una empresa ser buena en responsabilidad social corpo.pdfPuede una empresa ser buena en responsabilidad social corpo.pdf
Puede una empresa ser buena en responsabilidad social corpo.pdf
 
public class Monster protected String clanAffiliation pro.pdf
public class Monster  protected String clanAffiliation pro.pdfpublic class Monster  protected String clanAffiliation pro.pdf
public class Monster protected String clanAffiliation pro.pdf
 
Provide three evidences with scholar reference that support.pdf
Provide three evidences with scholar  reference that support.pdfProvide three evidences with scholar  reference that support.pdf
Provide three evidences with scholar reference that support.pdf
 
Provincial Government The name of the representative of the .pdf
Provincial Government The name of the representative of the .pdfProvincial Government The name of the representative of the .pdf
Provincial Government The name of the representative of the .pdf
 
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdfPrpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
 
Provide three evidences with reliable reference that suppor.pdf
Provide three evidences with reliable  reference that suppor.pdfProvide three evidences with reliable  reference that suppor.pdf
Provide three evidences with reliable reference that suppor.pdf
 
Provide the Independent variables Dependent variables a.pdf
Provide the Independent variables Dependent variables a.pdfProvide the Independent variables Dependent variables a.pdf
Provide the Independent variables Dependent variables a.pdf
 
Provide your example of a firm or a small business from the .pdf
Provide your example of a firm or a small business from the .pdfProvide your example of a firm or a small business from the .pdf
Provide your example of a firm or a small business from the .pdf
 
Provide the steps for the following In order to install sof.pdf
Provide the steps for the following In order to install sof.pdfProvide the steps for the following In order to install sof.pdf
Provide the steps for the following In order to install sof.pdf
 
Provide land use land cover images and photos using shape.pdf
Provide land use land cover images and photos  using shape.pdfProvide land use land cover images and photos  using shape.pdf
Provide land use land cover images and photos using shape.pdf
 
Provide SQL that creates two database tables Employee and D.pdf
Provide SQL that creates two database tables Employee and D.pdfProvide SQL that creates two database tables Employee and D.pdf
Provide SQL that creates two database tables Employee and D.pdf
 

Recently uploaded

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Recently uploaded (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

Program 02 Based on the previous problem you should impleme.pdf

  • 1. Program 02 Based on the previous problem, you should implement this second problem in the same file a05.c. Find the places in the code marked with the ToDo label and complete the work. You should not change any other part of the code. This includes do not add any global variables or any other function. For this problem, we are reusing the same struct from problem 1, but adding a pointer to the struct to be able to create a linked list. In this problem, you must use linked list to create a user playlist (play_list). The struct is holding the information of a song: ID, Name, Singer, Genre, Year, and the pointer Next (the pointer to the struct). There should be the following functions. In the similar way we have done in previous assignments, complete the following functions: Add a song to the play_list - always inserted at the end of the list. Search song by name - given the name of the song, return the struct with the data of the song. Edit a song - given the name of the song, find it in the play_list and modify any of the fields of the song (ID cannot be edited, and all fields should have a valid value). Return -1 if the song was not found. Delete a song - given the name of the song, find it, delete the song from the play_list (i.e., disconnect the node from the list). Return -1 if the song was not found, 1 if it was deleted. // Problem 2 // struct to hold information about a song struct Song { int id; char name[MAX_SONG_NAME_LENGTH]; char singer[MAX_SINGER_NAME_LENGTH]; genreType genre; int year; struct Song *next; }; // Function declarations struct Song *createSong(int id, char *name, char *singer, char *genre, int year); void printPlaylist(struct Song *playlist); void add_song(struct Song **playlist, struct Song *newSong); struct Song *search_song(struct Song *playlist, char *name); int edit_song(struct Song *playlist, char *name, char *singer, char *genre, int year); int delete_song(struct Song *playlist, char *name); // function to create a new song struct Song *createSong(int id, char *name, char *singer, char *genre, int year) { struct Song *newSong = (struct Song *)malloc(sizeof(struct Song)); newSong->id = id;
  • 2. strcpy(newSong->name, name); strcpy(newSong->singer, singer); if (strcmp(genre, "Pop") == 0) newSong->genre = 1; else if (strcmp(genre, "Rock") == 0) newSong->genre = 2; else if (strcmp(genre, "Reggae") == 0) newSong->genre = 3; else if (strcmp(genre, "Country") == 0) newSong->genre = 4; else if (strcmp(genre, "Blues") == 0) newSong->genre = 5; else if (strcmp(genre, "Balad") == 0) newSong->genre = 6; else newSong->genre = 0; newSong->year = year; newSong->next = NULL; return newSong; } // function to print the playlist void printPlaylist(struct Song *playlist) { struct Song *current = playlist; while (current != NULL) { printf("%dt%st%st%dt%dn", current->id, current->name, current->singer, current->genre, current->year); current = current->next; } } // function to add a song to the end of the playlist void add_song(struct Song **playlist, struct Song *newSong) { // TODO: Implement function } // function to search for a song by name struct Song *search_song(struct Song *playlist, char *name) { // TODO: Implement function } // function to edit a song by name
  • 3. int edit_song(struct Song *playlist, char *name, char *singer, char *genre, int year) { // TODO: Implement function } // function to delete a song by name int delete_song(struct Song *playlist, char *name) { // TODO: Implement function } void flushSngIn() { char c; do c = getchar(); while (c != 'n' && c != EOF); } int main() { // Problem 1 int choice = 0; int songCount = 0; char songName_input[MAX_SONG_NAME_LENGTH], singerName_input[MAX_SINGER_NAME_LENGTH]; char genre_input[20]; unsigned int year_input, add_result = 0; struct musicRepository music[20]; struct musicRepository *song = NULL; initializeRepository(music, 20); music[0].ID = numSongs + 1; numSongs++; strcpy(music[0].songName,"Shape of You"); strcpy(music[0].singerName,"Ed Sheeran"); music[0].genre=1; music[0].year=2017; songCount++; music[1].ID = numSongs + 1; numSongs++; strcpy(music[1].songName,"Despacito"); strcpy(music[1].singerName,"Luis Fonsi"); music[1].genre=1; music[1].year=2017; songCount++; music[2].ID = numSongs + 1; numSongs++;
  • 4. strcpy(music[2].songName,"Uptown Funk"); strcpy(music[2].singerName,"Mark Ronson ft. Bruno Mars"); music[2].genre=1; music[2].year=2014; songCount++; printf("Number of Songs: %d", songCount); do { printf("n"); printf("1. Add a song to the repositoryn"); printf("2. Search song by namen"); printf("3. Print a songn"); printf("4. Edit a songn"); printf("5. Delete a songn"); printf("6. Print full list of songsn"); printf("7. Exitn"); printf("Enter your choice: "); scanf("%d", &choice); flushSngIn(); switch (choice) { case 1: printf("nEnter song name: "); fgets(songName_input, sizeof(songName_input), stdin); songName_input[strlen(songName_input) - 1] = '0'; // flushSngIn(); // printf("Song name: %sn", songName_input); printf("Enter singer name: "); fgets(singerName_input, sizeof(singerName_input), stdin); singerName_input[strlen(singerName_input) - 1] = '0'; // flushSngIn(); printf("Enter genre ( Pop , Rock , Reggae , Country , Blues , Balad or unclassified ):"); fgets(genre_input, sizeof(genre_input), stdin); genre_input[strlen(genre_input) - 1] = '0'; // flushSngIn(); printf("Enter release year: "); scanf("%d", &year_input); flushSngIn(); add_result = addSong(music, songName_input, singerName_input, genre_input, year_input, songCount); if (add_result == 1)
  • 5. { printf("Song added successfullyn"); songCount++; // printf("Number of Songs: %d", songCount); // flushSngIn(); printRepository(music, songCount); break; } case 2: printf("Enter song name: "); fgets(songName_input, sizeof(songName_input), stdin); songName_input[strlen(songName_input) - 1] = '0'; flushSngIn(); song = searchSong(music, songName_input, songCount); printf("Song found: %s, %s, %d, %d", song->songName, song->singerName, song->genre, song->year); flushSngIn(); break; case 3: if (songCount > 0) { int songIndex; printf("Enter the ID of the song to print (0 to %d): ", songCount - 1); scanf("%d", &songIndex); printSong(music, songIndex); flushSngIn(); break; } case 4: printf("Enter song name: "); fgets(songName_input, sizeof(songName_input), stdin); songName_input[strlen(songName_input) - 1] = '0'; flushSngIn(); editSong(music, songCount, songName_input); break; case 5: printf("Enter song name: "); fgets(songName_input, sizeof(songName_input), stdin); songName_input[strlen(songName_input) - 1] = '0'; flushSngIn(); deleteSongByName(music, songName_input, songCount);
  • 6. songCount--; printRepository(music, songCount); break; case 6: printRepository(music, songCount); break; case 7: printf("Exiting the programn"); break; default: printf("Invalid choicen"); break; } } while (choice != 7); // Problem 2 // create some sample songs struct Song *s1 = createSong(1, "Shape of You", "Ed Sheeran", "Pop", 2017); struct Song *s2 = createSong(2, "Despacito", "Luis Fonsi", "Pop", 2017); struct Song *s3 = createSong(3, "Uptown Funk", "Mark Ronson ft. Bruno Mars", "Pop", 2014); // create the playlist and add the sample songs struct Song *playList = NULL; add_song(&playList, s1); add_song(&playList, s2); add_song(&playList, s3); // print the playlist printf("Initial Playlist:n"); printPlaylist(playList); // add a new song to the playlist struct Song *s4 = createSong(4, "Sorry", "Justin Bieber", "Pop", 2015); printf("nAdding new song to playlist:n"); add_song(&playList, s4); printPlaylist(playList); // delete a song from the playlist printf("nDeleting a song from the playlist:n"); struct Song *sToDelete = search_song(playList, "Despacito"); if (sToDelete != NULL) { delete_song(playList, sToDelete->name); printf("Playlist after deletion:n"); printPlaylist(playList); }
  • 7. else { printf("Song not found in playlist.n"); } // search for a song that doesn't exist in the playlist printf("nSearching for a song that doesn't exist in the playlist:n"); struct Song *searchResult = search_song(playList, "Non-existent Song"); if (searchResult != NULL) { printf("Found song:n"); printf("Song ID: %d, Song Name: %s, Singer Name: %s, Genre: %s, Year: %d", searchResult->id, searchResult->name, searchResult->singer, searchResult->genre, searchResult->year); } else { printf("Song not found in playlist.n"); } // search for a song that exists in the playlist printf("nSearching for a song that exists in the playlist:n"); searchResult = search_song(playList, "Uptown Funk"); if (searchResult != NULL) { // printf("Found song:n"); // printSong(searchResult); } else { printf("Song not found in playlist.n"); } // edit a song in the playlist printf("nEditing a song in the playlist:n"); int editResult = edit_song(playList, "Shape of You", "Ed Sheeran", "Pop", 2018); if (editResult == -1) { printf("Song not found in playlist.n"); } else { printf("Playlist after edit:n"); printPlaylist(playList);