C语言实现歌曲信息管理系统

时间:2021-08-04 23:14:48

本文实例为大家分享了C语言实现歌曲信息管理系统的具体代码,供大家参考,具体内容如下

系统功能:该系统以菜单方式工作,歌曲信息包括:歌名、演唱者、作词、作曲、所属专辑、出版时间、出版公司。试设计一歌厅歌曲管理系统,使之能提供以下功能:歌曲信息录入、修改、插入、删除功能;歌曲排序浏览功能;按歌名查询、按演唱者查询等功能。

完整的实现代码如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#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;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:http://blog.csdn.net/Hackbuteer1/article/details/6572317