char.docx

上传人:b****8 文档编号:29675331 上传时间:2023-07-26 格式:DOCX 页数:17 大小:17.73KB
下载 相关 举报
char.docx_第1页
第1页 / 共17页
char.docx_第2页
第2页 / 共17页
char.docx_第3页
第3页 / 共17页
char.docx_第4页
第4页 / 共17页
char.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

char.docx

《char.docx》由会员分享,可在线阅读,更多相关《char.docx(17页珍藏版)》请在冰豆网上搜索。

char.docx

char

#include

#include

#include

#defineHEADER1"***********************专家管理系统*************************************\n"

#defineHEADER2"|编号|姓名|知名度|地址|学历|\n"

#defineHEADER3"|--------------|-------------|-------------|-------------|-------------|\n"

#defineFORMAT"|%12s|%12s|%8s颗星|%12s|%12s|\n"

#defineDATAp->num,p->name,p->famous,p->address,p->degree

#defineEND"***************************************************************************\n"

#defineN100

intsaveflag=0;

typedefstructzhuanjia

{

charnum[4];

charname[10];

charfamous[15];

charaddress[10];

chardegree[20];

}expert;

voidmenu();/*主菜单*/

voidprintfheader();/*格式化表头*/

voidprintfdata(expertpp);/*格式化输出表中数据*/

intlocate(experttemp[],intn,charfindmess);/*记录查找定位*/

voidnameselect(experttemp[],intn);/*按姓名排序*/

voidDisp(experttemp[],intn);/*显示全部记录*/

intAdd(experttemp[],intn);/*录入数据*/

voidQur(experttemp[],intn);/*查询记录*/

voidModify(experttemp[],intn);/*修改记录*/

intDel(experttemp[],intn);/*删除记录*/

voidselectsort(experttemp[],intn);/*排序记录*/

voidsave(experttemp[],intn);/*保存文件*/

voidmain()

{

printf("欢迎你使用这个程序\n");

printf("☆☆☆☆☆☆☆☆****\n");

printf("★★★★★****\n");

printf("☆☆祝你快乐!

☆☆*★*★*\n");

printf("★★★★*★*\n");

printf("☆☆☆☆>>>------Iloveyou!

---->\n");

printf("★★★★**\n");

printf("☆☆☆☆*★*\n");

printf("☆☆**\n");

printf("★*\n");

printf("#〓§〓〓〓〓〓§〓〓〓〓〓〓§〓〓〓〓〓§〓#\n");

printf("  ↓     ↓      ↓     ↓\n");

printf(" ☆★☆   ☆★☆    ☆★☆   ☆★☆\n");

printf("☆ 祝 ☆ ☆ 你 ☆  ☆ 幸 ☆ ☆ 福 ☆\n");

printf(" ☆★☆   ☆★☆    ☆★☆   ☆★☆\n");

printf("  ↓     ↓      ↓     ↓\n");

printf("  ※     ※      ※     ※\n");

printf(" //\\\\  //\\\n");

printf("    /`\\\\ // `\\n");

printf("     \\\\//祝你:

\n");

printf(".-'^'-.\n");

printf("    .'a___a`.节日愉快合家欢乐!

\n");

printf("   == (___) ==\n");

printf("    '.._I_..'万事如意心想事成!

\n");

printf("  ____/.`-----'.\____\n");

printf(" [###(__)####\n");

printf("╔┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄╗\n");

printf("编者:

魏自强\n");

printf("│班级:

计算机科学与技术102班│\n");

printf("学号:

2010040101066\n");

printf("╚┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄╝\n\n");

experttele[N];

intselect;

intcount=0;

FILE*fp;

fp=fopen("d:

\\zhuanjia","a+");

if(fp==NULL)

{

printf("没有打开文件");

exit(0);

}

while(!

feof(fp))

{

if(fread(&tele[count],sizeof(zhuanjia),1,fp)==1)/*一次从文件中读取一条专家信息记录*/

count++;

}

fclose(fp);/*关闭文件*/

printf("\n打开文件成功,总共的记录有%d个\n:

",count);

while

(1)

{

menu();

printf("请选择功能0至6,0为退出服务。

\n");

scanf("%d",&select);

switch(select)

{

case1:

count=Add(tele,count),save(tele,count);break;

case2:

Disp(tele,count);break;

case3:

count=Del(tele,count),save(tele,count);break;

case4:

Qur(tele,count),save(tele,count);break;

case5:

Modify(tele,count),save(tele,count);break;

case6:

selectsort(tele,count),save(tele,count);break;

default:

printf("服务以结束谢谢你的使用\n");exit(0);

}

}

}

voidmenu()/*主菜单*/

{

printf("**********************主菜单***********************\n");

printf("*1增加记录2显示记录\n");

printf("*3删除记录4查找记录\n");

printf("*5修改记录6排序记录\n");

printf("*0结束服务,退出程序\n");

printf("***************************************************\n");

}

voidprintfheader()/*格式化表头*/

{

printf(HEADER1);

printf(HEADER2);

printf(HEADER3);

}

voidprintfdata(expertpp)/*格式化输出表中数据*/

{

expert*p;

p=&pp;

printf(FORMAT,DATA);

}

intlocate(experttemp[],intn,charfindmess[20])/*记录查找定位*/

{

intlow=0,high=n-1,mid;

nameselect(temp,n);

printf("12334556677678");

Disp(temp,n);

while(low<=high)

{

mid=(low+high)/2;

if(strcmp(temp[mid].name,findmess)==0)

returnmid;

if(strcmp(temp[mid].name,findmess)>0)

high=mid-1;

else

low=mid+1;

}

return(-1);

}

voidnameselect(experttemp[],intn)/*按姓名排序*/

{

inti,k;

expertnewinfo;

for(k=0;k

{

for(i=1;i

if(strcmp(temp[i-1].name,temp[i].name)>0)

{

strcpy(newinfo.num,temp[i-1].num);

strcpy(newinfo.name,temp[i-1].name);

strcpy(newinfo.famous,temp[i-1].famous);

strcpy(newinfo.address,temp[i-1].address);

strcpy(newinfo.degree,temp[i-1].degree);

strcpy(temp[i-1].num,temp[i].num);

strcpy(temp[i-1].name,temp[i].name);

strcpy(temp[i-1].famous,temp[i].famous);

strcpy(temp[i-1].address,temp[i].address);

strcpy(temp[i-1].degree,temp[i].degree);

strcpy(temp[i].num,newinfo.num);

strcpy(temp[i].name,newinfo.name);

strcpy(temp[i].famous,newinfo.famous);

strcpy(temp[i].address,newinfo.address);

strcpy(temp[i].degree,newinfo.degree);

}

}

}

voidDisp(experttemp[],intn)/*显示全部记录*/

{

inti;

if(n==0)/*没有记录*/

{

printf("以前没有记录,你可以现在输入记录,开始输入\n");

return;

}

printf("\n\n");

printfheader();

i=0;

while(i

{

printfdata(temp[i]);

i++;

printf(HEADER3);

}

}

intAdd(experttemp[],intn)/*录入数据*/

{

charch,num[10];

inti,k=0;

Disp(temp,n);

while

(1)

{

while

(1)

{

printf("输入编号输0结束\n");

scanf("%s",&num);

if(strcmp(num,"0")==0)

{

returnn;

}

i=0;

while(i

{

if(strcmp(temp[i].num,num)==0)

{k=1;break;}

i++;

}

if(k==1)/*重新输入*/

{printf("输入编号已经从在\n");

printf("重新输入(y/Y)不重新输入(其他字母)\n");

fflush(stdin);

scanf("%c",&ch);

if(ch=='y'||ch=='Y')

{

k=0;

continue;

}

else

returnn;

}

else

{break;}

}

strcpy(temp[n].num,num);

printf("输入姓名\n");

scanf("%s",&temp[n].name);

printf("输入知名度\n");

scanf("%s",&temp[n].famous);

printf("输入地址\n");

scanf("%s",&temp[n].address);

printf("输入学历\n");

scanf("%s",&temp[n].degree);

n++;

}

Disp(temp,n);

returnn;

}

voidQur(experttemp[],intn)/*查询记录*/

{

charsearchinput[20];

intp=0;

if(n<=0)

{

printf("\n没有记录");

return;

}

printf("输入你要查找的专家的名字:

");

scanf("%s",&searchinput);

p=locate(temp,n,searchinput);

if(p!

=-1)

{

printfheader();

printfdata(temp[p]);

printf(END);

}

else

printf("没有找到这个记录\n");

}

voidModify(experttemp[],intn)/*修改记录*/

{

charfindmess[20];

intp=0;

if(n<=0)

{

printf("没记录\n");

return;

}

printf("修改专家记录\n");

Disp(temp,n);

printf("你要修改的专家的名字");

scanf("%s",&findmess);

p=locate(temp,n,findmess);

if(p!

=-1)

{

printf("输入编号\n");

scanf("%s",&temp[p].num);

printf("输入姓名\n");

scanf("%s",&temp[p].name);

printf("输入知名度\n");

scanf("%s",&temp[p].famous);

printf("输入地址\n");

scanf("%s",&temp[p].address);

printf("输入学历\n");

scanf("%s",&temp[n].degree);

Disp(temp,n);

}

else

{

printf("没有找到");

}

return;

}

intDel(experttemp[],intn)/*删除记录*/

{

charfindmess[20];

intp=0;

inti=0;

if(n<=0)

{

printf("没有记录");

returnn;

}

printf("全记录");

Disp(temp,n);

printf("要删除记录的专家的姓名");

scanf("%s",&findmess);

p=locate(temp,n,findmess);

if(p!

=-1)

{

for(i=p+1;i

{

strcpy(temp[i-1].num,temp[i].num);

strcpy(temp[i-1].name,temp[i].name);

strcpy(temp[i-1].famous,temp[i].famous);

strcpy(temp[i-1].address,temp[i].address);

strcpy(temp[i-1].degree,temp[i].degree);

}

printf("删除成功\n");

n=n-1;

printf("删除后的全记录为\n");

Disp(temp,n);

}

else

printf("没有找到要删除的记录\n");

returnn;

}

voidselectsort(experttemp[],intn)/*排序记录*/

{

inti=0,j=0,k,select;

expertnewinfo;

if(n<=0)

{

printf("没有记录\n");

return;

}

Disp(temp,n);

printf("*1用编号排名*2用知名度排名\n");

scanf("%d",&select);

if(select==2)

{

for(k=0;k

{

for(i=1;i

if(strcmp(temp[i-1].famous,temp[i].famous)<0)

{

strcpy(newinfo.num,temp[i-1].num);

strcpy(newinfo.name,temp[i-1].name);

strcpy(newinfo.famous,temp[i-1].famous);

strcpy(newinfo.address,temp[i-1].address);

strcpy(newinfo.degree,temp[i-1].degree);

strcpy(temp[i-1].num,temp[i].num);

strcpy(temp[i-1].name,temp[i].name);

strcpy(temp[i-1].famous,temp[i].famous);

strcpy(temp[i-1].address,temp[i].address);

strcpy(temp[i-1].degree,temp[i].degree);

strcpy(temp[i].num,newinfo.num);

strcpy(temp[i].name,newinfo.name);

strcpy(temp[i].famous,newinfo.famous);

strcpy(temp[i].address,newinfo.address);

strcpy(temp[i].degree,newinfo.degree);

}

}

}

elseif(select==1)

{

for(i=0;i

for(k=0;k

for(i=k+1;i

if(strcmp(temp[k].num,temp[i].num)>0)

{

strcpy(newinfo.num,temp[k].num);

strcpy(newinfo.name,temp[k].name);

strcpy(newinfo.famous,temp[k].famous);

strcpy(newinfo.address,temp[k].address);

strcpy(newinfo.degree,temp[k].degree);

strcpy(temp[k].num,temp[i].num);

strcpy(temp[k].name,temp[i].name);

strcpy(temp[k].famous,temp[i].famous);

strcpy(temp[k].address,temp[i].address);

strcpy(temp[k].degree,temp[i].degree);

strcpy(temp[i].num,newinfo.num);

strcpy(temp[i].name,newinfo.name);

strcpy(temp[i].famous,newinfo.famous);

strcpy(temp[i].address,newinfo.address);

strcpy(temp[i].degree,newinfo.degree);

}

}

printf("排序后的记录为\n");

Disp(temp,n);

return;

}

voidsave(experttemp[],intn)/*保存文件*/

{

FILE*fp;

inti=0;

fp=fopen("d:

\\zhuanjia","w");

if(fp==NULL)

{

printf("\n打开文件错误!

\n");

getchar();

return;

}

for(i=0;i

{

if(fwrite(&temp[i],sizeof(expert),1,fp)==1)/*每次写一条记录*/

{

continue;

}

else

{

break;

}

}

if(i>0)

{

getchar();

printf("\n\n文件以保存到电脑中,现在一共有:

%d个文件\n",i);

saveflag=0;

}

else

{

system("cls");

printf("当前连接为空,没有记录被保存!

\n");

}

fclose(fp);

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 面试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1