SlideShare a Scribd company logo
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.pdf
iconsystemsslm
 
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
arihanthtextiles
 
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
aanyajoshi90
 
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
prajeetjain
 
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
illyasraja7
 
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
Louise 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.pdf
sastaindin
 
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
aggarwalshoppe14
 
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
fazanmobiles
 
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
shreeaadithyaacellso
 
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
Citus 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.pdf
ANANDSALESINDIA105
 
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
shreeaadithyaacellso
 
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
spshotham
 
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
herminaherman
 
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.pdf
mukulsingh0025
 
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.pdf
arorasales234
 
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
mail931892
 

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 .pdf
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
Puntaje Puntaje.pdf
Puntaje            Puntaje.pdfPuntaje            Puntaje.pdf
Puntaje Puntaje.pdf
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 
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
addtechglobalmarketi
 

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

The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 

Recently uploaded (20)

The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 

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);