📄 app1.cpp
字号:
printf("所添加的用户口令(1-20个字符):");
scanf("%s",Append_sPWD);
printf("所添加的用户权限(Administrator/Operator/Guest:");
scanf("%s",Append_Potency);
if( isUserExisted(Append_sID)==1 )
{
strcpy(Append_pLNode->UserID,Append_sID);
strcpy(Append_pLNode->UserPWD,Append_sPWD);
strcpy(Append_pLNode->Potency,Append_Potency);
Append_pLNode->next=NULL;
//添加到用户信息对象表
if( pMyUserList!=NULL)
{
Append_pLNode->next=pMyUserList->head->next;
pMyUserList->head->next=Append_pLNode;
}
else
{
printf("对象信息表不存在!!\n");
ErrorReport("AppendUser","对象信息表不存在!!");
exit(0);
}
FILE *fp;
if( (fp=fopen("UserInfo.dat","a"))!=NULL ) //打开用户信息表文件
{
fwrite(Append_pLNode,sizeof(UserNode)-4,1,fp);
fclose(fp);
}
else
{
printf("不能打开UserInfo.dat!!\n");
ErrorReport("AppendUser","不能打开UserInfo.dat文件!!");
exit(0);
}
printf("已成功添加该用户!!\n");
}
}
//修改用户口令模块
int ModifyPWD()
{
UserNode *Modify_pNode=pMyUserList->head->next;
char Modify_sID[20],Modify_sPWD[20];
printf("请输入需要修改口令的用户名:");
scanf("%s",Modify_sID);
printf("请输入新的口令:");
scanf("%s",Modify_sPWD);
//扫描用户信息表查找相符合的用户名:
while( Modify_pNode!=NULL && ( strcmp(Modify_pNode->UserID,Modify_sID)!=0 ) )
Modify_pNode=Modify_pNode->next;
//若Modify_pNode==NULL 则
if( Modify_pNode==NULL )
{
printf("没有该用户的信息!!\n");
return 0;
}
else
{
strcpy(Modify_pNode->UserPWD,Modify_sPWD);
printf("该用户口令已经更改!!\n");
//更新文件
Modify_pNode=pMyUserList->head->next;
FILE *fp;
if( (fp=fopen("UserInfo.dat","w"))!=NULL ) //打开用户信息表文件
{
while( Modify_pNode!=NULL )
{
fwrite(Modify_pNode,sizeof(UserNode)-4,1,fp);
Modify_pNode=Modify_pNode->next;
}
free(Modify_pNode);
fclose(fp);
}
return 1;
}
}
//删除用户信息
int DelUserInfo()
{
UserNode *Del_pNode=pMyUserList->head->next,*Del_pPreNode=pMyUserList->head;
char Del_sID[20];
printf("请输入需要删除的用户名:");
scanf("%s",Del_sID);
//扫描用户信息表查找相符合的用户名:
while( Del_pNode!=NULL && ( strcmp(Del_pNode->UserID,Del_sID)!=0 ) )
{
Del_pPreNode=Del_pNode;
Del_pNode=Del_pNode->next;
}
//若Del_pNode==NULL 则
if( Del_pNode==NULL )
{
printf("没有该用户的信息!!\n");
return 0;
}
else
{
//从链表中删除该用户
Del_pPreNode->next=Del_pNode->next;
//重新写入用户信息文件
Del_pNode=pMyUserList->head->next;
FILE *fp;
if( (fp=fopen("UserInfo.dat","w"))!=NULL ) //打开用户信息表文件
{
while( Del_pNode!=NULL )
{
fwrite(Del_pNode,sizeof(UserNode)-4,1,fp);
Del_pNode=Del_pNode->next;
}
free(Del_pNode);
fclose(fp);
}
printf("该用户信息已经删除!!\n");
return 1;
}
}
//显示用户信息模块
void DispUserInfo()
{
UserNode *Disp_pCurrentNode=pMyUserList->head->next;
printf("UserID\t\tUserPWD\t\t\t\tUserPotency\n\n");
while( Disp_pCurrentNode!=NULL)
{
printf("%s\t\t",Disp_pCurrentNode->UserID);
printf("%s\t\t\t\t",Disp_pCurrentNode->UserPWD );
printf("%s\n",Disp_pCurrentNode->Potency );
Disp_pCurrentNode=Disp_pCurrentNode->next;
}
}
//编码控制模块
void CodeControl()
{
//iFlag为循环控制变量,iFunItem为操作识别变量
int iFunItem,iFlag=1;
while(iFlag==1)
{
printf("选择编码表;\n");
printf("1)性别编码表;\n");
printf("2)教育情况编码表;\n");
printf("3)最后毕业学校编码表;\n");
printf("0)退出;\n");
printf("请选择操作:");
scanf("%d",&iFunItem);
switch(iFunItem)
{
case 1:
{
SexCodeManagement();
}
break;
case 2:
{
EStatusCodeManagement();
}
break;
case 3:
{
LastSchoolCodeManagement();
}
break;
case 0:
{
iFlag=0;
}
break;
default:
{
printf("错误的操作选择!!!\n");
ErrorReport("CodeControl","选择错误!!");
}
break;
}
}
}
//性别编码管理
void SexCodeManagement()
{
//iFlag为循环控制变量,iFunItem为操作识别变量
int iFunItem,iFlag=1;
while(iFlag==1)
{
printf("1)检索性别编码表;\n");
printf("2)添加性别编码;\n");
printf("3)修改性别编码;\n");
printf("4)删除性别编码;\n");
printf("5)显示性别编码表;\n");
printf("0)退出;\n");
printf("请选择操作:");
scanf("%d",&iFunItem);
switch(iFunItem)
{
case 1:
{
FindSexCode();
}
break;
case 2:
{
AppendSexCode();
}
break;
case 3:
{
ModifySexCode();
}
break;
case 4:
{
DelSexCode();
}
break;
case 5:
{
DispSexCode();
}
break;
case 0:
{
iFlag=0;
}
break;
default:
{
printf("错误的操作选择!!!\n");
ErrorReport("CodeControl","选择错误!!");
}
break;
}
}
}
//检索性别编码表
void FindSexCode()
{
SexNode *Fsc_pNode=pMySexList->head->next;
char Fsc_sSexCode[4];
if( pMySexList->head->next==NULL )
{
printf("当前性别编码表中数据为空!\n");
}
else
{
printf("请输入需要检索的编码(1-4个字符):");
scanf("%s",Fsc_sSexCode);
while( Fsc_pNode!=NULL && strcmp(Fsc_pNode->sSexCode,Fsc_sSexCode)!=0 )
Fsc_pNode=Fsc_pNode->next;
if( Fsc_pNode==NULL )
{
printf("没有对应的编码!\n");
}
else
{
printf("对应编码\t\t\t\t性别\n");
printf("%s\t\t\t\t\t%s\n",Fsc_pNode->sSexCode,Fsc_pNode->sSex);
}
}
}
//判断性别编码是否重复
int isSexCodeExisted(char *sSex)
{
SexNode *pNode;
if( pMySexList->head->next!=NULL )
{
pNode=pMySexList->head->next;
while( pNode!=NULL && strcmp(pNode->sSex,sSex)!=0 )
pNode=pNode->next;
if( pNode==NULL )
return 1;
else
{
printf("该编码信息已经存在!!\n");
return 0;
}
}
else
return 1;
}
//添加性别编码
void AppendSexCode()
{
SexNode *Asc_pNode;
char Asc_sSex[4];
char Asc_sSexCode[4];
//判断当前编码表对象是否存在
if( pMySexList->head==NULL )
{
printf("当前性别编码表为空!\n");
}
else
{
printf("请输入性别(男/女):");
scanf("%s",Asc_sSex);
printf("请输入性别编码:(1-2个字符):");
scanf("%s",Asc_sSexCode);
printf("OK %s\t\t\t%s\n",Asc_sSex,Asc_sSexCode);
if( isSexCodeExisted(Asc_sSex)==1 )
{
//将新的性别编码添加到链表
Asc_pNode=(SexNode*)malloc(sizeof(SexNode));
if( Asc_pNode==NULL )
{
printf("Memory assign fail\n");
ErrorReport("AppendSexCode","Memory assign fail");
}
else
{
strcpy(Asc_pNode->sSex,Asc_sSex);
printf("OK %s\t\t\t\n",Asc_pNode->sSex);
strcpy(Asc_pNode->sSexCode,Asc_sSexCode);
printf("OK %s\t\t\t%s\n",Asc_pNode->sSex,Asc_pNode->sSexCode);
Asc_pNode->next=pMySexList->head->next;
pMySexList->head->next=Asc_pNode;
}
//将新的性别编码表重新写入Sex.Dat文件
FILE *fp;
if( (fp=fopen("Sex.dat","a"))!=NULL ) //打开性别编码表文件
{
fwrite(Asc_pNode,sizeof(SexNode)-4,1,fp);
fclose(fp);
}
else
{
printf("不能打开Sex.dat!!\n");
ErrorReport("AppendSexCode","不能打开Sex.dat文件!!");
exit(0);
}
printf("已成功添加此编码!!\n");
}
}
}
//修改性别编码
void ModifySexCode()
{
SexNode *Msc_pNode=pMySexList->head->next;
char Msc_sSex[2];
char Msc_sSexCode[4];
printf("请输入需要修改编码的性别:");
scanf("%s",Msc_sSex);
printf("请输入新的编码:");
scanf("%s",&Msc_sSexCode);
//扫描用户信息表查找相符合的用户名:
while( Msc_pNode!=NULL && ( strcmp(Msc_pNode->sSex,Msc_sSex)!=0 ) )
Msc_pNode=Msc_pNode->next;
//若Msc_pNode==NULL 则
if( Msc_pNode==NULL )
{
printf("没有该编码的信息!!\n");
}
else
{
strcpy(Msc_pNode->sSexCode,Msc_sSexCode);
printf("该性别编码已经更改!!\n");
//更新文件
Msc_pNode=pMySexList->head->next;
FILE *fp;
if( (fp=fopen("Sex.dat","w"))!=NULL ) //打开用户信息表文件
{
while( Msc_pNode!=NULL )
{
fwrite(Msc_pNode,sizeof(SexNode)-4,1,fp);
Msc_pNode=Msc_pNode->next;
}
free(Msc_pNode);
fclose(fp);
}
}
}
//删除性别编码
void DelSexCode()
{
SexNode *Dsc_pNode=pMySexList->head->next;
SexNode *Dsc_pPreNode=pMySexList->head;
char Dsc_sSexCode[4];
printf("请输入需要删除的性别编码(1-4个字符):");
scanf("%s",Dsc_sSexCode);
//扫描用户信息表查找相符合的用户名:
while( Dsc_pNode!=NULL && ( strcmp(Dsc_pNode->sSexCode,Dsc_sSexCode)!=0 ) )
{
Dsc_pPreNode=Dsc_pNode;
Dsc_pNode=Dsc_pNode->next;
}
//若Del_pNode==NULL 则
if(Dsc_pNode==NULL )
{
printf("没有该编码的信息!!\n");
}
else
{
//从链表中删除该用户
Dsc_pPreNode->next=Dsc_pNode->next;
//重新写入用户信息文件
Dsc_pNode=pMySexList->head->next;
FILE *fp;
if( (fp=fopen("Sex.dat","w"))!=NULL ) //打开用户信息表文件
{
while( Dsc_pNode!=NULL )
{
fwrite(Dsc_pNode,sizeof(SexNode)-4,1,fp);
Dsc_pNode=Dsc_pNode->next;
}
free(Dsc_pNode);
fclose(fp);
}
printf("该编码信息已经删除!!\n");
}
}
//显示性别编码表
void DispSexCode()
{
SexNode *Disc_pCurrentNode=pMySexList->head->next;
printf("对应编码\t\t\t性别\n");
while( Disc_pCurrentNode!=NULL)
{
printf("%s\t\t\t\t",Disc_pCurrentNode->sSexCode );
printf("%s\n",Disc_pCurrentNode->sSex );
Disc_pCurrentNode=Disc_pCurrentNode->next;
}
}
//教育状况编码编码管理
void EStatusCodeManagement()
{
//iFlag为循环控制变量,iFunItem为操作识别变量
int iFunItem,iFlag=1;
while(iFlag==1)
{
printf("1)检索教育状况编码表;\n");
printf("2)添加教育状况编码;\n");
printf("3)修改教育状况编码;\n");
printf("4)删除教育状况编码;\n");
printf("5)显示教育状况编码表;\n");
printf("0)退出;\n");
printf("请选择操作:");
scanf("%d",&iFunItem);
switch(iFunItem)
{
case 1:
{
FindEStatusCode();
}
break;
case 2:
{
AppendEStatusCode();
}
break;
case 3:
{
ModifyEStatusCode();
}
break;
case 4:
{
DelEStatusCode();
}
break;
case 5:
{
DispEStatusCode();
}
break;
case 0:
{
iFlag=0;
}
break;
default:
{
printf("错误的操作选择!!!\n");
ErrorReport("CodeControl","选择错误!!");
}
break;
}
}
}
//判断教育状况编码是否重复
int isEStatusCodeExisted(char *sEStatus)
{
EStatusNode *pNode;
if( pMyEStatusList->head->next!=NULL )
{
pNode=pMyEStatusList->head->next;
while( pNode!=NULL && strcmp(pNode->sEStatus,sEStatus)!=0 )
pNode=pNode->next;
if( pNode==NULL )
return 1;
else
{
printf("该编码信息已经存在!!\n");
return 0;
}
}
else
return 1;
}
//检索教育状况编码表
void FindEStatusCode()
{
EStatusNode *Fec_pNode=pMyEStatusList->head->next;
char Fec_sEStatusCode[5];
if( pMyEStatusList->head->next==NULL )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -