SlideShare a Scribd company logo
1 of 6
Download to read offline
// 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);
********************************************
Please help me to finish this code (//TO DO) + Problem.

More Related Content

Similar to Problem 2 struct to hold information about a song struct So.pdf

Cover Page & Table of Contents
Cover Page & Table of ContentsCover Page & Table of Contents
Cover Page & Table of ContentsMichael Peterson
 
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
 
maincpp include ltiostreamgt include ltstringgt.pdf
maincpp  include ltiostreamgt include ltstringgt.pdfmaincpp  include ltiostreamgt include ltstringgt.pdf
maincpp include ltiostreamgt include ltstringgt.pdfmukulsingh0025
 
a database to represent information about CDs made by popular music gr.pdf
a database to represent information about CDs made by popular music gr.pdfa database to represent information about CDs made by popular music gr.pdf
a database to represent information about CDs made by popular music gr.pdfpawanmca65
 
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
 
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
 
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
 

Similar to Problem 2 struct to hold information about a song struct So.pdf (8)

Cover Page & Table of Contents
Cover Page & Table of ContentsCover Page & Table of Contents
Cover Page & Table of Contents
 
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
 
maincpp include ltiostreamgt include ltstringgt.pdf
maincpp  include ltiostreamgt include ltstringgt.pdfmaincpp  include ltiostreamgt include ltstringgt.pdf
maincpp include ltiostreamgt include ltstringgt.pdf
 
a database to represent information about CDs made by popular music gr.pdf
a database to represent information about CDs made by popular music gr.pdfa database to represent information about CDs made by popular music gr.pdf
a database to represent information about CDs made by popular music gr.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
 
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
 
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
 

More from ahujaelectronics175

Q2 We throw three dice and multiply three numbers that show up. Each.pdf
 Q2 We throw three dice and multiply three numbers that show up. Each.pdf Q2 We throw three dice and multiply three numbers that show up. Each.pdf
Q2 We throw three dice and multiply three numbers that show up. Each.pdfahujaelectronics175
 
Q1. What are some of the immediate downfalls that came from the 2021 .pdf
 Q1. What are some of the immediate downfalls that came from the 2021 .pdf Q1. What are some of the immediate downfalls that came from the 2021 .pdf
Q1. What are some of the immediate downfalls that came from the 2021 .pdfahujaelectronics175
 
Q. 5 Probabilistic Growth Let Ni denote the number of rabbits in gene.pdf
 Q. 5 Probabilistic Growth Let Ni denote the number of rabbits in gene.pdf Q. 5 Probabilistic Growth Let Ni denote the number of rabbits in gene.pdf
Q. 5 Probabilistic Growth Let Ni denote the number of rabbits in gene.pdfahujaelectronics175
 
Q.2 Write a program using loops (either while or for loop) tha.pdf
 Q.2 Write a program using loops (either while or for loop) tha.pdf Q.2 Write a program using loops (either while or for loop) tha.pdf
Q.2 Write a program using loops (either while or for loop) tha.pdfahujaelectronics175
 
Project Desoription The purpose of this project is to dovelop a code.pdf
 Project Desoription The purpose of this project is to dovelop a code.pdf Project Desoription The purpose of this project is to dovelop a code.pdf
Project Desoription The purpose of this project is to dovelop a code.pdfahujaelectronics175
 
Prompt In a 7 to 10 slide PowerPoint presentation, describe the stag.pdf
 Prompt In a 7 to 10 slide PowerPoint presentation, describe the stag.pdf Prompt In a 7 to 10 slide PowerPoint presentation, describe the stag.pdf
Prompt In a 7 to 10 slide PowerPoint presentation, describe the stag.pdfahujaelectronics175
 
Projected Profit is calculated as Profit Profit Increase ( H2 Cel.pdf
 Projected Profit is calculated as Profit Profit Increase ( H2 Cel.pdf Projected Profit is calculated as Profit Profit Increase ( H2 Cel.pdf
Projected Profit is calculated as Profit Profit Increase ( H2 Cel.pdfahujaelectronics175
 
Programming Assignment 5 Chapter 5 Write, compile, and test .pdf
 Programming Assignment 5 Chapter 5 Write, compile, and test .pdf Programming Assignment 5 Chapter 5 Write, compile, and test .pdf
Programming Assignment 5 Chapter 5 Write, compile, and test .pdfahujaelectronics175
 
Protein X can bind 3 different but similar substrates. Protein Y will.pdf
 Protein X can bind 3 different but similar substrates. Protein Y will.pdf Protein X can bind 3 different but similar substrates. Protein Y will.pdf
Protein X can bind 3 different but similar substrates. Protein Y will.pdfahujaelectronics175
 
Problem 924(120,3,5) In June 2022, Enivique and Denisse Espinosa tiav.pdf
 Problem 924(120,3,5) In June 2022, Enivique and Denisse Espinosa tiav.pdf Problem 924(120,3,5) In June 2022, Enivique and Denisse Espinosa tiav.pdf
Problem 924(120,3,5) In June 2022, Enivique and Denisse Espinosa tiav.pdfahujaelectronics175
 
Problem 4. In a bank, the probability of getting a bad check is is 4.pdf
 Problem 4. In a bank, the probability of getting a bad check is is 4.pdf Problem 4. In a bank, the probability of getting a bad check is is 4.pdf
Problem 4. In a bank, the probability of getting a bad check is is 4.pdfahujaelectronics175
 
Problem 4. Let fAR, and let x0 be an accumulation point of A. Prove .pdf
 Problem 4. Let fAR, and let x0 be an accumulation point of A. Prove .pdf Problem 4. Let fAR, and let x0 be an accumulation point of A. Prove .pdf
Problem 4. Let fAR, and let x0 be an accumulation point of A. Prove .pdfahujaelectronics175
 
Problem 3. A random variable is uniformly distributed on the interval.pdf
 Problem 3. A random variable is uniformly distributed on the interval.pdf Problem 3. A random variable is uniformly distributed on the interval.pdf
Problem 3. A random variable is uniformly distributed on the interval.pdfahujaelectronics175
 
Problem 3 In Evland, potential GDP is E3,000. The table shows Evland.pdf
 Problem 3 In Evland, potential GDP is E3,000. The table shows Evland.pdf Problem 3 In Evland, potential GDP is E3,000. The table shows Evland.pdf
Problem 3 In Evland, potential GDP is E3,000. The table shows Evland.pdfahujaelectronics175
 
Problem 16.96. A coin with with probability p of heads is tossed unti.pdf
 Problem 16.96. A coin with with probability p of heads is tossed unti.pdf Problem 16.96. A coin with with probability p of heads is tossed unti.pdf
Problem 16.96. A coin with with probability p of heads is tossed unti.pdfahujaelectronics175
 
Problem 11. Let X and Y be normal random variables with means 0 and 1.pdf
 Problem 11. Let X and Y be normal random variables with means 0 and 1.pdf Problem 11. Let X and Y be normal random variables with means 0 and 1.pdf
Problem 11. Let X and Y be normal random variables with means 0 and 1.pdfahujaelectronics175
 
Privatization is a form of Government Regulation that serves to stren.pdf
 Privatization is a form of Government Regulation that serves to stren.pdf Privatization is a form of Government Regulation that serves to stren.pdf
Privatization is a form of Government Regulation that serves to stren.pdfahujaelectronics175
 
Population Size Population size is the number of individuals that mak.pdf
 Population Size Population size is the number of individuals that mak.pdf Population Size Population size is the number of individuals that mak.pdf
Population Size Population size is the number of individuals that mak.pdfahujaelectronics175
 
Problem # 5 Let Y1,Y2,�,Yn denote independent and identically distri.pdf
 Problem # 5 Let Y1,Y2,�,Yn denote independent and identically distri.pdf Problem # 5 Let Y1,Y2,�,Yn denote independent and identically distri.pdf
Problem # 5 Let Y1,Y2,�,Yn denote independent and identically distri.pdfahujaelectronics175
 
Pre-laboratory Questions Given the antigen(s) found on the red blood .pdf
 Pre-laboratory Questions Given the antigen(s) found on the red blood .pdf Pre-laboratory Questions Given the antigen(s) found on the red blood .pdf
Pre-laboratory Questions Given the antigen(s) found on the red blood .pdfahujaelectronics175
 

More from ahujaelectronics175 (20)

Q2 We throw three dice and multiply three numbers that show up. Each.pdf
 Q2 We throw three dice and multiply three numbers that show up. Each.pdf Q2 We throw three dice and multiply three numbers that show up. Each.pdf
Q2 We throw three dice and multiply three numbers that show up. Each.pdf
 
Q1. What are some of the immediate downfalls that came from the 2021 .pdf
 Q1. What are some of the immediate downfalls that came from the 2021 .pdf Q1. What are some of the immediate downfalls that came from the 2021 .pdf
Q1. What are some of the immediate downfalls that came from the 2021 .pdf
 
Q. 5 Probabilistic Growth Let Ni denote the number of rabbits in gene.pdf
 Q. 5 Probabilistic Growth Let Ni denote the number of rabbits in gene.pdf Q. 5 Probabilistic Growth Let Ni denote the number of rabbits in gene.pdf
Q. 5 Probabilistic Growth Let Ni denote the number of rabbits in gene.pdf
 
Q.2 Write a program using loops (either while or for loop) tha.pdf
 Q.2 Write a program using loops (either while or for loop) tha.pdf Q.2 Write a program using loops (either while or for loop) tha.pdf
Q.2 Write a program using loops (either while or for loop) tha.pdf
 
Project Desoription The purpose of this project is to dovelop a code.pdf
 Project Desoription The purpose of this project is to dovelop a code.pdf Project Desoription The purpose of this project is to dovelop a code.pdf
Project Desoription The purpose of this project is to dovelop a code.pdf
 
Prompt In a 7 to 10 slide PowerPoint presentation, describe the stag.pdf
 Prompt In a 7 to 10 slide PowerPoint presentation, describe the stag.pdf Prompt In a 7 to 10 slide PowerPoint presentation, describe the stag.pdf
Prompt In a 7 to 10 slide PowerPoint presentation, describe the stag.pdf
 
Projected Profit is calculated as Profit Profit Increase ( H2 Cel.pdf
 Projected Profit is calculated as Profit Profit Increase ( H2 Cel.pdf Projected Profit is calculated as Profit Profit Increase ( H2 Cel.pdf
Projected Profit is calculated as Profit Profit Increase ( H2 Cel.pdf
 
Programming Assignment 5 Chapter 5 Write, compile, and test .pdf
 Programming Assignment 5 Chapter 5 Write, compile, and test .pdf Programming Assignment 5 Chapter 5 Write, compile, and test .pdf
Programming Assignment 5 Chapter 5 Write, compile, and test .pdf
 
Protein X can bind 3 different but similar substrates. Protein Y will.pdf
 Protein X can bind 3 different but similar substrates. Protein Y will.pdf Protein X can bind 3 different but similar substrates. Protein Y will.pdf
Protein X can bind 3 different but similar substrates. Protein Y will.pdf
 
Problem 924(120,3,5) In June 2022, Enivique and Denisse Espinosa tiav.pdf
 Problem 924(120,3,5) In June 2022, Enivique and Denisse Espinosa tiav.pdf Problem 924(120,3,5) In June 2022, Enivique and Denisse Espinosa tiav.pdf
Problem 924(120,3,5) In June 2022, Enivique and Denisse Espinosa tiav.pdf
 
Problem 4. In a bank, the probability of getting a bad check is is 4.pdf
 Problem 4. In a bank, the probability of getting a bad check is is 4.pdf Problem 4. In a bank, the probability of getting a bad check is is 4.pdf
Problem 4. In a bank, the probability of getting a bad check is is 4.pdf
 
Problem 4. Let fAR, and let x0 be an accumulation point of A. Prove .pdf
 Problem 4. Let fAR, and let x0 be an accumulation point of A. Prove .pdf Problem 4. Let fAR, and let x0 be an accumulation point of A. Prove .pdf
Problem 4. Let fAR, and let x0 be an accumulation point of A. Prove .pdf
 
Problem 3. A random variable is uniformly distributed on the interval.pdf
 Problem 3. A random variable is uniformly distributed on the interval.pdf Problem 3. A random variable is uniformly distributed on the interval.pdf
Problem 3. A random variable is uniformly distributed on the interval.pdf
 
Problem 3 In Evland, potential GDP is E3,000. The table shows Evland.pdf
 Problem 3 In Evland, potential GDP is E3,000. The table shows Evland.pdf Problem 3 In Evland, potential GDP is E3,000. The table shows Evland.pdf
Problem 3 In Evland, potential GDP is E3,000. The table shows Evland.pdf
 
Problem 16.96. A coin with with probability p of heads is tossed unti.pdf
 Problem 16.96. A coin with with probability p of heads is tossed unti.pdf Problem 16.96. A coin with with probability p of heads is tossed unti.pdf
Problem 16.96. A coin with with probability p of heads is tossed unti.pdf
 
Problem 11. Let X and Y be normal random variables with means 0 and 1.pdf
 Problem 11. Let X and Y be normal random variables with means 0 and 1.pdf Problem 11. Let X and Y be normal random variables with means 0 and 1.pdf
Problem 11. Let X and Y be normal random variables with means 0 and 1.pdf
 
Privatization is a form of Government Regulation that serves to stren.pdf
 Privatization is a form of Government Regulation that serves to stren.pdf Privatization is a form of Government Regulation that serves to stren.pdf
Privatization is a form of Government Regulation that serves to stren.pdf
 
Population Size Population size is the number of individuals that mak.pdf
 Population Size Population size is the number of individuals that mak.pdf Population Size Population size is the number of individuals that mak.pdf
Population Size Population size is the number of individuals that mak.pdf
 
Problem # 5 Let Y1,Y2,�,Yn denote independent and identically distri.pdf
 Problem # 5 Let Y1,Y2,�,Yn denote independent and identically distri.pdf Problem # 5 Let Y1,Y2,�,Yn denote independent and identically distri.pdf
Problem # 5 Let Y1,Y2,�,Yn denote independent and identically distri.pdf
 
Pre-laboratory Questions Given the antigen(s) found on the red blood .pdf
 Pre-laboratory Questions Given the antigen(s) found on the red blood .pdf Pre-laboratory Questions Given the antigen(s) found on the red blood .pdf
Pre-laboratory Questions Given the antigen(s) found on the red blood .pdf
 

Recently uploaded

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
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
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
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
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Recently uploaded (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
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
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

Problem 2 struct to hold information about a song struct So.pdf

  • 1. // 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;
  • 2. 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)
  • 3. { // 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");
  • 4. 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);
  • 5. 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';
  • 6. 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); ******************************************** Please help me to finish this code (//TO DO) + Problem.