C语言课程设计---歌厅歌曲管理系统
系統功能:該系統以菜單方式工作,歌曲信息包括:歌名、演唱者、作詞、作曲、所屬專輯、出版時間、出版公司。試設計一歌廳歌曲管理系統,使之能提供以下功能:歌曲信息錄入、修改、插入、刪除功能;歌曲排序瀏覽功能;按歌名查詢、按演唱者查詢等功能。
完整的實現代碼如下:
#include "stdio.h" #include "stdlib.h" #include "string.h" //歌曲信息包括:歌名、演唱者、作詞、作曲、所屬專輯、出版時間、出版公司 typedef struct music {char name[20]; //歌名char singer[20]; //演唱者char authors[20]; //作詞char compose[30]; //作曲char album[20]; //所屬專輯char time[15]; //出版時間char company[30]; //出版公司struct music *next; }music; music *head=NULL; int length; //鏈表的長度 void create() {music *p1,*p2;length=0;p1=(music *)malloc(sizeof(music));strcpy(p1->name,"-1");if(head==NULL)head=p1;printf("請輸入音樂的歌名、演唱者、作詞、作曲、所屬專輯、出版時間、出版公司:/n");while(1) //歌名為0的時候退出{p2=(music *)malloc(sizeof(music));//輸入歌曲信息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("鏈表創建完成!/n");break;}length++; //鏈表的長度p1->next=p2;p2->next=NULL;p1=p1->next;}return ; } void ModifymusicInfo() {music *p=head->next;char name[20];printf("請輸入要修改的歌曲的歌名:");getchar();scanf("%s",name);while(p!=NULL){if(strcmp(p->name,name)==0){printf("修改前,歌名為%s的歌曲的信息如下:/n",name);printf("音樂的歌名、演唱者、作詞、作曲、所屬專輯、出版時間、出版公司:/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("請輸入歌曲的新的所屬專輯:");getchar();scanf("%s",p->album);printf("請輸入歌曲的新出版公司:");getchar();scanf("%s",p->company);printf("修改后,歌名為%s的歌曲的信息如下:/n",name);printf("音樂的歌名、演唱者、作詞、作曲、所屬專輯、出版時間、出版公司:/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("該歌曲不存在!/n");return ;} }void display() {music *p=head->next;printf("鏈表中所有的歌曲信息如下:/n");printf("音樂的歌名、演唱者、作詞、作曲、所屬專輯、出版時間、出版公司:/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("請選擇查詢的方式:/n");printf("1、按歌名查詢/t 2、按演唱者查詢/n");scanf("%d",&x);if(x==1){printf("需要查找的歌曲歌名為:");getchar();scanf("%s",name);while(p!=NULL){if(strcmp(p->name,name)==0){printf("歌名為%s的歌曲的信息如下:/n",name);printf("音樂的歌名、演唱者、作詞、作曲、所屬專輯、出版時間、出版公司:/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("沒有這首歌曲的記錄!/n");}else if(x==2){flag=0;printf("需要查找的演唱者為:");getchar();scanf("%s",name);p=head->next;while(p!=NULL){if(strcmp(p->singer,name)==0){if(flag==0){printf("演唱者為%s的歌曲的信息如下:/n",name);printf("音樂的歌名、演唱者、作詞、作曲、所屬專輯、出版時間、出版公司:/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("沒有該演唱者的歌曲記錄!/n");return;}}return ; }void insert() {int num,i;music *p,*q;p=head;printf("請輸入你要插入位置: ");scanf("%d",&num);if(num>length){printf("找不到要插入的位置/n");return ;}else{printf("請輸入你要插入的音樂的歌名、演唱者、作詞、作曲、所屬專輯、出版時間、出版公司:/n");q=(music *)malloc(sizeof(music));//輸入歌曲信息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("該歌曲已經存在,無法插入!/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("插入成功!/n");return ;} } void Delete() {char name[20];music *p,*q;q=head,p=head->next;printf("請輸入要刪除的歌曲的歌名:/n");getchar();scanf("%s",name);while(p!=NULL){if(strcmp(p->name,name)==0){q->next=p->next;free(p);length--;printf("刪除成功!/n");return ;}p=p->next;q=q->next;}if(p==NULL){printf("找不到要刪除的歌曲!/n");return ;} } void menu() {printf("________________________________________________________________/n");printf("| 歌廳歌曲管理系統 |/n");printf("| 0、 退出系統 |/n");printf("| 1、 錄入歌曲信息 |/n");printf("| 2、 顯示歌曲信息 |/n");printf("| 3、 查找鏈表中的某一首歌曲 |/n");printf("| 4、 刪除鏈表中指定歌曲 |/n");printf("| 5、 指定的位置上插入一個新結點 |/n");printf("| 6、 修改歌曲信息 |/n");printf("________________________________________________________________/n");return ; } int main(void) {int a;menu();while(1){printf("請選擇相應的功能:");scanf("%d",&a);switch(a){case 0:return 0;case 1:create();menu();break;case 2:if(head){display();menu();}else{printf("鏈表為空,請先建立鏈表!/n");menu();}break;case 3:if(head){search();menu();}else{printf("鏈表為空,請先建立鏈表!/n");menu();}break;case 4:if(head){Delete();menu();}else{printf("鏈表為空,請先建立鏈表!/n");menu();}break;case 5:if(head){insert();menu();}else{printf("鏈表為空,請先建立鏈表!/n");menu();}break;case 6:if(head){ModifymusicInfo();menu();}else{printf("鏈表為空,請先建立鏈表!/n");menu();}break;default:break;}}system("pause");return 0; }
總結
以上是生活随笔為你收集整理的C语言课程设计---歌厅歌曲管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: XP或Win7系统下grub4dos安装
- 下一篇: 关于Linux的修复(重新引导)