SlideShare a Scribd company logo
1 of 6
Download to read offline
Can someone please help me complete the "add_song" function below. Thank you!
// Each song has this information: song's id, song's name, singer's name, genre of the song, and
its published year.
// The struct 'musicRepository' holds information of one song. Genre is enum type.
// An array of structs called 'list' is made to hold the list of songs.
// You should not modify any of the given code, the return types, or the parameters, you will risk of
getting compilation error.
// You are not allowed to modify main ().
// You can use string library functions.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable : 4996) // for Visual Studio Only
#define MAX_SONGS 20
#define MAX_SONG_NAME_LENGTH 40
#define MAX_SINGER_NAME_LENGTH 40
typedef enum
{
unclassified = 0,
Pop,
Rock,
Reggae,
Country,
Blues,
Balad,
} genreType; // enum type
struct musicRepository
{
// struct for song details
unsigned int ID;
char songName[MAX_SONG_NAME_LENGTH];
char singerName[MAX_SINGER_NAME_LENGTH];
genreType genre;
unsigned int year;
};
struct musicRepository list[MAX_SONGS]; // declare the list of songs
int numSongs = 0; // the number of songs currently stored in the list (initialized to 0)
// This function takes in an array of musicRepository structures and the size of the array as
parameters. It then loops through each index of the array and sets the values of id, year, genre,
name, and singer to their respective initial values.
// NOTE that strcpy is used to copy an empty string to name and singer, rather than setting them
equal to "". This is because arrays in C are not assignable, so the strcpy function must be used to
copy the empty string into the array.
void initializeRepository(struct musicRepository repo[], int size)
{
for (int i = 0; i < size; i++)
{
repo[i].ID = 0;
repo[i].year = 0;
repo[i].genre = 0;
strcpy(repo[i].songName, "");
strcpy(repo[i].singerName, "");
}
}
// This function takes in the musicRepository array and iterates through each element. If the ID of
the song is not 0, it prints the details of the song.
void printRepository(struct musicRepository repo[], int numSongs)
{
printf("n--- Song Repository ---n");
for (int i = 0; i < numSongs; i++)
{
if (repo[i].ID != 0)
{
printf("ID: %dn", repo[i].ID);
printf("Name: %sn", repo[i].songName);
printf("Singer: %sn", repo[i].singerName);
if (repo[i].genre == 0)
printf("Genre: unclassifiedn");
else if (repo[i].genre == 1)
printf("Genre: Popn");
else if (repo[i].genre == 2)
printf("Genre: Rockn");
else if (repo[i].genre == 3)
printf("Genre: Reggaen");
else if (repo[i].genre == 4)
printf("Genre: Countryn");
else if (repo[i].genre == 5)
printf("Genre: Bluesn");
else if (repo[i].genre == 6)
printf("Genre: Baladn");
printf("Year: %dn", repo[i].year);
printf("n");
}
}
}
// 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
}
void flushSngIn()
{
char c;
do
c = getchar();
while (c != 'n' && c != EOF);
}
// 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 Can someone please help me complete the add_song function .pdf

8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf
8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf
8.8 Program Playlist (Java)You will be building a linked list. Ma.pdfARCHANASTOREKOTA
 
Problem 2 struct to hold information about a song struct So.pdf
 Problem 2 struct to hold information about a song struct So.pdf Problem 2 struct to hold information about a song struct So.pdf
Problem 2 struct to hold information about a song struct So.pdfahujaelectronics175
 
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdfHi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdfapleathers
 
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdfarenamobiles123
 
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
 
maincpp include ltiostreamgt include ltstringgt.pdf
maincpp  include ltiostreamgt include ltstringgt.pdfmaincpp  include ltiostreamgt include ltstringgt.pdf
maincpp include ltiostreamgt include ltstringgt.pdfmukulsingh0025
 
Problem 2 create some sample songs struct Song.pdf
  Problem 2      create some sample songs     struct Song.pdf  Problem 2      create some sample songs     struct Song.pdf
Problem 2 create some sample songs struct Song.pdfkeshavagg1122
 
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
 
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
 
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
 
The Test File- The code- #include -iostream- #include -vector- #includ.docx
The Test File- The code- #include -iostream- #include -vector- #includ.docxThe Test File- The code- #include -iostream- #include -vector- #includ.docx
The Test File- The code- #include -iostream- #include -vector- #includ.docxAustinIKkNorthy
 
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
 
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
 
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
 
I am having the below compile errors. .pdf
I am having the below compile errors. .pdfI am having the below compile errors. .pdf
I am having the below compile errors. .pdfdbrienmhompsonkath75
 
Last fm api_overview
Last fm api_overviewLast fm api_overview
Last fm api_overviewyuliang
 
OverviewThis project will allow you to write a program to get mo.docx
OverviewThis project will allow you to write a program to get mo.docxOverviewThis project will allow you to write a program to get mo.docx
OverviewThis project will allow you to write a program to get mo.docxjacksnathalie
 

Similar to Can someone please help me complete the add_song function .pdf (20)

8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf
8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf
8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf
 
Problem 2 struct to hold information about a song struct So.pdf
 Problem 2 struct to hold information about a song struct So.pdf Problem 2 struct to hold information about a song struct So.pdf
Problem 2 struct to hold information about a song struct So.pdf
 
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdfHi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
 
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
8.15 Program Playlist (C++) You will be building a linked list. Mak.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
 
maincpp include ltiostreamgt include ltstringgt.pdf
maincpp  include ltiostreamgt include ltstringgt.pdfmaincpp  include ltiostreamgt include ltstringgt.pdf
maincpp include ltiostreamgt include ltstringgt.pdf
 
Problem 2 create some sample songs struct Song.pdf
  Problem 2      create some sample songs     struct Song.pdf  Problem 2      create some sample songs     struct Song.pdf
Problem 2 create some sample songs struct Song.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
 
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
 
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
 
The Test File- The code- #include -iostream- #include -vector- #includ.docx
The Test File- The code- #include -iostream- #include -vector- #includ.docxThe Test File- The code- #include -iostream- #include -vector- #includ.docx
The Test File- The code- #include -iostream- #include -vector- #includ.docx
 
Intro a Ember.js
Intro a Ember.jsIntro a Ember.js
Intro a Ember.js
 
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
 
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
 
ES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript SkillsES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript Skills
 
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
 
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
 
I am having the below compile errors. .pdf
I am having the below compile errors. .pdfI am having the below compile errors. .pdf
I am having the below compile errors. .pdf
 
Last fm api_overview
Last fm api_overviewLast fm api_overview
Last fm api_overview
 
OverviewThis project will allow you to write a program to get mo.docx
OverviewThis project will allow you to write a program to get mo.docxOverviewThis project will allow you to write a program to get mo.docx
OverviewThis project will allow you to write a program to get mo.docx
 

More from akshpatil4

Calculate the amount of money Paige had to deposit in an inv.pdf
Calculate the amount of money Paige had to deposit in an inv.pdfCalculate the amount of money Paige had to deposit in an inv.pdf
Calculate the amount of money Paige had to deposit in an inv.pdfakshpatil4
 
Cada ao en los Estados Unidos cientos de iglesias cristian.pdf
Cada ao en los Estados Unidos cientos de iglesias cristian.pdfCada ao en los Estados Unidos cientos de iglesias cristian.pdf
Cada ao en los Estados Unidos cientos de iglesias cristian.pdfakshpatil4
 
Can you please add comments so I can understand it Thank yo.pdf
Can you please add comments so I can understand it Thank yo.pdfCan you please add comments so I can understand it Thank yo.pdf
Can you please add comments so I can understand it Thank yo.pdfakshpatil4
 
can you help me write this code in Net Maui App please than.pdf
can you help me write this code in Net Maui App please than.pdfcan you help me write this code in Net Maui App please than.pdf
can you help me write this code in Net Maui App please than.pdfakshpatil4
 
Can you help me with these two questions I will give you a .pdf
Can you help me with these two questions I will give you a .pdfCan you help me with these two questions I will give you a .pdf
Can you help me with these two questions I will give you a .pdfakshpatil4
 
Can you help me design this interface in HTML Flight Find.pdf
Can you help me design this interface in HTML   Flight Find.pdfCan you help me design this interface in HTML   Flight Find.pdf
Can you help me design this interface in HTML Flight Find.pdfakshpatil4
 
Can You build the web based project Homepage for me Home .pdf
Can You build the web based project Homepage for me   Home .pdfCan You build the web based project Homepage for me   Home .pdf
Can You build the web based project Homepage for me Home .pdfakshpatil4
 
Can You build the web based project for me Home Page Aft.pdf
Can You build the web based project for me   Home Page Aft.pdfCan You build the web based project for me   Home Page Aft.pdf
Can You build the web based project for me Home Page Aft.pdfakshpatil4
 
can you break this down in python codes please Task 1 Cre.pdf
can you break this down in python codes please  Task 1 Cre.pdfcan you break this down in python codes please  Task 1 Cre.pdf
can you break this down in python codes please Task 1 Cre.pdfakshpatil4
 
Can someone explain this to me step by step Consider a give.pdf
Can someone explain this to me step by step Consider a give.pdfCan someone explain this to me step by step Consider a give.pdf
Can someone explain this to me step by step Consider a give.pdfakshpatil4
 
Can you answer these True or False questions for me please .pdf
Can you answer these True or False questions for me please .pdfCan you answer these True or False questions for me please .pdf
Can you answer these True or False questions for me please .pdfakshpatil4
 
Can someone please help with this Now that you have compl.pdf
Can someone please help with this  Now that you have compl.pdfCan someone please help with this  Now that you have compl.pdf
Can someone please help with this Now that you have compl.pdfakshpatil4
 
Can someone solve the TODO parts of the following problem i.pdf
Can someone solve the TODO parts of the following problem i.pdfCan someone solve the TODO parts of the following problem i.pdf
Can someone solve the TODO parts of the following problem i.pdfakshpatil4
 
Calculate the amount of money Dylan had to deposit in an inv.pdf
Calculate the amount of money Dylan had to deposit in an inv.pdfCalculate the amount of money Dylan had to deposit in an inv.pdf
Calculate the amount of money Dylan had to deposit in an inv.pdfakshpatil4
 
can someone please assist me with analysis of this case atud.pdf
can someone please assist me with analysis of this case atud.pdfcan someone please assist me with analysis of this case atud.pdf
can someone please assist me with analysis of this case atud.pdfakshpatil4
 
can someone help me with this class ENVS 200040 Pollution.pdf
can someone help me with this class ENVS 200040   Pollution.pdfcan someone help me with this class ENVS 200040   Pollution.pdf
can someone help me with this class ENVS 200040 Pollution.pdfakshpatil4
 
Can someone help me with these questions 1 Main structures.pdf
Can someone help me with these questions 1 Main structures.pdfCan someone help me with these questions 1 Main structures.pdf
Can someone help me with these questions 1 Main structures.pdfakshpatil4
 
Can someone help with these functions doAddTweet doEditTwe.pdf
Can someone help with these functions  doAddTweet doEditTwe.pdfCan someone help with these functions  doAddTweet doEditTwe.pdf
Can someone help with these functions doAddTweet doEditTwe.pdfakshpatil4
 
Can someone derive the Rossby wave dispersion relation with .pdf
Can someone derive the Rossby wave dispersion relation with .pdfCan someone derive the Rossby wave dispersion relation with .pdf
Can someone derive the Rossby wave dispersion relation with .pdfakshpatil4
 
Calculate EPS of Solid Ltd and Sound Ltd assuming a 2x1 .pdf
Calculate EPS of Solid Ltd and Sound Ltd assuming a 2x1 .pdfCalculate EPS of Solid Ltd and Sound Ltd assuming a 2x1 .pdf
Calculate EPS of Solid Ltd and Sound Ltd assuming a 2x1 .pdfakshpatil4
 

More from akshpatil4 (20)

Calculate the amount of money Paige had to deposit in an inv.pdf
Calculate the amount of money Paige had to deposit in an inv.pdfCalculate the amount of money Paige had to deposit in an inv.pdf
Calculate the amount of money Paige had to deposit in an inv.pdf
 
Cada ao en los Estados Unidos cientos de iglesias cristian.pdf
Cada ao en los Estados Unidos cientos de iglesias cristian.pdfCada ao en los Estados Unidos cientos de iglesias cristian.pdf
Cada ao en los Estados Unidos cientos de iglesias cristian.pdf
 
Can you please add comments so I can understand it Thank yo.pdf
Can you please add comments so I can understand it Thank yo.pdfCan you please add comments so I can understand it Thank yo.pdf
Can you please add comments so I can understand it Thank yo.pdf
 
can you help me write this code in Net Maui App please than.pdf
can you help me write this code in Net Maui App please than.pdfcan you help me write this code in Net Maui App please than.pdf
can you help me write this code in Net Maui App please than.pdf
 
Can you help me with these two questions I will give you a .pdf
Can you help me with these two questions I will give you a .pdfCan you help me with these two questions I will give you a .pdf
Can you help me with these two questions I will give you a .pdf
 
Can you help me design this interface in HTML Flight Find.pdf
Can you help me design this interface in HTML   Flight Find.pdfCan you help me design this interface in HTML   Flight Find.pdf
Can you help me design this interface in HTML Flight Find.pdf
 
Can You build the web based project Homepage for me Home .pdf
Can You build the web based project Homepage for me   Home .pdfCan You build the web based project Homepage for me   Home .pdf
Can You build the web based project Homepage for me Home .pdf
 
Can You build the web based project for me Home Page Aft.pdf
Can You build the web based project for me   Home Page Aft.pdfCan You build the web based project for me   Home Page Aft.pdf
Can You build the web based project for me Home Page Aft.pdf
 
can you break this down in python codes please Task 1 Cre.pdf
can you break this down in python codes please  Task 1 Cre.pdfcan you break this down in python codes please  Task 1 Cre.pdf
can you break this down in python codes please Task 1 Cre.pdf
 
Can someone explain this to me step by step Consider a give.pdf
Can someone explain this to me step by step Consider a give.pdfCan someone explain this to me step by step Consider a give.pdf
Can someone explain this to me step by step Consider a give.pdf
 
Can you answer these True or False questions for me please .pdf
Can you answer these True or False questions for me please .pdfCan you answer these True or False questions for me please .pdf
Can you answer these True or False questions for me please .pdf
 
Can someone please help with this Now that you have compl.pdf
Can someone please help with this  Now that you have compl.pdfCan someone please help with this  Now that you have compl.pdf
Can someone please help with this Now that you have compl.pdf
 
Can someone solve the TODO parts of the following problem i.pdf
Can someone solve the TODO parts of the following problem i.pdfCan someone solve the TODO parts of the following problem i.pdf
Can someone solve the TODO parts of the following problem i.pdf
 
Calculate the amount of money Dylan had to deposit in an inv.pdf
Calculate the amount of money Dylan had to deposit in an inv.pdfCalculate the amount of money Dylan had to deposit in an inv.pdf
Calculate the amount of money Dylan had to deposit in an inv.pdf
 
can someone please assist me with analysis of this case atud.pdf
can someone please assist me with analysis of this case atud.pdfcan someone please assist me with analysis of this case atud.pdf
can someone please assist me with analysis of this case atud.pdf
 
can someone help me with this class ENVS 200040 Pollution.pdf
can someone help me with this class ENVS 200040   Pollution.pdfcan someone help me with this class ENVS 200040   Pollution.pdf
can someone help me with this class ENVS 200040 Pollution.pdf
 
Can someone help me with these questions 1 Main structures.pdf
Can someone help me with these questions 1 Main structures.pdfCan someone help me with these questions 1 Main structures.pdf
Can someone help me with these questions 1 Main structures.pdf
 
Can someone help with these functions doAddTweet doEditTwe.pdf
Can someone help with these functions  doAddTweet doEditTwe.pdfCan someone help with these functions  doAddTweet doEditTwe.pdf
Can someone help with these functions doAddTweet doEditTwe.pdf
 
Can someone derive the Rossby wave dispersion relation with .pdf
Can someone derive the Rossby wave dispersion relation with .pdfCan someone derive the Rossby wave dispersion relation with .pdf
Can someone derive the Rossby wave dispersion relation with .pdf
 
Calculate EPS of Solid Ltd and Sound Ltd assuming a 2x1 .pdf
Calculate EPS of Solid Ltd and Sound Ltd assuming a 2x1 .pdfCalculate EPS of Solid Ltd and Sound Ltd assuming a 2x1 .pdf
Calculate EPS of Solid Ltd and Sound Ltd assuming a 2x1 .pdf
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
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
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
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...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
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
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

Can someone please help me complete the add_song function .pdf

  • 1. Can someone please help me complete the "add_song" function below. Thank you! // Each song has this information: song's id, song's name, singer's name, genre of the song, and its published year. // The struct 'musicRepository' holds information of one song. Genre is enum type. // An array of structs called 'list' is made to hold the list of songs. // You should not modify any of the given code, the return types, or the parameters, you will risk of getting compilation error. // You are not allowed to modify main (). // You can use string library functions. #include <stdio.h> #include <stdlib.h> #include <string.h> #pragma warning(disable : 4996) // for Visual Studio Only #define MAX_SONGS 20 #define MAX_SONG_NAME_LENGTH 40 #define MAX_SINGER_NAME_LENGTH 40 typedef enum { unclassified = 0, Pop, Rock, Reggae, Country, Blues, Balad, } genreType; // enum type struct musicRepository { // struct for song details unsigned int ID; char songName[MAX_SONG_NAME_LENGTH]; char singerName[MAX_SINGER_NAME_LENGTH]; genreType genre; unsigned int year; }; struct musicRepository list[MAX_SONGS]; // declare the list of songs int numSongs = 0; // the number of songs currently stored in the list (initialized to 0) // This function takes in an array of musicRepository structures and the size of the array as parameters. It then loops through each index of the array and sets the values of id, year, genre, name, and singer to their respective initial values. // NOTE that strcpy is used to copy an empty string to name and singer, rather than setting them equal to "". This is because arrays in C are not assignable, so the strcpy function must be used to
  • 2. copy the empty string into the array. void initializeRepository(struct musicRepository repo[], int size) { for (int i = 0; i < size; i++) { repo[i].ID = 0; repo[i].year = 0; repo[i].genre = 0; strcpy(repo[i].songName, ""); strcpy(repo[i].singerName, ""); } } // This function takes in the musicRepository array and iterates through each element. If the ID of the song is not 0, it prints the details of the song. void printRepository(struct musicRepository repo[], int numSongs) { printf("n--- Song Repository ---n"); for (int i = 0; i < numSongs; i++) { if (repo[i].ID != 0) { printf("ID: %dn", repo[i].ID); printf("Name: %sn", repo[i].songName); printf("Singer: %sn", repo[i].singerName); if (repo[i].genre == 0) printf("Genre: unclassifiedn"); else if (repo[i].genre == 1) printf("Genre: Popn"); else if (repo[i].genre == 2) printf("Genre: Rockn"); else if (repo[i].genre == 3) printf("Genre: Reggaen"); else if (repo[i].genre == 4) printf("Genre: Countryn"); else if (repo[i].genre == 5) printf("Genre: Bluesn"); else if (repo[i].genre == 6) printf("Genre: Baladn"); printf("Year: %dn", repo[i].year); printf("n"); } }
  • 3. } // 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;
  • 4. 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 } void flushSngIn() { char c; do c = getchar(); while (c != 'n' && c != EOF); } // 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);
  • 5. 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);
  • 6. if (editResult == -1) { printf("Song not found in playlist.n"); } else { printf("Playlist after edit:n"); printPlaylist(playList); } return 0; }