C语言程序设计报告歌曲信息管理系统.docx
《C语言程序设计报告歌曲信息管理系统.docx》由会员分享,可在线阅读,更多相关《C语言程序设计报告歌曲信息管理系统.docx(14页珍藏版)》请在冰豆网上搜索。
C语言程序设计报告歌曲信息管理系统
《高级语言程序设计》课程设计
说明书
设计题目:
歌曲信息管理系统设计
1、设计题目·····································3
2、主函数·······································4
3、输入模块·····································4
4、删除模块·····································5
5、浏览模块·····································6
6、查找模块·····································6
7、各被调函数···································7
8、设计小结·····································8
9、源程序代码···································8
1、需求分析:
用文件存储信息,因而要提供文件的输入输出操作;可对歌曲信息进行输入、删除、浏览,因而要提供文件的输入、删除和信息显示操作;查询歌曲信息要提供查找操作;实现按作者分组显示功能则要提供排序功能;另外要提供键盘式选择菜单以实现功能选择。
2、总体设计:
整个管理系统可以被设计为数据输入模块、数据删除模块、信息浏览模块、信息查询模块和信息分组显示模块。
3、详细设计
数据结构采用结构体,建立歌曲信息结构体:
StructSongInfo
{Charname[20];//歌曲名
Charauthor[20];//作者
Charsinger[20];//演唱者
Charpub_date[6];//发行年月(yyyymm)
}SI;
(1)数据输入模块把歌曲信息写入文件。
(2)数据删除模块采用基本的查找算法,查找歌曲信息文件,如果是要删除的歌曲,则舍弃改信息。
否则重新写入文件。
(3)信息浏览模块读歌曲信息文件,显示输出。
(4)信息查询模块通过菜单选择查询字段:
歌曲名作者演唱者。
然后采用基本查找算法在歌曲信息文件中查找,如果找到,则输出;否则输出“对不起,没有您要找的歌曲信息!
。
”
(5)信息分组显示模块选择按作者分组显示歌曲信息,用fread或fscanf把歌曲信息文件中的信息读取到临时变量中(临时变量数据结构可以采用歌曲信息结构体数组),采用排序算法(冒泡、插入、选择等)把歌曲信息按照作者排序,然后输出。
一:
详细设计
1主函数
主函数的设计提供数据输入、数据处理和数据输出以及各种函数的调用。
其中各功能模块用菜单方式选择;另外,部分菜单也可以写成函数。
[程序]
voidmain()
{
voidmenu();
voidfunction1();
voidfunction2();
voidfunction3();
voidfunction4();
menu();
return;
}
2各功能模块设计
(1)输入模块
信息输入时直接按顺序结构(如图2)输入:
voidinput()
{charch;
n=0;
if((fp=fopen("song.txt","a"))==NULL)
printf("can'topenfilesong.txt");
exit(0);
printf("Pleaseinputarecord:
");
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删除模块:
用户输入要删除的信息,如输入歌曲名,根据歌曲名找到其他记录并删除。
/******************删除模块*************************/
voiddel()
intm,k=0;
longa;
charnamekey[8];
printf("\n请输入您要删除的歌曲名:
scanf("%s",namekey);
if((fp=fopen("song.txt","r+"))==NULL)
printf("\n不能打开该文件!
while(!
feof(fp))
a=ftell(fp);
fscanf(fp,"%6s%5s%5s%10s\n",song[n].name,song[n].year,song[n].author,song[n].singer);
if(strcmp(namekey,song[n].name)==0)
k=1;
if(k==1)
printf("\n已查到,记录为");
printf("\n%6s%5s%5s%10s\n",song[n].name,song[n].year,song[n].author,song[n].singer);
printf("\n确实要删除,按1;不删除,按0:
scanf("%d",&m);
if(m==1)
fseek(fp,a,0);
fprintf(fp,"%s%s%s%s\n","","","","");
else
printf("\n对不起,查无此人。
3·浏览模块:
在用户按下菜单后直接显示出所有歌曲信息。
voidxianshi()
{n=0;
if((fp=fopen("song.txt","rb"))==NULL)
printf("can'topenthefilesong.txt");
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);
4·查找模块:
用户输入要查找的歌曲名或歌曲的任意信息,按菜单键。
voidsearchname()
inta=0;charch;n=0;
printf("cannotopenthefile.\n");
a=n;
printf("用什么方式查询?
\n");
printf("1.歌名2.时间3.歌手\n");
switch(ch)
case'1':
printf("输入你要查的歌名:
gets(numstr);
for(n=0;n{if(!strcmp(numstr,song[n].name))break;n++;}break;case'2':printf("输入你要查的歌曲时间\n");gets(numstr);for(n=0;n{if(atol(numstr)==song[n].year)break;n++;}break;case'3':printf("输入你要查的歌手\n");gets(numstr);for(n=0;n{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].singer);fclose(fp);}6各种被调函数(1)insert函数:数据的插入,用于个人的信息的补录,包括姓名、工作单位、电话号码和email地址。(2)del函数:用于通讯录中个人信息的删除。(3)change函数:用于通讯录中个人信息的修改,输入人名,对人名所对应的机构体内容进行修改(包括姓名、工作单位、电话号码和email信息)。(4)searchname函数:用于输入姓名查找个人信息。如果通讯录中没有此人信息,显示“查无此人!”。(5)searchnum函数:用于输入电话号码查询个人信息。如果通讯录中没此人信息,显示“查无此人!”。(6)show函数:用于个人全部信息的显示。(7)income函数:用于所有原始个人信息的录入(包括姓名、电话号码、工作单位和email地址)。设计小结:本程序大体参考与网上信息,说实话,这程序我无法完成,但又必须做,即使不会或者做不完美,但是也要尽力去做,做这个程序是要我们能够使用所学的内容,这次设计,让我重新掌握了C语言,而且还得到了用C语言解决实际问题的宝贵经验,也从中学到了很多东西。让我懂得了做什么事都要有耐心,要有对什么事都认真仔细的品质,让我学会了很多以前不懂的东西,使我更加意识到实践的重要性!三:原程序#include#include#include#includeinti=0;structsystem{charauthor[20];charsinger[20];chartime[20];charname[20];}dan[100];voidenter(){intj;charc[2];FILE*fp;if((fp=fopen("data.txt","w"))==NULL){printf("Cannotopenthefile!\n");exit(0);}for(j=0;j{fwrite(&dan[j],sizeof(structsystem),1,fp);}while(1){printf("Pleaseinputtheauthor:\n");scanf("%s",dan[i].author);printf("Pleaseinputthesong'sname:\n");scanf("%s",dan[i].name);printf("Pleaseinputthesinger:\n");scanf("%s",dan[i].singer);printf("Pleaseinputtheoutday:\n");scanf("%s",dan[i].time);if(fwrite(&dan[i++],sizeof(structsystem),1,fp)!=1)printf("Filewriteerror\n");elseprintf("Successful!\n");printf("Isthereanymore?(Yes[y]/No[n])\n");scanf("%s",c);if(strcmp(c,"n")==0)break;}fclose(fp);}voiddelete(){intj,v,c;charw[20];FILE*fp;printf("Pleaseinputthesong'namewhichyouwanttodelete:");scanf("%s",w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),1,fp)!=1)break;}v=j;for(j=0;j{if(strcmp(w,dan[j].name)==0)c=j;}fclose(fp);fp=fopen("data.txt","wb");for(j=0;j{if(j!=c)fwrite(&dan[j],sizeof(structsystem),1,fp);}fclose(fp);printf("DeleteOK!\n");i--;}voidbrowse(){intj;FILE*fp;fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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");}elsebreak;}fclose(fp);}voidsearch(){intflag,j,x;charw[20];FILE*fp;charv[20];printf("(1)Byauthor\n");printf("(2)Bysinger\n");printf("(3)Byname\n");printf("Pleasechoosewhichyouwanttosearch:\n");scanf("%d",&x);if(x==3){flag=0;printf("Pleaseinputthesong'sname:");scanf("%s",&w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseif(x==2){flag=0;printf("Pleaseinputthesinger:");scanf("%s",&v);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseif(x==1){flag=0;printf("Pleaseinputtheauthor:");scanf("%s",w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseprintf("Error!\n");}main(){inta;while(1){printf("\t\tWelcometothesong'system!------byflea\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\tPleasechoosethenumber(0-4):");scanf("%d",&a);if(a==0)break;switch(a){case1:enter();break;case2:delete();break;case3:browse();break;case4:search();break;}}}
if(!
strcmp(numstr,song[n].name))
case'2':
printf("输入你要查的歌曲时间\n");
for(n=0;n{if(atol(numstr)==song[n].year)break;n++;}break;case'3':printf("输入你要查的歌手\n");gets(numstr);for(n=0;n{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].singer);fclose(fp);}6各种被调函数(1)insert函数:数据的插入,用于个人的信息的补录,包括姓名、工作单位、电话号码和email地址。(2)del函数:用于通讯录中个人信息的删除。(3)change函数:用于通讯录中个人信息的修改,输入人名,对人名所对应的机构体内容进行修改(包括姓名、工作单位、电话号码和email信息)。(4)searchname函数:用于输入姓名查找个人信息。如果通讯录中没有此人信息,显示“查无此人!”。(5)searchnum函数:用于输入电话号码查询个人信息。如果通讯录中没此人信息,显示“查无此人!”。(6)show函数:用于个人全部信息的显示。(7)income函数:用于所有原始个人信息的录入(包括姓名、电话号码、工作单位和email地址)。设计小结:本程序大体参考与网上信息,说实话,这程序我无法完成,但又必须做,即使不会或者做不完美,但是也要尽力去做,做这个程序是要我们能够使用所学的内容,这次设计,让我重新掌握了C语言,而且还得到了用C语言解决实际问题的宝贵经验,也从中学到了很多东西。让我懂得了做什么事都要有耐心,要有对什么事都认真仔细的品质,让我学会了很多以前不懂的东西,使我更加意识到实践的重要性!三:原程序#include#include#include#includeinti=0;structsystem{charauthor[20];charsinger[20];chartime[20];charname[20];}dan[100];voidenter(){intj;charc[2];FILE*fp;if((fp=fopen("data.txt","w"))==NULL){printf("Cannotopenthefile!\n");exit(0);}for(j=0;j{fwrite(&dan[j],sizeof(structsystem),1,fp);}while(1){printf("Pleaseinputtheauthor:\n");scanf("%s",dan[i].author);printf("Pleaseinputthesong'sname:\n");scanf("%s",dan[i].name);printf("Pleaseinputthesinger:\n");scanf("%s",dan[i].singer);printf("Pleaseinputtheoutday:\n");scanf("%s",dan[i].time);if(fwrite(&dan[i++],sizeof(structsystem),1,fp)!=1)printf("Filewriteerror\n");elseprintf("Successful!\n");printf("Isthereanymore?(Yes[y]/No[n])\n");scanf("%s",c);if(strcmp(c,"n")==0)break;}fclose(fp);}voiddelete(){intj,v,c;charw[20];FILE*fp;printf("Pleaseinputthesong'namewhichyouwanttodelete:");scanf("%s",w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),1,fp)!=1)break;}v=j;for(j=0;j{if(strcmp(w,dan[j].name)==0)c=j;}fclose(fp);fp=fopen("data.txt","wb");for(j=0;j{if(j!=c)fwrite(&dan[j],sizeof(structsystem),1,fp);}fclose(fp);printf("DeleteOK!\n");i--;}voidbrowse(){intj;FILE*fp;fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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");}elsebreak;}fclose(fp);}voidsearch(){intflag,j,x;charw[20];FILE*fp;charv[20];printf("(1)Byauthor\n");printf("(2)Bysinger\n");printf("(3)Byname\n");printf("Pleasechoosewhichyouwanttosearch:\n");scanf("%d",&x);if(x==3){flag=0;printf("Pleaseinputthesong'sname:");scanf("%s",&w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseif(x==2){flag=0;printf("Pleaseinputthesinger:");scanf("%s",&v);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseif(x==1){flag=0;printf("Pleaseinputtheauthor:");scanf("%s",w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseprintf("Error!\n");}main(){inta;while(1){printf("\t\tWelcometothesong'system!------byflea\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\tPleasechoosethenumber(0-4):");scanf("%d",&a);if(a==0)break;switch(a){case1:enter();break;case2:delete();break;case3:browse();break;case4:search();break;}}}
if(atol(numstr)==song[n].year)
case'3':
printf("输入你要查的歌手\n");
for(n=0;n{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].singer);fclose(fp);}6各种被调函数(1)insert函数:数据的插入,用于个人的信息的补录,包括姓名、工作单位、电话号码和email地址。(2)del函数:用于通讯录中个人信息的删除。(3)change函数:用于通讯录中个人信息的修改,输入人名,对人名所对应的机构体内容进行修改(包括姓名、工作单位、电话号码和email信息)。(4)searchname函数:用于输入姓名查找个人信息。如果通讯录中没有此人信息,显示“查无此人!”。(5)searchnum函数:用于输入电话号码查询个人信息。如果通讯录中没此人信息,显示“查无此人!”。(6)show函数:用于个人全部信息的显示。(7)income函数:用于所有原始个人信息的录入(包括姓名、电话号码、工作单位和email地址)。设计小结:本程序大体参考与网上信息,说实话,这程序我无法完成,但又必须做,即使不会或者做不完美,但是也要尽力去做,做这个程序是要我们能够使用所学的内容,这次设计,让我重新掌握了C语言,而且还得到了用C语言解决实际问题的宝贵经验,也从中学到了很多东西。让我懂得了做什么事都要有耐心,要有对什么事都认真仔细的品质,让我学会了很多以前不懂的东西,使我更加意识到实践的重要性!三:原程序#include#include#include#includeinti=0;structsystem{charauthor[20];charsinger[20];chartime[20];charname[20];}dan[100];voidenter(){intj;charc[2];FILE*fp;if((fp=fopen("data.txt","w"))==NULL){printf("Cannotopenthefile!\n");exit(0);}for(j=0;j{fwrite(&dan[j],sizeof(structsystem),1,fp);}while(1){printf("Pleaseinputtheauthor:\n");scanf("%s",dan[i].author);printf("Pleaseinputthesong'sname:\n");scanf("%s",dan[i].name);printf("Pleaseinputthesinger:\n");scanf("%s",dan[i].singer);printf("Pleaseinputtheoutday:\n");scanf("%s",dan[i].time);if(fwrite(&dan[i++],sizeof(structsystem),1,fp)!=1)printf("Filewriteerror\n");elseprintf("Successful!\n");printf("Isthereanymore?(Yes[y]/No[n])\n");scanf("%s",c);if(strcmp(c,"n")==0)break;}fclose(fp);}voiddelete(){intj,v,c;charw[20];FILE*fp;printf("Pleaseinputthesong'namewhichyouwanttodelete:");scanf("%s",w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),1,fp)!=1)break;}v=j;for(j=0;j{if(strcmp(w,dan[j].name)==0)c=j;}fclose(fp);fp=fopen("data.txt","wb");for(j=0;j{if(j!=c)fwrite(&dan[j],sizeof(structsystem),1,fp);}fclose(fp);printf("DeleteOK!\n");i--;}voidbrowse(){intj;FILE*fp;fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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");}elsebreak;}fclose(fp);}voidsearch(){intflag,j,x;charw[20];FILE*fp;charv[20];printf("(1)Byauthor\n");printf("(2)Bysinger\n");printf("(3)Byname\n");printf("Pleasechoosewhichyouwanttosearch:\n");scanf("%d",&x);if(x==3){flag=0;printf("Pleaseinputthesong'sname:");scanf("%s",&w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseif(x==2){flag=0;printf("Pleaseinputthesinger:");scanf("%s",&v);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseif(x==1){flag=0;printf("Pleaseinputtheauthor:");scanf("%s",w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseprintf("Error!\n");}main(){inta;while(1){printf("\t\tWelcometothesong'system!------byflea\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\tPleasechoosethenumber(0-4):");scanf("%d",&a);if(a==0)break;switch(a){case1:enter();break;case2:delete();break;case3:browse();break;case4:search();break;}}}
strcmp(numstr,song[n].singer))
printf("歌名作者歌手时间\n");
printf("%6s%5s%5s%10s\n",song[n].name,song[n].year,song[n].author,song[n].singer);
6各种被调函数
(1)insert函数:
数据的插入,用于个人的信息的补录,包括姓名、工作单位、电话号码和email地址。
(2)del函数:
用于通讯录中个人信息的删除。
(3)change函数:
用于通讯录中个人信息的修改,输入人名,对人名所对应的机构体内容进行修改(包括姓名、工作单位、电话号码和email信息)。
(4)searchname函数:
用于输入姓名查找个人信息。
如果通讯录中没有此人信息,显示“查无此人!
”。
(5)searchnum函数:
用于输入电话号码查询个人信息。
如果通讯录中没此人信息,显示“查无此人!
(6)show函数:
用于个人全部信息的显示。
(7)income函数:
用于所有原始个人信息的录入(包括姓名、电话号码、工作单位和email地址)。
设计小结:
本程序大体参考与网上信息,说实话,这程序我无法完成,但又必须做,即使不会或者做不完美,但是也要尽力去做,做这个程序是要我们能够使用所学的内容,这次设计,让我重新掌握了C语言,而且还得到了用C语言解决实际问题的宝贵经验,也从中学到了很多东西。
让我懂得了做什么事都要有耐心,要有对什么事都认真仔细的品质,让我学会了很多以前不懂的东西,使我更加意识到实践的重要性!
三:
原程序
#include
inti=0;
structsystem
charauthor[20];
charsinger[20];
chartime[20];
charname[20];
}dan[100];
voidenter()
intj;
charc[2];
FILE*fp;
if((fp=fopen("data.txt","w"))==NULL)
printf("Cannotopenthefile!
for(j=0;j
fwrite(&dan[j],sizeof(structsystem),1,fp);
while
(1)
printf("Pleaseinputtheauthor:
scanf("%s",dan[i].author);
printf("Pleaseinputthesong'sname:
scanf("%s",dan[i].name);
printf("Pleaseinputthesinger:
scanf("%s",dan[i].singer);
printf("Pleaseinputtheoutday:
scanf("%s",dan[i].time);
if(fwrite(&dan[i++],sizeof(structsystem),1,fp)!
=1)
printf("Filewriteerror\n");
elseprintf("Successful!
printf("Isthereanymore?
(Yes[y]/No[n])\n");
scanf("%s",c);
if(strcmp(c,"n")==0)break;
voiddelete()
intj,v,c;
charw[20];
printf("Pleaseinputthesong'namewhichyouwanttodelete:
scanf("%s",w);
fp=fopen("data.txt","rb");
for(j=0;j<100;j++)
if(fread(&dan[j],sizeof(structsystem),1,fp)!
=1)break;
v=j;
for(j=0;j{if(strcmp(w,dan[j].name)==0)c=j;}fclose(fp);fp=fopen("data.txt","wb");for(j=0;j{if(j!=c)fwrite(&dan[j],sizeof(structsystem),1,fp);}fclose(fp);printf("DeleteOK!\n");i--;}voidbrowse(){intj;FILE*fp;fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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");}elsebreak;}fclose(fp);}voidsearch(){intflag,j,x;charw[20];FILE*fp;charv[20];printf("(1)Byauthor\n");printf("(2)Bysinger\n");printf("(3)Byname\n");printf("Pleasechoosewhichyouwanttosearch:\n");scanf("%d",&x);if(x==3){flag=0;printf("Pleaseinputthesong'sname:");scanf("%s",&w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseif(x==2){flag=0;printf("Pleaseinputthesinger:");scanf("%s",&v);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseif(x==1){flag=0;printf("Pleaseinputtheauthor:");scanf("%s",w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseprintf("Error!\n");}main(){inta;while(1){printf("\t\tWelcometothesong'system!------byflea\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\tPleasechoosethenumber(0-4):");scanf("%d",&a);if(a==0)break;switch(a){case1:enter();break;case2:delete();break;case3:browse();break;case4:search();break;}}}
if(strcmp(w,dan[j].name)==0)
c=j;
fp=fopen("data.txt","wb");
for(j=0;j{if(j!=c)fwrite(&dan[j],sizeof(structsystem),1,fp);}fclose(fp);printf("DeleteOK!\n");i--;}voidbrowse(){intj;FILE*fp;fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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");}elsebreak;}fclose(fp);}voidsearch(){intflag,j,x;charw[20];FILE*fp;charv[20];printf("(1)Byauthor\n");printf("(2)Bysinger\n");printf("(3)Byname\n");printf("Pleasechoosewhichyouwanttosearch:\n");scanf("%d",&x);if(x==3){flag=0;printf("Pleaseinputthesong'sname:");scanf("%s",&w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseif(x==2){flag=0;printf("Pleaseinputthesinger:");scanf("%s",&v);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseif(x==1){flag=0;printf("Pleaseinputtheauthor:");scanf("%s",w);fp=fopen("data.txt","rb");for(j=0;j<100;j++){if(fread(&dan[j],sizeof(structsystem),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("Cannotfindthesong!\n");fclose(fp);}elseprintf("Error!\n");}main(){inta;while(1){printf("\t\tWelcometothesong'system!------byflea\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\tPleasechoosethenumber(0-4):");scanf("%d",&a);if(a==0)break;switch(a){case1:enter();break;case2:delete();break;case3:browse();break;case4:search();break;}}}
if(j!
=c)
printf("DeleteOK!
i--;
voidbrowse()
if(fread(&dan[j],sizeof(structsystem),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");
elsebreak;
voidsearch()
intflag,j,x;
charv[20];
printf("
(1)Byauthor\n");
(2)Bysinger\n");
printf("(3)Byname\n");
printf("Pleasechoosewhichyouwanttosearch:
scanf("%d",&x);
if(x==3)
flag=0;
scanf("%s",&w);
if(strcmp(dan[j].name,w)==0)
flag=1;
if(flag==0)
printf("Cannotfindthesong!
elseif(x==2)
scanf("%s",&v);
if(strcmp(dan[j].singer,v)==0)
elseif(x==1)
if(strcmp(dan[j].author,w)==0)
elseprintf("Error!
main()
inta;
printf("\t\tWelcometothesong'system!
------byflea\n");
printf("\t\t******************^o^MENU^o^*******************\n\n");
printf("\t\t\t
(1).Enter\n");
(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\tPleasechoosethenumber(0-4):
scanf("%d",&a);
if(a==0)break;
switch(a)
case1:
enter();break;
case2:
delete();break;
case3:
browse();break;
case4:
search();break;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1