充斥着颜文字的c语言课设作业,对一根链表进行操作,使其存入文件,环境是vc6.0
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
typedef struct employee
{
int id;
char name[10];
char sex[10];
char bir[10];
char pos[10];
char study[10];
float sal;
struct employee *next;
}em;
void login()
{
char username[10];
char password[8];
int i;
system("color 3F");
printf("\n\n\n *~*~*~*~*~*~*~*~*~*~*~~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~**~*~*~*~*~*~*~*~*~*~*~\n\n");
printf(" 欢迎使用职工信息管理系统(~ ̄▽ ̄)~\n\n");
for(i=1;i<4;i++)
{
printf("\n 你的用户名:");
gets(username);
printf("\n 你的密码:");
gets(password);
if((strcmp(username,"cyx")==0)&&(strcmp(password,"123456")==0))//验证登录名和密码
{
printf("\n *~*~*~*~*~*~*~*~*~*~*~ 登陆成功,干杯![]~( ̄▽ ̄) ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ ");
system("pause");
return;
}
else{
if(i==1)
{
printf("\n 输错了嗷╰( ̄▽ ̄)╭,再来一次吧\n\n\n\n");
}
if(i==2)
{
printf("\n 又输错了,只有一次机会了o(;>△<)o\n\n\n\n");
}
if(i==3)
{
printf("\n 结束了!退群吧(〝▼皿▼)\n");
Sleep(1000);
exit(0);
}
}
}
}
int menu()
{
int a;
do
{
system("cls");
printf("\n\n\t\t----------------------职工信息管理系统----------------------\n\n");
printf("\t\t~*~*~* 1. 录入职工信息 ~*~*~*\n\n");
printf("\t\t~*~*~* 2. 阅览职工信息 ~*~*~*\n\n");
printf("\t\t~*~*~* 3. 查询职工信息 ~*~*~*\n\n");
printf("\t\t~*~*~* 4. 添加职工信息 ~*~*~*\n\n");
printf("\t\t~*~*~* 5. 删除职工信息 ~*~*~*\n\n");
printf("\t\t~*~*~* 6. 修改职工信息 ~*~*~*\n\n");
printf("\t\t~*~*~* 7. 信息写入文件 ~*~*~*\n\n");
printf("\t\t~*~*~* 8. 文件输出信息 ~*~*~*\n\n");
printf("\t\t~*~*~* 0. 退出这个系统 ~*~*~*\n\n");
printf("\t输入你想运行的选项(〃'▽'〃):");
scanf("%d",&a);
}while(a<0||a>9);
return a;
}
em *input(int n)//录入职工信息
{
int i=1;
em *l=NULL,*r=NULL,*head=NULL;
l=(em *)malloc(sizeof(em));
head=l;
printf("第1位:\n");
printf("工号:");
scanf("%d",&l->id );
printf("\n");
printf("姓名:");
scanf("%s",&l->name);
printf("\n");
printf("性别:");
scanf("%s",&l->sex);
printf("\n");
printf("生日:");
scanf("%s",&l->bir);
printf("\n");
printf("学历:");
scanf("%s",&l->study);
printf("\n");
printf("职务:");
scanf("%s",&l->pos);
printf("\n");
printf("薪水:");
scanf("%f",&l->sal);
printf("\n");
if(n>1)
{
for(i=1;i<n;i++)
{ printf("\n\n");
printf("第%d位:\n",i+1);
r=(em *)malloc(sizeof(em));
printf("工号:");
scanf("%d",&r->id );
printf("\n");
printf("姓名:");
scanf("%s",r->name);
printf("\n");
printf("性别:");
scanf("%s",r->sex);
printf("\n");
printf("生日:");
scanf("%s",r->bir);
printf("\n");
printf("学历:");
scanf("%s",r->study);
printf("\n");
printf("职务:");
scanf("%s",r->pos);
printf("\n");
printf("薪水:");
scanf("%f",&r->sal);
printf("\n");
l->next =r;
l=r;
}
}
if(i==n)
{
l->next=NULL;
}
printf("录入结束\n");
system("pause");
return head;
}
void output(em *head)//阅览职工信息
{
em *p;
p=head;
printf("\n------------------------------------------------------------\n");
printf("工号 姓名 性别 生日 学历 职务 薪水");
printf("\n------------------------------------------------------------\n");
if(head==NULL)
{
printf("\n\n 凉凉,一个人的信息都没有 \n");
}
else
{
while(p!=NULL)
{
printf("\n%-5d %-5s %-5s %-5s %-5s %-5s %-5f\n",p->id ,p->name ,p->sex ,p->bir ,p->study ,p->pos ,p->sal );
p=p->next ;
}
}
printf("\n\n即将返回主菜单\n\n\n\n\n\n");
}
//信息查找菜单
int findmenu()
{ int a;
system("cls");
printf("\t------------------------------------------------------------------------------------\n");
printf("\t\t\t1.按照工资查找");
printf("\t\t\t2.按照学历查找");
printf("\n\n请输入您的选项(按0返回主菜单):");
scanf("%d",&a);
while(a<0||a>2)
{
system("cls");
printf("\n\n\t\t\t皮这一下你很开心嘛?_(:з」∠)_\n");
printf("\n\t\t\t再输入一次吧233333\n");
printf("\t------------------------------------------------------------------------------------\n");
printf("\t\t\t1.按照工资查找");
printf("\t\t\t2.按照学历查找");
printf("\n请输入您的选项(按0返回主菜单):");
scanf("%d",&a);
}
return a;
}
int findselect(em *head,int n)
{ int k=0;
em *p;
switch(n)
{
case 1:
system("cls");
p=head;
int a;
printf("\n要查找的工资为:");
scanf("%d",&a);
printf("\n------------------------------------------------------------\n");
printf("工号 姓名 性别 生日 学历 职务 薪水");
printf("\n------------------------------------------------------------\n");
while(p!=NULL)
{
if(p->sal==a)
{
k++;
}
p=p->next ;
}
if(k==0)
{
printf("找到0人符合要求\n\n");
system("pause");
return 1;
}
else
{
printf("找到%d人符合要求",k);
p=head;
while(p!=NULL)
{
if(p->sal==a)
{
printf("\n %d %s %s %s %s %s %f\n",p->id ,p->name ,p->sex ,p->bir ,p->study ,p->pos ,p->sal );
}
p=p->next ;
}
system("pause");
return 1;
}
case 2:
system("cls");
p=head;
char b[10];
printf("\n要查找的学历为:");
scanf("%s",&b);
printf("\n------------------------------------------------------------\n");
printf("工号 姓名 性别 生日 学历 职务 薪水");
printf("\n------------------------------------------------------------\n");
while(p!=NULL)
{
if(strcmp(p->pos,b) ==0)
{
k++;
}
p=p->next ;
}
if(k==0)
{
printf("找到0人符合要求\n\n");
system("pause");
return 2;
}
else
{
printf("找到%d人符合要求",k);
p=head;
while(p!=NULL)
{
if(strcmp(p->pos,b) ==0)
{
printf("\n %d %s %s %s %s %s %f\n",p->id ,p->name ,p->sex ,p->bir ,p->study ,p->pos ,p->sal );
}
p=p->next;
}
system("pause");
return 2;
}
}
}
//职工信息添加
void add(em *head)
{
em *p,*pnew;
p=head;
pnew=(em*)malloc(sizeof(em));
printf("\t\t工号:");
scanf("%d",&pnew->id );
printf("\n\t\t姓名:");
scanf("%s",&pnew->name );
printf("\n\t\t性别:");
scanf("%s",&pnew->sex );
printf("\n\t\t生日:");
scanf("%s",&pnew->bir );
printf("\n\t\t学历:");
scanf("%s",&pnew->study );
printf("\n\t\t职务:");
scanf("%s",&pnew->pos );
printf("\n\t\t薪水:");
scanf("%f",&pnew->sal );
while(p->next!=NULL)
{
p=p->next;
}
p->next =pnew;
pnew->next=NULL;
}
//信息删除
em *del(em **head)
{
int x,y;
if(head==NULL)
{
printf("\n\n凉凉,一个人的信息都没有,删不了啊(;′д`)ゞ\n\n");
return *head;
}
printf("1.删除某个职工信息\n\n");
printf("2.删除所有职工信息\n\n");
printf("(~ ̄▽ ̄)~ 你的选项是:");
scanf("%d",&x);
if(x==1)
{
printf("\n\t\t请输入将要删除的职工位置:");
scanf("%d",&y);
if(y==1)
{
*head=(*head)->next;
}
else
{ em *p,*q;
int i;
p=*head;
for(i=2;i<y&&p->next !=NULL;i++)
{
p=p->next;
}
q=p->next ;
p->next =q->next ;
}
printf("\n\t\t(* ̄︶ ̄)删除成功!\n");
return *head;
}
else if(x==2)
{
*head=NULL;
printf("\n已将所有人移除系统(* ̄︶ ̄)");
return *head;
}
else
{
printf("输入错误,即将返回主菜单\n");
return NULL;
}
}
//信息修改
int correct(em *head)
{
int a;
em *p;
p=head;
if(head==NULL)
{
printf("\n\n凉凉,一个人的信息都没有,改不了啊(;′д`)ゞ\n\n");
return 0;
}
else
{ printf("\n\t\t\t请输入将要修改的职工工号:");
scanf("%d",&a);
while(p!=NULL)
{
if(a==p->id)
{
printf("\n\t\t修改后的工号:");
scanf("%d",&p->id );
printf("\n\t\t修改后的姓名:");
scanf("%s",&p->name );
printf("\n\t\t修改后的性别:");
scanf("%s",&p->sex );
printf("\n\t\t修改后的生日:");
scanf("%s",&p->bir );
printf("\n\t\t修改后的学历:");
scanf("%s",&p->study );
printf("\n\t\t修改后的职务:");
scanf("%s",&p->pos );
printf("\n\t\t修改后的薪水:");
scanf("%f",&p->sal );
}
p=p->next ;
}
return 1;
}
}
int write(em* head)
{
FILE *fp;
if((fp=fopen("WIS.txt","w+"))==NULL)
{
printf("文件打开失败Σ(っ°Д°;)っ\n");
return 0;
}
else
{
em *p;
p=head;
while(p!=NULL)
{
fprintf(fp,"%d\t",p->id);
fprintf(fp,"%s\t",p->name);
fprintf(fp,"%s\t",p->sex );
fprintf(fp,"%s\t",p->bir );
fprintf(fp,"%s\t",p->study);
fprintf(fp,"%s\t",p->pos);
fprintf(fp,"%lf\n",p->sal);
p=p->next;
}
fclose(fp);
return 1;
}
}
int read()
{
int id;
char name[15];
char sex[10];
char bir[15];
char pos[10];
char study[10];
float sal;
FILE*fp;
printf("\n------------------------------------------------------------\n");
printf("工号 姓名 性别 生日 学历 职务 薪水\n");
printf("------------------------------------------------------------\n");
fp=fopen("WIS.txt","r");
while(fscanf(fp,"%d\t%s\t%s\t%s\t%s\t%s\t%f\n",&id,name,sex,bir,study,pos,&sal)!=EOF)
{
printf("%d\t%s\t%s\t%s\t%s\t%s\t%f\n",id,name,sex,bir,study,pos,sal);
}
return 1;
}
int main()
{
int n,y;
login();
em *head=NULL;
for(;;)
{
switch(menu())
{
case 1:
system("cls");
printf("\n------------------------------------------------------------\n");
printf("输入职工的个数:");
scanf("%d",&n);
if(n<=0)
{
printf("\n请输入正确的人数(〝▼皿▼)\n(即将返回主菜单。。。)");
system("pause");
break;
}
else
{
printf("\n请开始输入学生数据( ̄▽ ̄)~*:\n\n");
head=input(n);
break;
}
case 2:
system("cls");
printf("显示职工数据:");
output(head);
system("pause");
break;
case 3:
system("cls");
do
{
y=findselect(head,findmenu());
}while(y!=0);
break;
case 4:
system("cls");
printf("\n------------------------------------------------------------\n");
add(head);
printf("\n添加成功!\n");
system("pause");
break;
case 5://删除操作
system("cls");
printf("\n------------------------------------------------------------\n");
del(&head);
system("pause");
break;
case 6:
system("cls");
printf("\n------------------------------------------------------------\n");
if(correct(head)==1)
{
printf("\n\n修改成功!");
}
else
{
printf("修改失败!");
}
system("pause");
break;
case 7:
system("cls");
if(write(head)==1)
printf("写入成功!");
else
printf("写入失败!");
system("pause");
break;
case 8:
system("cls");
if(read()==1)
printf("读取成功!");
else
printf("读取失败!");
system("pause");
break;
case 0:
printf("\n\n ------------------------ 山水有相逢,后会有期( ̄▽ ̄)/ ------------------------\n");
exit(0);
}
}
return 0;
}