《高级语言程序设计》课程设计说明书设计题目:歌曲信息管理系统设计目录1、设计题目 (3)2、主函数 (4)3、输入模块 (4)4、删除模块 (5)5、浏览模块 (6)6、查找模块 (6)7、各被调函数 (7)8、设计小结 (8)9、源程序代码 (8)歌曲信息管理系统设计1、需求分析:用文件存储信息,因而要提供文件的输入输出操作;可对歌曲信息进行输入、删除、浏览,因而要提供文件的输入、删除和信息显示操作;查询歌曲信息要提供查找操作;实现按作者分组显示功能则要提供排序功能;另外要提供键盘式选择菜单以实现功能选择。
2、总体设计:整个管理系统可以被设计为数据输入模块、数据删除模块、信息浏览模块、信息查询模块和信息分组显示模块。
3、详细设计数据结构采用结构体,建立歌曲信息结构体:Struct SongInfo{ Char name[20]; //歌曲名Char author[20]; //作者Char singer[20]; //演唱者Char pub_date[6]; //发行年月(yyyymm)}SI;(1) 数据输入模块把歌曲信息写入文件。
(2) 数据删除模块采用基本的查找算法,查找歌曲信息文件,如果是要删除的歌曲,则舍弃改信息。
否则重新写入文件。
(3) 信息浏览模块读歌曲信息文件,显示输出。
(4) 信息查询模块通过菜单选择查询字段:歌曲名作者演唱者。
然后采用基本查找算法在歌曲信息文件中查找,如果找到,则输出;否则输出“对不起,没有您要找的歌曲信息!。
”(5) 信息分组显示模块选择按作者分组显示歌曲信息,用fread 或fscanf 把歌曲信息文件中的信息读取到临时变量中(临时变量数据结构可以采用歌曲信息结构体数组),采用排序算法(冒泡、插入、选择等)把歌曲信息按照作者排序,然后输出。
一:详细设计1主函数主函数的设计提供数据输入、数据处理和数据输出以及各种函数的调用。
其中各功能模块用菜单方式选择;另外,部分菜单也可以写成函数。
[程序]void main(){void menu();void function1();void function2();void function3();void function4();menu();return;}2 各功能模块设计(1)输入模块信息输入时直接按顺序结构(如图2)输入:void input(){ char ch;n=0;if((fp=fopen("song.txt","a"))==NULL){printf("can't open file song.txt");exit(0);}printf("Please input a record:");for(n=0;n<=50;){printf("\nrecord %d:\n歌名:",n+1);gets(song[n].name);printf("\n时间:");gets(song[n].year);printf("\n作者:");gets(song[n].author);printf("\n歌手:");gets(song[n].singer);n++;printf("继续输入吗?(y/n)\n");ch=getchar();getchar();if(ch=='n')break;}fwrite(song,sizeof(song[0]),n,fp);fclose(fp);}2删除模块:用户输入要删除的信息,如输入歌曲名,根据歌曲名找到其他记录并删除。
[程序]/******************删除模块*************************/void del(){int m,k=0;long a;char namekey[8];printf("\n请输入您要删除的歌曲名:");scanf("%s",namekey);if((fp=fopen("song.txt","r+"))==NULL){printf("\n不能打开该文件!");exit(0);}while(!feof(fp))a=ftell(fp);fscanf(fp,"%6s %5s %5s %10s\n",song[n].name,song[n].year,song[n].author,song[n].s inger);if(strcmp(namekey,song[n].name)==0){k=1;break;}}if(k==1){printf("\n已查到,记录为");printf("\n%6s %5s %5s %10s\n",song[n].name,song[n].year,song[n].author,song[n].si nger);printf("\n确实要删除,按1;不删除,按0:");scanf("%d",&m);if(m==1){fseek(fp,a,0);fprintf(fp,"%s %s %s %s\n"," " ," "," "," ");}}elseprintf("\n对不起,查无此人。
");fclose(fp);}3·浏览模块:在用户按下菜单后直接显示出所有歌曲信息。
void xianshi(){ n=0;if((fp=fopen("song.txt","rb"))==NULL){printf("can't open the file song.txt");exit(0);}printf(" 歌名\t 作者\t 歌手时间\n");while(fread(&song[n],sizeof(song[n]),1,fp)==1){printf("%6s %5s %10s %5s\n",song[n].name,song[n].author,song[n].singer,song[n]. year);n++;fclose(fp);}4·查找模块:用户输入要查找的歌曲名或歌曲的任意信息,按菜单键。
void searchname() {int a=0; char ch; n=0;if((fp=fopen("song.txt","rb"))==NULL){printf("can not open the file.\n ");exit(0);}while(fread(&song[n],sizeof(song[n]),1,fp)==1)n++;a=n;printf("用什么方式查询?\n");printf("1.歌名2.时间3.歌手\n");ch=getchar();getchar();switch(ch){case '1':printf(" 输入你要查的歌名:\n");gets(numstr);for(n=0;n<a;){if(!strcmp(numstr,song[n].name))break;n++;}break;case '2':printf("输入你要查的歌曲时间\n");gets(numstr);for(n=0;n<a;){if(atol(numstr)==song[n].year)break;n++;}break;case '3':printf("输入你要查的歌手\n");gets(numstr);for(n=0;n<a;){if(!strcmp(numstr,song[n].singer))break;n++;}break;}printf(" 歌名作者歌手时间\n");printf("%6s %5s %5s %10s\n",song[n].name,song[n].year,song[n].author,song[n].sing er);fclose(fp);}6 各种被调函数(1)insert函数:数据的插入,用于个人的信息的补录,包括姓名、工作单位、电话号码和email地址。
(2)del函数:用于通讯录中个人信息的删除。
(3)change函数:用于通讯录中个人信息的修改,输入人名,对人名所对应的机构体内容进行修改(包括姓名、工作单位、电话号码和email信息)。
(4)searchname函数:用于输入姓名查找个人信息。
如果通讯录中没有此人信息,显示“查无此人!”。
(5)searchnum函数:用于输入电话号码查询个人信息。
如果通讯录中没此人信息,显示“查无此人!”。
(6)show函数:用于个人全部信息的显示。
(7)income函数:用于所有原始个人信息的录入(包括姓名、电话号码、工作单位和email地址)。
设计小结:本程序大体参考与网上信息,说实话,这程序我无法完成,但又必须做,即使不会或者做不完美,但是也要尽力去做,做这个程序是要我们能够使用所学的内容,这次设计,让我重新掌握了C语言,而且还得到了用C语言解决实际问题的宝贵经验,也从中学到了很多东西。
让我懂得了做什么事都要有耐心,要有对什么事都认真仔细的品质,让我学会了很多以前不懂的东西,使我更加意识到实践的重要性!三:原程序#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <string.h>int i=0;struct system{char author[20];char singer[20];char time[20];char name[20];} dan[100];void enter(){int j;char c[2];FILE *fp;if((fp=fopen("data.txt","w"))==NULL) {printf("Can not open the file!\n");exit(0);}for(j=0;j<i;j++){fwrite(&dan[j],sizeof(struct system),1,fp);}while(1){printf("Please input the author:\n");scanf("%s",dan[i].author);printf("Please input the song's name:\n");scanf("%s",dan[i].name);printf("Please input the singer:\n");scanf("%s",dan[i].singer);printf("Please input the outday:\n");scanf("%s",dan[i].time);if(fwrite(&dan[i++],sizeof(struct system),1,fp)!=1) printf("File write error\n");else printf("Successful!\n");printf("Is there any more?( Yes[y]/No[n]) \n");scanf("%s",c);if(strcmp(c,"n")==0)break;}fclose(fp);}void delete(){int j,v,c;char w[20];FILE *fp;printf("Please input the song'name which you want to delete:");scanf("%s",w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(struct system),1,fp)!=1) break;}v=j;for(j=0;j<v;j++){if(strcmp(w,dan[j].name)==0)c=j;}fclose(fp);fp=fopen("data.txt","wb");for(j=0;j<v;j++){if(j!=c)fwrite(&dan[j],sizeof(struct system),1,fp);}fclose(fp);printf("Delete OK!\n");i--;}void browse(){int j;FILE *fp;fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(struct system),1,fp)==1){printf("Name:%s\n",dan[j].name);printf("Author:%s\n",dan[j].author);printf("Singer:%s\n",dan[j].singer);printf("Outday:%s\n",dan[j].time);printf("---------------------------------\n");}else break;}fclose(fp);}void search(){int flag,j,x;char w[20];FILE *fp;char v[20];printf("(1)By author\n");printf("(2)By singer\n");printf("(3)By name\n");printf("Please choose which you want to search:\n");scanf("%d",&x);if(x==3){flag=0;printf("Please input the song's name:");scanf("%s",&w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(struct system),1,fp)!=1) break;if(strcmp(dan[j].name,w)==0){printf("Name:%s\n",dan[j].name);printf("Author:%s\n",dan[j].author);printf("Singer:%s\n",dan[j].singer);printf("Outday:%s\n",dan[j].time);printf("---------------------------------\n");flag=1;}}if(flag==0)printf("Cannot find the song!\n");fclose(fp);}else if(x==2){flag=0;printf("Please input the singer:");scanf("%s",&v);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(struct system),1,fp)!=1) break;if(strcmp(dan[j].singer,v)==0){printf("Name:%s\n",dan[j].name);printf("Author:%s\n",dan[j].author);printf("Singer:%s\n",dan[j].singer);printf("Outday:%s\n",dan[j].time);printf("---------------------------------\n");flag=1;}}if(flag==0)printf("Cannot find the song!\n");fclose(fp);}else if(x==1){flag=0;printf("Please input the author:");scanf("%s",w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(struct system),1,fp)!=1) break;if(strcmp(dan[j].author,w)==0){printf("Name:%s\n",dan[j].name);printf("Author:%s\n",dan[j].author);printf("Singer:%s\n",dan[j].singer);printf("Outday:%s\n",dan[j].time);printf("---------------------------------\n");flag=1;}}if(flag==0)printf("Cannot find the song!\n");fclose(fp);}else printf("Error!\n");}main(){int a;while(1){printf("\t\tWelcome to the song'system!------by flea\n");printf("\t\t******************^o^ MENU ^o^*******************\n\n");printf("\t\t\t(1).Enter\n");printf("\t\t\t(2).Delete\n");printf("\t\t\t(3).Browse\n");printf("\t\t\t(4).Search\n");printf("\t\t\t(0).exit\n");printf("\t\t*************************************************\n ");printf("\n\t\t\tPlease choose the number(0-4):");scanf("%d",&a);if(a==0) break;switch(a){case 1:enter();break;case 2:delete();break;case 3:browse();break;case 4:search();break;}}}。