System function: the system works in the form of menus. Song information includes: song name, artist, lyrics, composing, album, publishing time, and publishing company. Design a song Management System for the karaoke bar to provide the following functions: Song information entry, modification, insertion and deletion functions; Song sorting and browsing functions; query by Song name and query by singer.
The complete implementation code is as follows:
# Include "stdio. H "<br/> # include" stdlib. H "<br/> # include" string. H "<br/> // The Song information includes: song name, artist, lyrics, composing, album, publishing time, publishing company <br/> typedef struct music <br/>{< br/> char name [20]; // song name <br/> char singer [20]; // singer <br/> char authors [20]; // prepared by <br/> char compose [30]; // composing <br/> char album [20]; // album <br/> char time [15]; // publication date <br/> char company [30]; // Publishing Company <br/> struct music * Next; <br/>} music; <br/> music * head = NULL; <br /> Int length; // The length of the linked list <br/> void create () <br/>{< br/> music * P1, * P2; <br/> length = 0; <br/> P1 = (music *) malloc (sizeof (music); <br/> strcpy (P1-> name, "-1"); <br/> If (Head = NULL) <br/> head = p1; <br/> printf ("Enter the name, artist, lyrics, composing, album, publishing time, and publishing company of the Music:/N "); <br/> while (1) // exit when the song name is 0 <br/> {<br/> P2 = (music *) malloc (sizeof (music )); <br/> // enter the song Information <br/> scanf ("% S % s", P2-> name, p2-> singer, P2-> authors, P2-> comp Ose, P2-> album, P2-> time, P2-> Company); <br/> If (strcmp (P2-> name, "0") = 0) <br/>{< br/> printf ("linked list created! /N "); <br/> break; <br/>}< br/> length ++; // The length of the linked list <br/> P1-> next = P2; <br/> P2-> next = NULL; <br/> P1 = p1-> next; <br/>}< br/> return; <br/>}< br/> void modifymusicinfo () <br/>{< br/> music * P = head-> next; <br/> char name [20]; <br/> printf ("enter the name of the song to be modified:"); <br/> getchar (); <br/> scanf ("% s", name); <br/> while (P! = NULL) <br/>{< br/> If (strcmp (p-> name, name) = 0) <br/> {<br/> printf ("the information of the song named % s before modification is as follows:/N", name ); <br/> printf ("Music song name, artist, lyrics, composing, album, publishing time, publishing company:/N "); <br/> printf ("% S % s/n", p-> name, p-> singer, p-> authors, p-> compose, p-> album, p-> time, p-> Company); <br/> printf ("Enter the new album of the song :"); <br/> getchar (); <br/> scanf ("% s", p-> album); <br/> printf ("Enter the new publishing company of the song: "); <br/> getchar (); <br/> scanf (" % s ", p-> Company); <B R/> printf ("after modification, the information of the song named % s is as follows:/N", name ); <br/> printf ("Music song name, artist, lyrics, composing, album, publishing time, publishing company:/N "); <br/> printf ("% S % s/n", p-> name, p-> singer, p-> authors, p-> compose, p-> album, p-> time, p-> Company); <br/> return; <br/>}< br/> P = p-> next; <br/>}< br/> If (P = NULL) <br/>{< br/> printf ("This song does not exist! /N "); <br/> return; <br/>}</P> <p> void display () <br/>{< br/> music * P = head-> next; <br/> printf ("all the songs in the linked list are as follows:/N "); <br/> printf ("Music song name, artist, lyrics, composing, album, publishing time, publishing company:/N"); <br/> while (P! = NULL) <br/>{< br/> printf ("% S % s/n", p-> name, p-> singer, p-> authors, p-> compose, p-> album, p-> time, p-> company ); <br/> P = p-> next; <br/>}< br/> return; <br/>}< br/> void search () <br/>{< br/> int num, X, flag; <br/> char name [20]; <br/> music * P = head-> next; <br/> printf ("select the query method:/N "); <br/> printf ("1. query by Song name/T 2. query by singer/N"); <br/> scanf ("% d", & X ); <br/> If (x = 1) <br/>{< br/> printf ("the name of the song to be searched is:"); <br/> get Char (); <br/> scanf ("% s", name); <br/> while (P! = NULL) <br/>{</P> <p> If (strcmp (p-> name, name) = 0) <br/>{ <br/> printf ("the information of a song named % s is as follows:/N", name ); <br/> printf ("Music song name, artist, lyrics, composing, album, publishing time, publishing company:/N "); <br/> printf ("% S % s/n", p-> name, p-> singer, p-> authors, p-> compose, p-> album, p-> time, p-> Company); <br/> return; <br/>}< br/> P = p-> next; <br/>}< br/> If (P = NULL) <br/> printf ("no record for this song! /N "); <br/>}< br/> else if (x = 2) <br/>{< br/> flag = 0; <br/> printf ("the singer to be searched is:"); <br/> getchar (); <br/> scanf ("% s", name ); <br/> P = head-> next; <br/> while (P! = NULL) <br/>{< br/> If (strcmp (p-> singer, name) = 0) <br/>{< br/> If (flag = 0) <br/>{< br/> printf ("the information of the song whose singer is % s is as follows: /n ", name); <br/> printf (" Music song name, artist, lyrics, composing, album, publishing time, publishing company:/N "); <br/> flag = 1; <br/>}< br/> printf ("% S % s/n ", p-> name, p-> singer, p-> authors, p-> compose, p-> album, p-> time, p-> company ); <br/>}< br/> P = p-> next; <br/>}< br/> If (P = NULL & flag = 0) <br/> {<br/> printf ("No song record for this artist! /N "); <br/> return; <br/>}< br/> return; <br/>}</P> <p> void insert () <br/> {<br/> int num, I; <br/> music * P, * q; <br/> P = head; </P> <p> printf ("Enter the location you want to insert :"); <br/> scanf ("% d", & num); <br/> If (Num> length) <br/>{< br/> printf ("the location to be inserted cannot be found/N"); <br/> return; <br/>}< br/> else <br/> {<br/> printf ("Enter the name, artist, lyrics, composing, and album of the music you want to insert., publishing time, publishing company: /n "); <br/> q = (music *) malloc (sizeof (music )); <br/> // enter the song Information <br/> scanf ("% S % s % S % s ", Q-> name, Q-> singer, Q-> authors, Q-> compose, Q-> album, q-> time, Q-> Company); <br/> while (P! = NULL) <br/>{< br/> If (strcmp (p-> name, Q-> name) = 0) <br/>{< br/> printf ("This song already exists and cannot be inserted! /N "); <br/> return; <br/>}< br/> P = p-> next; <br/>}< br/> P = head; <br/> for (I = 0; I <num; I ++) <br/> P = p-> next; <br/> q-> next = p-> next; <br/> P-> next = Q; <br/> length ++; <br/> printf ("inserted successfully! /N "); <br/> return; <br/>}</P> <p> void Delete () <br/>{< br/> char name [20]; <br/> music * P, * q; <br/> q = head, P = head-> next; <br/> printf ("enter the name of the song to be deleted:/N"); <br/> getchar (); <br/> scanf ("% s", name); </P> <p> while (P! = NULL) <br/>{< br/> If (strcmp (p-> name, name) = 0) <br/>{< br/> q-> next = p-> next; <br/> free (p); <br/> length --; <br/> printf ("deleted successfully! /N "); <br/> return; <br/>}< br/> P = p-> next; <br/> q = Q-> next; <br/>}< br/> If (P = NULL) <br/> {<br/> printf ("the song to be deleted cannot be found! /N "); <br/> return; <br/>}< br/> void menu () <br/>{< br/> printf ("________________________________________________________________/N"); <br/> printf ("| karaoke bar song Management System |/N "); <br/> printf ("| 0, exit the system |/N"); <br/> printf ("| 1. Enter the song information |/N "); <br/> printf ("| 2. display the song information |/N "); <br/> printf ("| 3. Search for a song in the linked list |/N "); <br/> printf ("| 4. Delete the specified song in the linked list |/N "); <br/> printf ("| 5. Insert a new node at the specified position |/N"); <br/> printf ("| 6. Modify the song Information |/N "); <br/> printf (" ____________________________________________________________________/N "); <br/> return; <br/>}< br/> int main (void) <br/>{< br/> int A; <br/> menu (); <br/> while (1) <br/>{< br/> printf ("select the appropriate function:"); <br/> scanf ("% d", & ); <br/> switch (a) <br/>{< br/> case 0: <br/> return 0; <br/> case 1: <br/> Create (); <br/> menu (); <br/> break; <br/> case 2: <br/> If (head) <br/>{< br/> display (); <br/> menu (); <br />}< Br/> else <br/> {<br/> printf ("the linked list is empty. Create a linked list first! /N "); <br/> menu (); <br/>}< br/> break; <br/> case 3: <br/> If (head) <br/>{< br/> Search (); <br/> menu (); <br/>}< br/> else <br/> {<br/> printf ("the linked list is empty. Create a linked list first! /N "); <br/> menu (); <br/>}< br/> break; <br/> case 4: <br/> If (head) <br/>{< br/> Delete (); <br/> menu (); <br/>}< br/> else <br/> {<br/> printf ("the linked list is empty. Create a linked list first! /N "); <br/> menu (); <br/>}< br/> break; <br/> case 5: <br/> If (head) <br/>{< br/> insert (); <br/> menu (); <br/>}< br/> else <br/> {<br/> printf ("the linked list is empty. Create a linked list first! /N "); <br/> menu (); <br/>}< br/> break; <br/> case 6: <br/> If (head) <br/>{< br/> modifymusicinfo (); <br/> menu (); <br/>}< br/> else <br/> {<br/> printf ("the linked list is empty. Create a linked list first! /N "); <br/> menu (); <br/>}< br/> break; <br/> default: <br/> break; <br/>}< br/> system ("pause"); <br/> return 0; <br/>}