C language implements song information management system
- 2020-06-03 07:24:44
- OfStack
This paper shares the specific code of C language song information management system for your reference, the specific content is as follows
System function: the system works by menu, song information includes: song name, singer, lyricist, composition, album, publication date, publishing company. Try to design 1 hall song management system, so that it can provide the following functions: song information input, modify, insert, delete functions; Song sorting browse function; Query by song name, query by singer and other functions.
The complete implementation code is as follows:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
// Song information includes: song title, singer, lyrics, composition, album, publication date, publishing company
typedef struct music
{
char name[20]; // Da da da
char singer[20]; // The singer
char authors[20]; // The lyrics
char compose[30]; // Composition,
char album[20]; // Their album
char time[15]; // Publication date
char company[30]; // Publishing company
struct music *next;
}music;
music *head=NULL;
int length; // The length of the list
void create()
{
music *p1,*p2;
length=0;
p1=(music *)malloc(sizeof(music));
strcpy(p1->name,"-1");
if(head==NULL)
head=p1;
printf(" Please enter the name of the song, the artist, the lyrics, the composition, the album, the publication date, the publishing company: /n");
while(1) // As the title 0 Time to quit
{
p2=(music *)malloc(sizeof(music));
// Enter song information
scanf("%s %s %s %s %s %s %s",p2->name,p2->singer,p2->authors,p2->compose,p2->album,p2->time,p2->company);
if(strcmp(p2->name,"0")==0)
{
printf(" Linked list creation complete! /n");
break;
}
length++; // The length of the list
p1->next=p2;
p2->next=NULL;
p1=p1->next;
}
return ;
}
void ModifymusicInfo()
{
music *p=head->next;
char name[20];
printf(" Please enter the song name of the song you want to modify: ");
getchar();
scanf("%s",name);
while(p!=NULL)
{
if(strcmp(p->name,name)==0)
{
printf(" Before modification, the song title is %s The song's message is as follows: /n",name);
printf(" The title of the song, the singer, the lyrics, the composition, the album, the publication date, the publishing company: /n");
printf("%s %s %s %s %s %s %s/n",p->name,p->singer,p->authors,p->compose,p->album,p->time,p->company);
printf(" Please enter the new album of the song: ");
getchar();
scanf("%s",p->album);
printf(" Please enter the song of the new publishing company: ");
getchar();
scanf("%s",p->company);
printf(" After modification, the song title is %s The song's message is as follows: /n",name);
printf(" The title of the song, the singer, the lyrics, the composition, the album, the publication date, the publishing company: /n");
printf("%s %s %s %s %s %s %s/n",p->name,p->singer,p->authors,p->compose,p->album,p->time,p->company);
return ;
}
p=p->next;
}
if(p==NULL)
{
printf(" The song does not exist! /n");
return ;
}
}
void display()
{
music *p=head->next;
printf(" All the songs in the list are listed below :/n");
printf(" The title of the song, the singer, the lyrics, the composition, the album, the publication date, the publishing company: /n");
while(p!=NULL)
{
printf("%s %s %s %s %s %s %s/n",p->name,p->singer,p->authors,p->compose,p->album,p->time,p->company);
p=p->next;
}
return ;
}
void search()
{
int num,x,flag;
char name[20];
music *p=head->next;
printf(" Please select the method of inquiry: /n");
printf("1 , by song name /t 2 , search by singer /n");
scanf("%d",&x);
if(x==1)
{
printf(" The song you need to find is called: ");
getchar();
scanf("%s",name);
while(p!=NULL)
{
if(strcmp(p->name,name)==0)
{
printf(" As the title %s The song's message is as follows: /n",name);
printf(" The title of the song, the singer, the lyrics, the composition, the album, the publication date, the publishing company: /n");
printf("%s %s %s %s %s %s %s/n",p->name,p->singer,p->authors,p->compose,p->album,p->time,p->company);
return ;
}
p=p->next;
}
if(p==NULL)
printf(" There is no record of this song! /n");
}
else if(x==2)
{
flag=0;
printf(" The singer to be searched is: ");
getchar();
scanf("%s",name);
p=head->next;
while(p!=NULL)
{
if(strcmp(p->singer,name)==0)
{
if(flag==0)
{
printf(" The singer is %s The song's message is as follows: /n",name);
printf(" The title of the song, the singer, the lyrics, the composition, the album, the publication date, the publishing company: /n");
flag=1;
}
printf("%s %s %s %s %s %s %s/n",p->name,p->singer,p->authors,p->compose,p->album,p->time,p->company);
}
p=p->next;
}
if(p==NULL && flag==0)
{
printf(" There is no record of the singer! /n");
return;
}
}
return ;
}
void insert()
{
int num,i;
music *p,*q;
p=head;
printf(" Please enter the position you want to insert : ");
scanf("%d",&num);
if(num>length)
{
printf(" The position to insert cannot be found /n");
return ;
}
else
{
printf(" Please enter the name of the song, the artist, the lyrics, the composer, the album, the time of publication, the publishing company of the music you want to insert: /n");
q=(music *)malloc(sizeof(music));
// Enter song information
scanf("%s %s %s %s %s %s %s",q->name,q->singer,q->authors,q->compose,q->album,q->time,q->company);
while(p!=NULL)
{
if(strcmp(p->name,q->name)==0)
{
printf(" This song already exists, cannot insert! /n");
return ;
}
p=p->next;
}
p=head;
for(i=0;i<num;i++)
p=p->next;
q->next=p->next;
p->next=q;
length++;
printf(" Insert successfully! /n");
return ;
}
}
void Delete()
{
char name[20];
music *p,*q;
q=head,p=head->next;
printf(" Please enter the name of the song you want to delete :/n");
getchar();
scanf("%s",name);
while(p!=NULL)
{
if(strcmp(p->name,name)==0)
{
q->next=p->next;
free(p);
length--;
printf(" Delete successful! /n");
return ;
}
p=p->next;
q=q->next;
}
if(p==NULL)
{
printf(" Can't find the song to delete! /n");
return ;
}
}
void menu()
{
printf("________________________________________________________________/n");
printf("| Songhall song management system |/n");
printf("| 0 , Log out |/n");
printf("| 1 , Input song information |/n");
printf("| 2 , Display song information |/n");
printf("| 3 , Find something in a linked list 1 song |/n");
printf("| 4 , Deletes the specified song in the linked list |/n");
printf("| 5 , Inserts at the specified location 1 A new node |/n");
printf("| 6 , Modify song information |/n");
printf("________________________________________________________________/n");
return ;
}
int main(void)
{
int a;
menu();
while(1)
{
printf(" Please select the corresponding function: ");
scanf("%d",&a);
switch(a)
{
case 0:
return 0;
case 1:
create();
menu();
break;
case 2:
if(head)
{
display();
menu();
}
else
{
printf(" The list is empty, please create the list first! /n");
menu();
}
break;
case 3:
if(head)
{
search();
menu();
}
else
{
printf(" The list is empty, please create the list first! /n");
menu();
}
break;
case 4:
if(head)
{
Delete();
menu();
}
else
{
printf(" The list is empty, please create the list first! /n");
menu();
}
break;
case 5:
if(head)
{
insert();
menu();
}
else
{
printf(" The list is empty, please create the list first! /n");
menu();
}
break;
case 6:
if(head)
{
ModifymusicInfo();
menu();
}
else
{
printf(" The list is empty, please create the list first! /n");
menu();
}
break;
default:
break;
}
}
system("pause");
return 0;
}