管理系统模板.docx
- 文档编号:7335662
- 上传时间:2023-01-23
- 格式:DOCX
- 页数:9
- 大小:17.32KB
管理系统模板.docx
《管理系统模板.docx》由会员分享,可在线阅读,更多相关《管理系统模板.docx(9页珍藏版)》请在冰豆网上搜索。
管理系统模板
#include
#include
#include
#include
#include
structinformation{
intnum; //工号
charname[30];
charbirth[20];
chargender[10]; //性别
chareducation[20];//学历
charposition[30]; //职位
doublewage; //工资
charaddress[200];
charphone[15];
structinformation*next;
};
typedefstructinformationinfor;
typedefinfor*inforPtr;
voidmenu(void);
voidadd(inforPtr*sPtr,intvalue);
intexist(inforPtr*sPtr,intvalue);
voiddisplay(inforPtrnewList);
voidquery(inforPtr*sPtr,int(*compare)(inforPtroriginal,inforPtrcreat));
intqueryByWage(inforPtroriginal,inforPtrcreat);
voidsave(inforPtr*sPtr);
voidload(inforPtr*sPtr);
voiddel(inforPtr*sPtr,intvalue);
intmain(void)
{
inforPtrstartList=NULL;
intselect;
intnum;
intdelNum;
printf("**************************欢迎使用职工信息管理系统*****************************\n");
load(&startList); //读取文件数据,传入链表以便传从load函数递链表至主函数
display(startList);
printf("\n\n\n");
menu();
scanf("%d",&select);
while(select!
=9)
{
switch(select){
case1:
printf("输入工号:
\n?
");
scanf("%d",&num);
if(exist(&startList,num))
{
printf("记录已经存在,不能添加\n\n");
break;
}
else
add(&startList,num);
break;
case2:
display(startList);
break;
case3:
query(&startList,queryByWage);
break;
case4:
// save(&startList);
break;
case5:
// load(&startList);
break;
case6:
printf("输入要删除员工工号:
\n?
");
scanf("%d",&delNum);
if(!
exist(&startList,delNum))
{
printf("记录不存在,无法删除!
\n\n");
break;
}
else
del(&startList,delNum);
break;
}
menu();
scanf("%d",&select);
}
return0;
}
/****菜单*****/
voidmenu(void)
{
puts("1.增加新纪录.");
puts("2.按工号显示记录");
puts("3.按工资排序");
// puts("4.保存");
// puts("5.读取");
puts("6.删除");
puts("9.退出");
printf("?
");
}
/*判断是否已经存在工号*/
intexist(inforPtr*sPtr,intvalue) /*判断工号是否已经存在*/
{
inforPtrcurrent;
current=*sPtr;
while(current!
=NULL)
{
if(value==current->num)
return1;
current=current->next;
}
return0;
}
voidadd(inforPtr*sPtr,intvalue) /*使用链表添加记录*/
{
inforPtrcurrent;
inforPtrprev;
inforPtrnewList;
intc;
/*charstr[450]={0}; */
if((newList=(structinformation*)malloc(sizeof(structinformation)))!
=NULL)
{
current=*sPtr;
prev=NULL;
newList->num=value;
newList->next=NULL;
while((c=getchar())!
='\n'&&c!
=NULL); //fflush(stdin)
/* printf("%-10s%-10s%-10s%-15s%-10s%-10s%-20s%s\n","姓名","出生年月","性别","教育程度","职位","工资","住址","电话");
gets(str);
sscanf(str,"%[^0-9]%s%s%s%s%lf%s%s",newList->name,newList->birth,newList->gender,newList->education,
newList->position,&newList->wage,newList->address,newList->phone); */
printf("姓名:
\n");
scanf("%s",newList->name);
printf("\n出生年月:
\n");
scanf("%s",newList->birth);
printf("\n性别:
\n");
scanf("%s",newList->gender);
printf("\n教育程度:
\n");
scanf("%s",newList->education);
printf("\n职位:
\n");
scanf("%s",newList->position);
printf("\n工资:
\n");
scanf("%lf",&newList->wage);
printf("\n住址:
\n");
scanf("%s",newList->address);
printf("\n电话:
\n");
scanf("%s",newList->phone);
while(current!
=NULL&&value>current->num)
{
prev=current;
current=current->next;
}
if(prev==NULL)
{
newList->next=*sPtr;
*sPtr=newList;
}
else
{
newList->next=current;
prev->next=newList;
}
}
else
printf("内存已满,无法添加\n");
save(sPtr);
}
/*显示链表中数据*/
voiddisplay(inforPtrnewList)
{
fflush(stdout);
printf("\n\n************************************************************************************************************************\n\n");
printf("%-5s%-13s%-12s%-5s%-15s%-10s%-10s%-40s%s\n","工号","姓名","出生年月","性别","教育程度","职位","工资","住址","电话");
while(newList!
=NULL)
{
printf("%-5.3d%-13s%-12s%-5s%-15s%-10s%-10.2lf%-40s%s\n",newList->num,newList->name,newList->birth,newList->gender,newList->education,
newList->position,newList->wage,newList->address,newList->phone);
newList=newList->next;
}
printf("\n*************************************************************************************************************************\n\n");
}
voidquery(inforPtr*sPtr,int(*compare)(inforPtroriginal,inforPtrcreat))
{
inforPtrSPtr; //equalto*sPtr
inforPtrnewPtr; //newList
inforPtrcurrentPtr;
inforPtrprevPtr;
inforPtrheadPtr;
SPtr=*sPtr;
newPtr=NULL;
currentPtr=NULL;
prevPtr=NULL;
headPtr=NULL;
while(SPtr!
=NULL)
{
if((newPtr=(structinformation*)malloc(sizeof(structinformation)))!
=NULL)
{
prevPtr=NULL;
currentPtr=headPtr;
newPtr->next=NULL;
/*move*/
while(currentPtr!
=NULL&&(*compare)(SPtr,currentPtr))
{
prevPtr=currentPtr;
currentPtr=currentPtr->next;
}
if(prevPtr==NULL)
{
newPtr->next=headPtr;
headPtr=newPtr;
}
else
{
prevPtr->next=newPtr;
newPtr->next=currentPtr;
}
strcpy(newPtr->address,SPtr->address);
strcpy(newPtr->birth,SPtr->birth);
strcpy(newPtr->education,SPtr->education);
strcpy(newPtr->gender,SPtr->gender);
strcpy(newPtr->name,SPtr->name);
newPtr->num=SPtr->num;
strcpy(newPtr->phone,SPtr->phone);
strcpy(newPtr->position,SPtr->position);
newPtr->wage=SPtr->wage;
SPtr=SPtr->next;
}
else
printf("OUTOFMEMORY\n");
}
display(headPtr);
}
/*按照工资排序*/
intqueryByWage(inforPtroriginal,inforPtrcreat)
{
returnoriginal->wage
}
/*保存到文件*/
voidsave(inforPtr*sPtr)
{
FILE*fPtr;
inforPtrSPtr;
SPtr=*sPtr;
if((fPtr=fopen("data.dat","wb++"))!
=NULL)
{
while(SPtr!
=NULL)
{
fwrite(SPtr,sizeof(structinformation),1,fPtr);
SPtr=SPtr->next;
}
}
else
{
printf("Filecannotopen!
\n\n");
exit(0);
}
fclose(fPtr);
printf("\n*****自动保存成功!
*****\n\n");
}
voidload(inforPtr*sPtr)
{
FILE*fPtr;
infornewList;
inforPtrcurrentPtr=NULL;
inforPtrheadPtr=NULL;
inforPtrnewPtr=NULL;
inforPtrprevPtr=NULL;
intverify=-100;
struct_statverifyFile;
if((fPtr=fopen("data.dat","rb++"))==NULL)
{
if((fPtr=fopen("data.dat","wb++"))==NULL)
printf("Filecannotopen");
else
printf( "\n欢迎首次使用,本系统所有数据将自动保存!
\n" );
}
else
{
stat("data.dat",&verifyFile);
if(verifyFile.st_size!
=0)
{
headPtr=NULL;
newPtr=NULL;
currentPtr=NULL;
while(!
feof(fPtr))
{
fread(&newList,sizeof(structinformation),1,fPtr);
/* printf("%-5.3d%-10s%-10s%-10s%-15s%-10s%-10.2lf%-20s%s\n",newList.num,newList.name,newList.birth,newList.gender,newList.education,
newList.position,newList.wage,newList.address,newList.phone);
*/
if(verify!
=newList.num)
{
if((newPtr=(structinformation*)malloc(sizeof(structinformation)))!
=NULL)
{
prevPtr=NULL;
currentPtr=headPtr;
newPtr->next=NULL;
while(currentPtr!
=NULL&&newList.num>currentPtr->num)
{
prevPtr=currentPtr;
currentPtr=currentPtr->next;
}
if(prevPtr==NULL)
{
newPtr->next=headPtr;
headPtr=newPtr;
}
else
{
prevPtr->next=newPtr;
newPtr->next=currentPtr;
}
strcpy(newPtr->address,newList.address);
strcpy(newPtr->birth,newList.birth);
strcpy(newPtr->education,newList.education);
strcpy(newPtr->gender,newList.gender);
s
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 管理 系统 模板
![提示](https://static.bdocx.com/images/bang_tan.gif)