Ⅰ 用 c语言 编写 综合实验 职工信息管理系统
# include <iostream>
# include <fstream>
# include <string>
# include <iomanip>
# include <stdlib.h>
using namespace std;
struct worker_inf
{
int month; //月份
int code; //工人编号
string name; //姓名
float get[4]; //基本工资,津贴,房帖,交通补贴
float pay[4]; //房租,储蓄,交通费,会费
float tax; //个人所得税
float theory_num; //应发书
float rece_num; //应扣数
float practice_num; //实发数
worker_inf *next;
};
/////////////////////////////////////////////////////////////////
class worker //定义职工类
{
private:
worker_inf *head;
void print(worker_inf *); //输出一条指定职工的工资记录,并返回该记录的指针
worker_inf *find(int); //查找条例条件的记录,并返回该记录的指针
public:
worker(){head=NULL;}
worker_inf *get_head(){return head;}
int listcount(); //统计当前链表的记录总数,并返回一个整数
void additem(int month,int code,string name,float get[4],float pay[4]); //添加一条工资记录表尾
void removeitem(int); //删除一条指定职工的工资记录
int menu(); //修改某职工工资的菜单
void changemonth(); //修改月份
void changeitem(int); //修改职工的工资信息
void list(); //输出当月全体职工的工资信息
void search(int); //输出指定编号职工的工资信息
float tax_num(); //计算职工个人所得税
float theorynumber(); //计算应发工资
float recenumber(); //计算应扣工资
float practicenumber(); //计算实发工资
};
//////////////////////////////////////////////////////////////////
int worker::listcount() //统计当前链表数,并返回一个整数
{
if(!head)return 0;
worker_inf *p=head;
int n=0;
while(p)
{n++;p=p->next;}
return n;
}
//////////////////////////////////////////////////////////////////
void worker::additem(int month,int code,string name,float get[4],float pay[4]) //添加一条工资记录到表尾
{
if(!head)
{
head=new worker_inf;
for(int i=0;i<4;i++)
{
head->get[i]=get[i];
head->pay[i]=pay[i];
}
head->code=code;
head->month=month;
head->name=name;
head->next=NULL;
return;
}
worker_inf *t=head;
while(t && t->code!=code)
t=t->next;
if(t)
{
cout<<"操作失败:编号为"<<code<<"的记录已经存在!"<<endl;
return;
}
worker_inf *p=head;
while(p->next)p=p->next;
worker_inf *p1=new worker_inf;
p1->code=code;
for(int i=0;i<4;i++)
{
p1->get[i]=get[i];
p1->pay[i]=pay[i];
}
p1->code=code;
p1->month=month;
p1->name=name;
p1->next=NULL;
p->next=p1;
return;
}
////////////////////////////////////////////////////////////////////
void worker::removeitem(int code) //删除一条指定职工的工资记录
{
worker_inf *t=find(code);
if(!t)return;
worker_inf *p=head;//如果要删除的记录位于表头
if(head==t)
{
head=head->next;
delete p;
cout<<"成功删除编号为"<<code<<"的记录!"<<endl<<endl;
return;
}
while(p->next!=t)p=p->next;
worker_inf *p1=p->next;
p->next=p1->next;
delete p1;
cout<<"成功删除编号为"<<code<<"的记录!"<<endl<<endl;
return;
}
////////////////////////////////////////////////////////////////
int worker::menu() //修改某一职工信息的菜单
{
int select=-1;
cout<<"\t\t\t\t\t\t**************修改菜单**************"<<endl<<endl;
cout<<"1.基本工资"<<endl<<endl;
cout<<"2.津贴"<<endl<<endl;
cout<<"3.房帖"<<endl<<endl;
cout<<"4.交通补贴"<<endl<<endl;
cout<<"5.房租"<<endl<<endl;
cout<<"6.储蓄"<<endl<<endl;
cout<<"7.交通费"<<endl<<endl;
cout<<"8.会费"<<endl<<endl;
cout<<"0.退出修改系统"<<endl<<endl;
cout<<"[请选择(输入相应数字)]:";
cin>>select;
if(select<0||select>9)
{
cout<<"对不起您输入错误!请重新输入【0-9】:"<<endl;
cin>>select;
}
return select;
}
/////////////////////////////////////////////////////////////////
int menu();
void worker::changeitem(int code) //修改某职工部分工资信息
{
worker_inf *p=find(code);
if(!p){cout<<"不存在职工编号为"<<code<<"的职工工资信息"<<endl;return;}
int select;
while(1)
{
float m;
select=menu();
if(select==0){system("cls");break;}
cout<<"请输入修改后的值";
cin>>m;
int n;
if(select<=4){
n=select-1;
p->get[n]=m;}
else{
n=select-5;
p->pay[n]=m;}
tax_num();
theorynumber();
recenumber();
practicenumber();
cout<<"修改成功"<<endl;
}
}
////////////////////////////////////////////////////////////////////
void worker::changemonth() //修改月份
{
worker_inf *p=head;
while(p)
{
if(p->month==12)p->month=1;
else
p->month++;
p=p->next;
}
}
//////////////////////////////////////////////////////////////////////
void worker::print(worker_inf *p)//输出worker_inf制定的记录
{
cout.precision(0);
cout<<p->month<<" ";
cout<<p->code<<" ";
cout<<p->name<<"\t";
for(int i=0;i<4;i++)
{cout<<setiosflags(ios::fixed)<<p->get[i]<<"\t";}
for(int j=0;j<4;j++)
{cout<<p->pay[j]<<"\t";}
cout<<p->tax<<"\t";
cout<<p->theory_num<<"\t";
cout<<p->rece_num<<"\t";
cout<<p->practice_num<<endl<<endl;
return;
}
///////////////////////////////////////////////////////////////////////
void worker::list() //列出当前链表中的所有记录
{
if(listcount==0)
{
cout<<"错误:当前的列表为空!"<<endl;
return;
}
worker_inf *p=head;
cout<<"共有记录:"<<listcount()<<endl;
cout<<"月份\t编号\t姓名\t基本工资\t津贴\t房帖\t交通补贴\t房租\t储蓄\t交通费\t会费\t个人所得税\t应发工资\t应扣工资\t实际工资"<<endl;
while(p)
{
print(p);
p=p->next;
}
cout<<endl;
return;
}
/////////////////////////////////////////////////////////////////////////
void worker::search(int code) //在当前链表查找指定记录并输出
{
cout<<"searching....."<<endl;
worker_inf *p=find(code);
if(p)
{
cout<<"月份\t编号\t姓名\t基本工资\t津贴\t房帖\t交通补贴\t房租\t储蓄\t交通费\t会费\t个人所得税\t应发工资\t应扣工资\t实际工资"<<endl;
print(p);
}
cout<<endl;
}
//////////////////////////////////////////////////////////////////////////
worker_inf *worker::find(int code) //查找条例条件的记录,并返回该指针
{
if(listcount==0)
{
cout<<"错误:当前列表为空!"<<endl;
return NULL;
}
worker_inf *p=head;
while(p)
{
if(p->code==code)break;
p=p->next;
}
if(!p)
{
cout<<"错误:找不到该记录!\n";
return NULL;
}
return p;
}
//////////////////////////////////////////////////////////////////////////
float worker::theorynumber() //计算应发数
{
int i;
if(listcount()==0)
{
cout<<"错误:当前的列表为空!"<<endl;
return -1;
}
float sum;
worker_inf *p=head;
while(p)
{
sum=0;
for(i=0;i<4;i++)
sum+=p->get[i];
p->theory_num=sum;
p=p->next;
}
return 0;
}
//////////////////////////////////////////////////////////////////
float worker::tax_num() //计算个人所得税
{
if(listcount==0)
{
cout<<"错误:当前的列表为空!"<<endl;
return -1;
}
worker_inf *p=head;
while(p)
{
float s;
s=p->theory_num;
if(s<=800)
p->theory_num=0;
else if(s<=2000) p->theory_num=(s-800)*0.05;
else if(s<=5000)
p->theory_num=(s-2000)*0.1+60;
else p->theory_num=(s-5000)*0.2+360;
p=p->next;
}
return 0;
}
///////////////////////////////////////////////////////////////////////
float worker::recenumber() //计算应扣数
{
int i;
if(listcount==0)
{
cout<<"错误:当前的列表为空!"<<endl;
}
float sum;
worker_inf *p=head;
while(p)
{
sum=0;
for(i=0;i<4;i++)
sum+=p->pay[i];
p->rece_num=p->tax+sum;
p=p->next;
}
return 0;
}
/////////////////////////////////////////////////////////////////////////
float worker::practicenumber() //计算实发数
{
if(listcount()==0)
{
cout<<"错误:当前的列表为空!"<<endl;
return -1;
}
worker_inf *p=head;
while(p)
{
float a,b;
a=p->theory_num;
b=p->rece_num;
p->practice_num=a-b;
p=p->next;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////
worker worker; //定义全局变量
int menu()
{
int select=-1;
cout<<"*****************主菜单***********************"<<endl<<endl;
cout<<"1.添加职工信息;"<<endl<<endl;
cout<<"2.删除职工信息;"<<endl<<endl;
cout<<"3.修改职工的工资信息;"<<endl<<endl;
cout<<"4.按职工编号查找记录;"<<endl<<endl;
cout<<"5.列出所有记录;"<<endl<<endl;
cout<<"6.从数据文件导入当月工资信息;"<<endl<<endl;
cout<<"7.将当月工资信息导出到磁盘文件;"<<endl<<endl;
cout<<"0.安全退出系统;"<<endl<<endl;
cout<<"[请选择(输入相应的数字)]:";
cin>>select;
return select;
}
/////////////////////////////////////////////////////////////////////////////
char exit()
{
char s;
cout<<"确定要退出程序吗?[Y/N]:";
cin>>s;
return s;
}
//////////////////////////////////////////////////////////////////////////////
void input(int *month,int*code,string *name,float get[4],float pay[4]) //输入职工信息
{
cout<<"请输入月份 编号 姓名 基本工资 津贴 房帖 交通补贴 房租 储蓄 交通费 会费:"<<endl;
cin>>*month;
cin>>*code;
if(*code==-1)return;
cin>>*name>>get[0]>>get[1]>>get[2]>>get[3]>>pay[0]>>pay[1]>>pay[2]>>pay[3];
return;
}
///////////////////////////////////////////////////////////////////////////////
void addnew() //增加记录
{
int month=0,code=0;float get[4]={0},pay[4]={0};
string name="";
cout<<endl<<"当输入的职工编号为-1时表示输入结束。"<<endl;
input(&month,&code,&name,get,pay);
while(code!=-1)
{
worker.additem(month,code,name,get,pay);
worker.tax_num();
worker.theorynumber();
worker.recenumber();
worker.practicenumber();
input(&month,&code,&name,get,pay);
}
return;
}
////////////////////////////////////////////////////////////////////////////////
void dofind() //按职工编号查找
{
int code;
cout<<endl<<"当输入的编号为-1时表示结束输入."<<endl;
do
{
cout<<"请输入要查找的职工的编号:";
cin>>code;
if(code==-1)continue;
worker.search(code);
}while(code!=-1);
return;
}
/////////////////////////////////////////////////////////////////////////////////
void dodelete() //删除职工信息
{
cout<<endl<<"当输入的编号为-1时表示输入结束."<<endl;
int code;
do
{
cout<<"请输入要删除的职工的编号:";
cin>>code;
if(code==-1)continue;
worker.removeitem(code);
}while(code!=-1);
return;
}
///////////////////////////////////////////////////////////////////////////////////
void domodify() //修改职工信息
{
int code;
cout<<"当输入职工编号为-1时表示结束修改"<<endl;
while(1){
cout<<"请输入所需修改职工编号";
cin>>code;
if(code==-1)return;
else
worker.changeitem(code);
}
return;
}
///////////////////////////////////////////////////////////////////////////////////
void SaveFilethism()//将当月工资信息写入文件
{
worker_inf *p;
char name[20];
fstream iofile;
int i=0;
iofile.open("Worker_5th.dat",ios::out|ios::binary);
if(!iofile)
{
cerr<<"open error!"<<endl;
abort();
}
p=worker.get_head();
while(p)
{
p->name.(name,20,0);
name[p->name.length()]=0;
iofile.write((char *) &p->code,sizeof(int));
iofile.write((char *) &p->month,sizeof(int));
iofile.write((char *) name,20);
for(int i=0;i<4;i++)
{
iofile.write((char *) &p->get[i],sizeof(float));
}
for(int j=0;j<4;j++)
{
iofile.write((char *) &p->pay[j],sizeof(float));
}
p=p->next;
}
iofile.close();
cout<<"成功将工资信息存入文件"<<endl;
}
////////////////////////////////////////////////////////////////////////
void Loadfilethism() //读取当月全体职工的工资信息文件
{
int month,code;
char name[20]="";
float get[4],pay[4];
fstream iofile;
int i=0;
iofile.open("Worker_5th.dat",ios::in|ios::binary);
if(!iofile)
{
cout<<"数据文件不存在,请先建立该文件"<<endl;
return;
}
if(iofile.eof())
{
cout<<"数据库为空,请先添加数据"<<endl;
iofile.close();
}
else
{
while(iofile.peek()!=EOF)//peek()是取文件当前指针,EOF是文件尾标符
{
iofile.read((char *) &code,sizeof(int));
iofile.read((char *) &month,sizeof(int));
iofile.read((char *) name,20);
for(int i=0;i<4;i++)
{
iofile.read((char *) &get[i],sizeof(float));
} for(int j=0;j<4;j++)
{
iofile.read((char *) &pay[j],sizeof(float));
}
worker.additem(code,month,name,get,pay);
}
worker.tax_num();
worker.theorynumber();
worker.recenumber();
worker.practicenumber();
iofile.close();
cout<<"成功导入工资信息"<<endl;
}
}
/////////////////////////////////////////////////////////////////////////
void list()
{
worker.list();
}
/////////////////////////////////////////////////////////////////////////
int main()
{
cout<<"******************欢迎进入职工工资管理系统*******************"<<endl<<endl;
int select;
char s;
while(1)
{
select=menu();
switch(select)
{
case 0: //退出程序
s=exit();
if(s=='y'||s=='Y') return 0;
break;
case 1: //增加新记录
addnew();
break;
case 2: //删除记录
dodelete();
break;
case 3: //修改记录
domodify();
break;
case 4: //按条件查找
dofind();
break;
case 5: //列出全部记录
list();
break;
case 6: //导入当月职工记录
Loadfilethism();
break;
case 7: //将职工记录存入磁盘
SaveFilethism();
break;
default:
cout<<"此输入无效!"<<endl;
}
}
return 0;
}
Ⅱ 员工信息管理系统,C语言做
以下是我的程序,刚编好的,刚好符合你的要求,看看吧,对你应该有帮助:
呵呵
#include
#include
#include
#include
#define N 100
struct employee
{
int num;
char name[10];
char sex;
int age;
char xueli[30];
int wage;
char addr[30];
long int tel;
}em[100]; /*定义一个结构体*/
void menu();
void input();
void save(int);
void display();
void del();
void add();
void search();
void search_num();
void search_xueli();
void search_tel();
void modify(); /*定义各函数*/
void menu() /*菜单函数*/
{
printf(" ☆☆☆计算机科学与技术学系☆☆☆\n");
printf("\n");
printf(" ∮08802班 关丽霞∮\n");
printf("\n");
printf(" ******************职工信息管理****************\n");
printf(" 1.录入职工信息");
printf(" 2.浏览职工信息\n");
printf(" 3.查询职工信息");
printf(" 4.删除职工信息\n");
printf(" 5.添加职工信息");
printf(" 6.修改职工信息\n");
printf(" 7.退出\n");
printf(" ********************谢谢使用******************\n");
printf("\n");
printf("\n");
}
void main()
{
menu(); /*调用菜单函数*/
int n,flag;
char a;
do
{
printf("请选择你需要操作的步骤(1--7):\n");
scanf("%d",&n);
if(n>=1&&n<=7)
{
flag=1;
break;
}
else
{
flag=0;
printf("您输入有误,请重新选择!");
}
}
while(flag==0);
while(flag==1)
{
switch(n)
{
case 1:printf(" ◆◆◆输入职工信息◆◆◆\n");printf("\n");input();break;
case 2:printf(" ◆◆◆浏览职工信息◆◆◆\n");printf("\n");display();break;
case 3:printf(" ◆◆◆按职工号查询职工信息◆◆◆\n");printf("\n");search();break;
case 4:printf(" ◆◆◆删除职工信息◆◆◆\n");printf("\n");del();break;
case 5:printf(" ◆◆◆添加职工信息◆◆◆\n");printf("\n");add();break;
case 6:printf(" ◆◆◆修改职工信息◆◆◆\n");printf("\n");modify();break;
case 7:exit(0);break;
default :break;
}
getchar();
printf("\n");
printf("是否继续进行(y or n):\n");
scanf("%c",&a);
if(a=='y')
{
flag=1;
system("cls"); /*清屏*/
menu(); /*调用菜单函数*/
printf("请再次选择你需要操作的步骤(1--6):\n");
scanf("%d",&n);
printf("\n");
}
else
exit(0);
}
}
void input() /*录入函数*/
{
int i,m;
printf("请输入需要创建信息的职工人数(1--100):\n");
scanf("%d",&m);
for (i=0;i<m;i++)
{
printf("职工号: ");
srand((int)time(0));
em[i].num=rand()%10000+20000000;
if(em[i].num!=em[i-1].num)
printf("%8d ",em[i].num);
printf("\n");
printf("请输入姓名: ");
scanf("%s",em[i].name);
getchar();
printf("请输入性别(f--女 m--男): ");
scanf("%c",&em[i].sex);
printf("请输入年龄: ");
scanf("%d",&em[i].age);
printf("请输入学历: ");
scanf("%s",em[i].xueli);
printf("请输入工资: ");
scanf("%d",&em[i].wage);
printf("请输入住址: ");
scanf("%s",em[i].addr);
printf("请输入电话: ");
scanf("%d",&em[i].tel);
printf("\n");
}
printf("\n创建完毕!\n");
save(m);
}
void save(int m) /*保存文件函数*/
{
int i;
FILE*fp;
if ((fp=fopen("employee_list","wb"))==NULL) /*创建文件并判断是否能打开*/
{
printf ("cannot open file\n");
exit(0);
}
for (i=0;i<m;i++) /*将内存中职工的信息输出到磁盘文件中去*/
if (fwrite(&em[i],sizeof(struct employee),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
int load() /*导入函数*/
{
FILE*fp;
int i=0;
if((fp=fopen("employee_list","rb"))==NULL)
{
printf ("cannot open file\n");
exit(0);
}
else
{
do
{
fread(&em[i],sizeof(struct employee),1,fp);
i++;
}
while(feof(fp)==0);
}
fclose(fp);
return(i-1);
}
void display() /*浏览函数*/
{
int i;
int m=load();
printf("\n 职工号\t姓名\t性别\t年龄\t学历\t工资\t住址\t电话 \n");
for(i=0;i<m;i++) /*m为输入部分的职工人数*/
printf("\n %d\t%s\t%c\t%d\t%s\t%d\t%s\t%ld\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage,em[i].addr,em[i].tel);
}
void del() /*删除函数*/
{
int m=load();
int i,j,n,t,flag;
char name[20];
printf("\n 原来的职工信息:\n");
display(); /* 调用浏览函数*/
printf("\n");
printf("请输入要删除的职工的姓名:\n");
scanf("%s",name);
for(flag=1,i=0;flag&&i<m;i++)
{
if(strcmp(em[i].name,name)==0)
{
printf("\n已找到此人,原始记录为:\n");
printf("\n职工号\t姓名\t性别\t年龄\t学历\t工资\t住址\t电话 \n");
printf("\n%d\t%s\t%c\t%d\t%s\t%d\t%s\t%ld\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage,em[i].addr,em[i].tel);
printf("\n确实要删除此人信息请按1,不删除请按0\n");
scanf("%d",&n);
if(n==1) /*如果删除,则其他的信息都往上移一行*/
{
for(j=i;j<m-1;j++)
{
strcpy(em[j].name,em[j+1].name);
em[j].num=em[j+1].num;
em[j].sex=em[j+1].sex;
em[j].age=em[j+1].age;
strcpy(em[j].xueli,em[j+1].xueli);
em[j].wage=em[j+1].wage;
strcpy(em[j].addr,em[j+1].addr);
em[j].tel=em[j+1].tel;
}
flag=0;
}
}
}
if(!flag)
m=m-1;
else
printf("\n对不起,查无此人!\n");
printf("\n 浏览删除后的所有职工信息:\n");
save(m); /*调用保存函数*/
display(); /*调用浏览函数*/
printf("\n继续删除请按1,不再删除请按0\n");
scanf("%d",&t);
switch(t)
{
case 1:del();break;
case 0:break;
default :break;
}
}
void add()/*添加函数*/
{
FILE*fp;
int n;
int count=0;
int i;
int m=load();
printf("\n 原来的职工信息:\n");
display(); /* 调用浏览函数*/
printf("\n");
fp=fopen("emploee_list","a");
printf("请输入想增加的职工数:\n");
scanf("%d",&n);
for (i=m;i<(m+n);i++)
{
printf("\n 请输入新增加职工的信息:\n");
printf("请输入职工号: ");
srand((int)time(0));
em[i].num=rand()%10000+20000000;
if(em[i].num!=em[i-1].num)
printf("%8d ",em[i].num);
printf("\n");
printf("请输入姓名: ");
scanf("%s",em[i].name);
getchar();
printf("请输入性别(f--女 m--男): ");
scanf("%c",&em[i].sex);
printf("请输入年龄: ");
scanf("%d",&em[i].age);
printf("请输入学历: ");
scanf("%s",em[i].xueli);
printf("请输入工资: ");
scanf("%d",&em[i].wage);
printf("请输入住址: ");
scanf("%s",em[i].addr);
printf("请输入电话: ");
scanf("%d",&em[i].tel);
printf("\n");
count=count+1;
printf("已增加的人数:\n");
printf("%d\n",count);
}
printf("\n添加完毕!\n");
m=m+count;
printf("\n浏览增加后的所有职工信息:\n");
printf("\n");
save(m);
display();
fclose(fp);
}
void search()/*查询函数*/
{
int t,flag;
do
{
printf("\n按职工号查询请按1 ; 按学历查询请按2 ; 按电话号码查询请按3,进入主函数按4\n");
scanf("%d",&t);
if(t>=1&&t<=4)
{
flag=1;
break;
}
else
{
flag=0;
printf("您输入有误,请重新选择!");
}
}
while(flag==0);
while(flag==1)
{
switch(t)
{
case 1:printf("按职工号查询\n");search_num();break;
case 2:printf("按学历查询\n");search_xueli();break;
case 3:printf("按电话号码查询\n");search_tel();break;
case 4:main();break;
default:break;
}
}
}
void search_num()
{
int num;
int i,t;
int m=load();
printf("请输入要查找的职工号(20001111---20009999):\n");
scanf("%d",&num);
for(i=0;i<m;i++)
if(num==em[i].num)
{
printf("\n已找到此人,其记录为:\n");
printf("\n职工号\t姓名\t性别\t年龄\t学历\t工资\t住址\t电话 \n");
printf("\n%d\t%s\t%c\t%d\t%s\t%d\t%s\t%ld\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage,em[i].addr,em[i].tel);
break;
}
if(i==m)
printf("\n对不起,查无此人\n");
printf("\n");
printf("返回查询函数请按1,继续查询职工号请按2\n");
scanf("%d",&t);
switch(t)
{
case 1:search();break;
case 2: break;
default:break;
}
}
void search_xueli()
{
char xueli[30];
int i,t;
int m=load();
printf("请输入要查找的学历:\n");
scanf("%s",xueli);
for(i=0;i<m;i++)
if(strcmp(em[i].xueli,xueli)==0)
{
printf("\n已找到,其记录为:\n");
printf("\n职工号\t姓名\t性别\t年龄\t学历\t工资\t住址\t电话 \n");
printf("\n%d\t%s\t%c\t%d\t%s\t%d\t%s\t%ld\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage,em[i].addr,em[i].tel);
}
if(i==m)
printf("\n对不起,查无此人\n");
printf("\n");
printf("返回查询函数请按1,继续查询学历请按2\n");
scanf("%d",&t);
switch(t)
{
case 1:search();break;
case 2:break;
default :break;
}
}
void search_tel()
{
long int tel;
int i, t;
int m=load();
printf("请输入要查找的电话号码:\n");
scanf("%ld",&tel);
for(i=0;i<m;i++)
if(tel==em[i].tel)
{
printf("\n已找到此人,其记录为:\n");
printf("\n职工号\t姓名\t性别\t年龄\t学历\t工资\t住址\t电话 \n");
printf("\n%d\t%s\t%c\t%d\t%s\t%d\t%s\t%ld\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage,em[i].addr,em[i].tel);
break;
}
if(i==m)
printf("\n对不起,查无此人\n");
printf("\n");
printf("返回查询函数请按1,继续查询电话号码请按2\n");
scanf("%d",&t);
switch(t)
{
case 1:search();break;
case 2:break;
default :break;
}
}
void modify() /*修改函数*/
{
int num;
char name[10];
char sex;
int age;
char xueli[30];
int wage;
char addr[30];
long int tel;
int b,c,i,n,t,flag;
int m=load(); /*导入文件内的信息*/
printf("\n 原来的职工信息:\n");
display(); /* 调用浏览函数*/
printf("\n");
printf("请输入要修改的职工的姓名:\n");
scanf("%s",name);
for(flag=1,i=0;flag&&i<m;i++)
{
if(strcmp(em[i].name,name)==0)
{
printf("\n已找到此人,原始记录为:\n");
printf("\n职工号\t姓名\t性别\t年龄\t学历\t工资\t住址\t电话 \n");
printf("\n%d\t%s\t%c\t%d\t%s\t%d\t%s\t%ld\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage,em[i].addr,em[i].tel);
printf("\n确实要修改此人信息请按1 ; 不修改请按0\n");
scanf("%d",&n);
if(n==1)
{
printf("\n需要进行修改的选项\n 1.职工号 2.姓名 3.性别 4.年龄 5.学历 6.工资 7.住址 8.电话\n");
printf("请输入你想修改的那一项序号:\n");
scanf("%d",&c);
if(c>8||c<1)
printf("\n选择错误,请重新选择!\n");
}
flag=0;
}
}
if(flag==1)
printf("\n对不起,查无此人!\n");
do
{
switch(c) /*因为当找到第i个职工时,for语句后i自加了1,所以下面的应该把改后的信息赋值给第i-1个人*/
{
case 1:printf("职工号改为: ");
scanf("%d",&num);
em[i-1].num=num;
break;
case 2:printf("姓名改为: ");
scanf("%s",name);
strcpy(em[i-1].name,name);
break;
case 3:printf("性别改为: ");
getchar();
scanf("%c",&sex);
em[i-1].sex=sex;
break;
case 4:printf("年龄改为: ");
scanf("%d",&age);
em[i-1].age=age;
break;
case 5:printf("学历改为: ");
scanf("%s",xueli);
strcpy(em[i-1].xueli,xueli);
break;
case 6:printf("工资改为: ");
scanf("%d",wage);
break;
case 7:printf("住址改为: ");
scanf("%s",addr);
strcpy(em[i-1].addr,addr);
break;
case 8:printf("电话改为: ");
scanf("%ld",&tel);
em[i-1].tel=tel;
break;
}
printf("\n");
printf("\n是否确定所修改的信息?\n 是 请按1 ; 不,重新修改 请按2: \n");
scanf("%d",&b);
}
while(b==2);
printf("\n浏览修改后的所有职工信息:\n");
printf("\n");
save(m);
display();
printf("\n继续修改请按1,不再修改请按0\n");
scanf("%d",&t);
switch(t)
{
case 1:modify();break;
case 0:break;
default :break;
}
}
Ⅲ C语言程序——职工信息管理系统
貌似这么大的系统很难有人帮你做,这儿有个学生管理系统,稍加修改就成了~
/*学生成绩管理系统*/
/*系统版本号:2006build 400.0201b*/
/*内核:adobo*/
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#define N 32
int total=N; //定义全局变量,学生的总个数total
struct student
{
int xh;
char xm[6];
int yw;
int sx;
int yy;
int jsj;
int zf;
};
struct student stu[N],temp;
char get_key() //得到用户按键值
{
char key;
while (1)
{
if (kbhit())
{
key=getch();
break;
}
}
return key;
}
void wait() //按键等待,相当于PAUSE的功能
{
char key;
while (1)
{
if (kbhit())
{
key=getche();
break;
}
}
}
int id_search(int num) //查询该学号学生的数组编号
{
int i;
for (i=0;i<total;i++)
if (stu[i].xh==num) break;
return i;
}
void show_one(int id) //显示某学号学生的信息
{
cout<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"⑴学号:"<<stu[id].xh<<endl;
cout<<"⑵姓名:"<<stu[id].xm<<endl;
cout<<"⑶语文:"<<stu[id].yw<<endl;
cout<<"⑷数学:"<<stu[id].sx<<endl;
cout<<"⑸英语:"<<stu[id].yy<<endl;
cout<<"⑹计算机:"<<stu[id].jsj<<endl;
cout<<"⑺总分:"<<stu[id].zf<<endl;
cout<<"--------------------------------------------------------------"<<endl;
}
void show_all() //显示所有学生的信息
{
int i;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"学号\t"<<"姓名\t"<<"语文\t"<<"数学\t"<<"英语\t"<<"计算机\t"<<"总分"<<endl;
for (i=0;i<total;i++)
cout<<stu[i].xh<<'\t'<<stu[i].xm<<'\t'<<stu[i].yw<<'\t'<<stu[i].sx<<'\t'<<stu[i].yy<<'\t'<<stu[i].jsj<<'\t'<<stu[i].zf<<endl;
cout<<"--------------------------------------------------------------"<<endl;
}
void cj_input() //输入学生的成绩
{
int i;
cout<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"※学生成绩信息录入菜单※"<<endl;
cout<<"◎请完整输入学生个人信息"<<endl;
cout<<"◎学号项键入0可结束编辑"<<endl;
cout<<"--------------------------------------------------------------"<<endl;
for (i=0;i<N;i++)
{
cout<<"请输入第"<<i+1<<"个学生的学号:";
cin>>stu[i].xh;
if (stu[i].xh==0) return; //用户输入0时,结束编辑
cout<<"请输入第"<<i+1<<"个学生的姓名:";
cin>>stu[i].xm;
cout<<"请输入第"<<i+1<<"个学生的语文成绩:";
cin>>stu[i].yw;
cout<<"请输入第"<<i+1<<"个学生的数学成绩:";
cin>>stu[i].sx;
cout<<"请输入第"<<i+1<<"个学生的英语成绩:";
cin>>stu[i].yy;
cout<<"请输入第"<<i+1<<"个学生的计算机成绩:";
cin>>stu[i].jsj;
stu[i].zf=stu[i].yw+stu[i].sx+stu[i].yy+stu[i].jsj;
cout<<"---------------提示:学号项键入 0可结束编辑----------------"<<endl;
}
}
void auto_input() //自动输入学生的成绩,为测试方便而设
{
int i;
for (i=0;i<N;i++)
{
stu[i].xh=(i+1);
strcpy(stu[i].xm,"ayc");
stu[i].yw=rand()%100;
stu[i].sx=rand()%100;
stu[i].yy=rand()%100;
stu[i].jsj=rand()%100;
stu[i].zf=stu[i].yw+stu[i].sx+stu[i].yy+stu[i].jsj;
}
}
void cj_modify() //学生成绩的修改
{
int num,id;
char choice;
cout<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"※学生成绩信息修改菜单※"<<endl;
cout<<"◎请确认已经录入学生信息"<<endl;
cout<<"◎学号不存在即会返回菜单"<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"请输入待修改的学生的学号:";
cin>>num;
id=id_search(num);
if (id==total)
{
cout<<endl;
cout<<"-〖系统提示〗------------------------"<<endl;
cout<<" 错误!无该学号学生信息!"<<endl;
cout<<"-------------------------------------"<<endl;
wait();
return;
}
cout<<"选择要修改的项目的编号,其它值返回:";
show_one(id);
choice=get_key();
if (choice=='1')
{cout<<"输入新的学号:";
cin>>stu[id].xh;
}
else if (choice=='2')
{cout<<"输入新的姓名:";
cin>>stu[id].xm;
}
else if (choice=='3')
{cout<<"输入新的语文成绩:";
cin>>stu[id].yw;
}
else if (choice=='4')
{cout<<"输入新的数学成绩:";
cin>>stu[id].sx;
}
else if (choice=='5')
{cout<<"输入新的英语成绩:";
cin>>stu[id].yy;
}
else if (choice=='6')
{
cout<<"输入新的计算机成绩:";
cin>>stu[id].jsj;
}
stu[id].zf=stu[id].yw+stu[id].sx+stu[id].yy+stu[id].jsj;
if (choice=='1'||choice=='2'||choice=='3'||choice=='4'||choice=='5'||choice=='6')
{
cout<<"-〖系统提示〗------------------------"<<endl;
cout<<" 已成功修改该学生信息!";
cout<<"-------------------------------------"<<endl;
show_one(id);
wait();
}
}
void cj_delete() //学生信息的删除
{
int num,id,i;
cout<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"※学生成绩信息删除菜单※"<<endl;
cout<<"◎请确认已经录入学生信息"<<endl;
cout<<"◎学号不存在即会返回菜单"<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"请输入要删除的学生学号:";
cin>>num;
id=id_search(num);
if (id==total)
{
cout<<endl;
cout<<"-〖系统提示〗------------------------"<<endl;
cout<<" 错误!无该学号学生信息!"<<endl;
cout<<"-------------------------------------"<<endl;
wait();
return;
}
show_one(id);
for (i=id;i<total;i++)
stu[i]=stu[i+1];
total=total-1;
cout<<endl;
cout<<" 学 生 成 绩 显 示 菜 单 "<<endl;
show_all();
cout<<endl;
cout<<"-〖系统提示〗------------------------"<<endl;
cout<<" 已成功删除该学生的信息!"<<endl;
cout<<"-------------------------------------"<<endl;
wait();
}
void func_1() //录入编辑菜单
{
char choice;
while(1)
{
system("cls");
cout<<" 学 生 成 绩 管 理 系 统 "<<endl;
cout<<"=============================================================="<<endl;
cout<<" ⑴录入成绩 "<<endl;
cout<<" ⑵修改成绩 "<<endl;
cout<<" ⑶删除成绩 "<<endl;
cout<<" ⑷返回上级 "<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<" 键入相应数字项进行功能选择(1-4) "<<endl;
choice=get_key();
if (choice=='1') cj_input(); //这里为测试方便,自动输入了成绩,注意改回
else if (choice=='2') cj_modify();
else if (choice=='3') cj_delete();
else if (choice=='4') break;
}
}
void show_person() //个人成绩查询
{
int num,id;
cout<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"※学生成绩信息修改菜单※"<<endl;
cout<<"◎请确认已经录入学生信息"<<endl;
cout<<"◎学号不存在即会返回菜单"<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"请输入要查询的学生学号:";
cin>>num;
id=id_search(num);
if (id==total)
{
cout<<endl;
cout<<"-〖系统提示〗------------------------"<<endl;
cout<<" 错误!无该学号学生信息!"<<endl;
cout<<"-------------------------------------"<<endl;
wait();
return;
}
show_one(id);
wait();
}
void cj_pm() //生成名次,即按照总分输出
{
int i,j;
for (j=0;j<total;j++)
{
for (i=0;i<total-j;i++)
{
if (stu[i].zf<stu[i+1].zf)
{
temp=stu[i];
stu[i]=stu[i+1];
stu[i+1]=temp;
}
}
}
cout<<endl;
cout<<" 学 生 成 绩 显 示 (按 总 分) "<<endl;
show_all();
wait();
}
void cj_xh() //按照学号输出
{
int i,j;
for (j=0;j<total;j++)
{
for (i=0;i<total-j;i++)
{
if (stu[i].xh>stu[i+1].xh)
{
temp=stu[i];
stu[i]=stu[i+1];
stu[i+1]=temp;
}
}
}
cout<<endl;
cout<<" 学 生 成 绩 显 示 (按 学 号) "<<endl;
show_all();
wait();
}
void cj_bk() //生成补考名单
{
int i;
cout<<" 补 考 名 单 "<<endl;
cout<<"=============================================================="<<endl;
cout<<"学号\t"<<"姓名\t"<<"语文\t"<<"数学\t"<<"英语\t"<<"计算机\t"<<endl;
for (i=0;i<total;i++)
{
if ((stu[i].yw<60)||(stu[i].sx<60)||(stu[i].yy<60)||(stu[i].jsj<60))
{
cout<<stu[i].xh<<'\t'<<stu[i].xm<<'\t';
if(stu[i].yw<60) cout<<"补考\t";
else cout<<'\t';
if(stu[i].sx<60) cout<<"补考\t";
else cout<<'\t';
if(stu[i].yy<60) cout<<"补考\t";
else cout<<'\t';
if(stu[i].jsj<60) cout<<"补考\t"<<endl;
else cout<<endl;
}
}
cout<<"--------------------------------------------------------------"<<endl;
wait();
}
void func_2() //成绩查询统计
{
char choice;
while(1)
{
system("cls");
cout<<" 学 生 成 绩 管 理 系 统 "<<endl;
cout<<"=============================================================="<<endl;
cout<<" ⑴个人成绩查询 "<<endl;
cout<<" ⑵班级排名查询 "<<endl;
cout<<" ⑶生成补考名单 "<<endl;
cout<<" ⑷返回上级 "<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<" 键入相应数字项进行功能选择(1-4) "<<endl;
choice=get_key();
if (choice=='1') show_person();
else if (choice=='2') cj_pm();
else if (choice=='3') cj_bk();
else if (choice=='4') break;
}
}
void func_3() //成绩打印与输出
{
char choice;
while(1)
{
system("cls");
cout<<" 学 生 成 绩 管 理 系 统 "<<endl;
cout<<"=============================================================="<<endl;
cout<<" ⑴按学号输出 "<<endl;
cout<<" ⑵按总分输出 "<<endl;
cout<<" ⑶返回上级 "<<endl;
cout<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<" 键入相应数字项进行功能选择(1-3) "<<endl;
choice=get_key();
if (choice=='1') cj_xh();
else if (choice=='2') cj_pm();
else if (choice=='3') break;
}
}
int main() //主函数开始
{
char choice;
while(1)
{
system("cls");
cout<<" 学 生 成 绩 管 理 系 统 "<<endl;
cout<<"=============================================================="<<endl;
cout<<" ⑴成绩录入与编辑 "<<endl;
cout<<" ⑵成绩查询与统计 "<<endl;
cout<<" ⑶成绩打印与输出 "<<endl;
cout<<" ⑷退出本管理系统 "<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<" 键入相应数字项进行功能选择(1-4) "<<endl;
choice=get_key();
if (choice=='1') func_1();
else if (choice=='2') func_2();
else if (choice=='3') func_3();
else if (choice=='4') break;
}
system("cls"); //版权信息
cout<<"***************[关于本系统]***************"<<endl;
}
Ⅳ 急求:职工信息管理系统设置(c语言的程序代码)
#include<iostream>
#include<fstream>
using namespace std;
struct wkrs
{
char num[10];
char name[10];
char sex[3];
int age;
}wk[10];
struct wkr
{
char name[10];
int age;
}wkshort[10];
void Display();
void Readin();
void Disp();
void SelectWk();
void Delwk();
int MenuSelect();
int num=0,number=10;
void main()
{
for(;;)
{
switch(MenuSelect())
{
case 1:Readin();break;
case 2:Display();break;
case 3:SelectWk();break;
case 4:Delwk();break;
case 5:Disp();break;
case 6:cout<<"退出运行,再见!"<<endl;exit(0);
}
}
}
int MenuSelect()
{
char s[2];int cn;
cout<<"1.输入数据"<<endl;
cout<<"2.显示原始数据"<<endl;
cout<<"3.制作简明数据"<<endl;
cout<<"4.删除简明数据"<<endl;
cout<<"5.显示简明文件"<<endl;
cout<<"退出运行"<<endl;
cout<<endl<<"左边数字对应功能选择,请选1-6:";
for(;;)
{
gets(s);
cn=atoi(s);
if(cn<1||cn>6)
cout<<endl<<"输入错误,重选1-6:";
else
break;
}
return(cn);
}
void Display()
{
int i;
ifstream disp("workers.txt");
//disp>>number;
if(!disp)
{
cout<<"文件打不开"<<endl;
return;
}
cout<<endl<<"序号"<<"\t姓名"<<"\t性别"<<"\t年龄"<<endl;
for(i=0;i<number;i++)
{
disp>>wk[i].num>>wk[i].name>>wk[i].sex>>wk[i].age;
cout<<endl<<wk[i].num<<"\t"<<wk[i].name<<"\t"<<wk[i].sex<<"\t"<<wk[i].age;
}
disp.close();
cout<<endl<<"一共有"<<number<<"个职工的信息"<<endl;
}
void Disp()
{
ifstream disp("wk_saw.txt",ios::binary);
if(!disp)
{
cout<<"文件打不开"<<endl;
return;
}
cout<<endl<<"职工简明文件内容:"<<endl;
cout<<endl<<"姓名"<<"\t年龄:"<<endl;
disp>>num;
for(int i=0;i<num;i++)
{
disp>>wkshort[i].name>>wkshort[i].age;
cout<<endl<<wkshort[i].name<<"\t"<<wkshort[i].age;
}
disp.close();
cout<<endl<<"一共有"<<num<<"个职工的信息"<<endl;
}
void Readin()
{
char ch[10];int i=0;
cout<<"准备输入职工信息"<<endl;
for(i=0;i<number;i++)
{
cout<<"序号:";
cin>>wk[i].num;
if(strcmp("0",wk[i].num)==0)
{
number=i;break;
}
cout<<"姓名:";
getchar();
gets(ch);
strcpy(wk[i].name,ch);
cout<<"性别:";
cin>>wk[i].sex;
cout<<"年龄:";
cin>>wk[i].age;
}
if(number==0)
{
cout<<"没有输入数据,不改写文件!"<<endl;
return;
}
cout<<"输入结束!"<<endl;
ofstream wr("workers.txt");
for(i=0;i<number;i++)
{
wr<<wk[i].num<<" "<<wk[i].name<<" "<<wk[i].sex<<" "<<wk[i].age<<endl;
}
wr.close();
cout<<endl<<"一共写入"<<number<<"个职工的信息"<<endl;
}
void SelectWk()
{
int i;
ifstream disp("workers.txt");
if(!disp)
{
cout<<"文件打不开"<<endl;
return;
}
//disp>>number;
for(i=0;i<number;i++)
{
cout<<endl<<wk[i].num<<"\t"<<wk[i].name<<"\t"<<wk[i].sex<<"\t"<<wk[i].age;
strcpy(wkshort[i].name,wk[i].name);
wkshort[i].age=wk[i].age;
}
cout<<endl;
disp.close();
ofstream wr("wk_saw.txt");
wr<<number<<endl;
for(i=0;i<number;i++)
{
wr<<wkshort[i].name<<" "<<wkshort[i].age<<endl;
}
wr.close();
Disp();
cout<<endl;
}
void Delwk()
{
int i=0,j,flag=0;char na[10];
Disp();
if(num==0)
{
cout<<endl<<"文件内容为空,退出删除操作."<<endl;
return;
}
cout<<endl<<"输入待删除的职工的姓名(输入0退出删除):";
while(strcmp(na,"0")!=0)
{
cout<<endl<<"姓名:";
gets(na);
if(strcmp(na,"0")==0)
{
cout<<endl<<"退出删除操作."<<endl;
return;
}
for(flag=1,i=0;i<num;i++)
{
if(strcmp(na,wkshort[i].name)==0)
{
for(j=i;j<num;j++)
{
strcpy(wkshort[j].name,wkshort[j+1].name);
wkshort[j].age=wkshort[j+1].age;
}
flag=0;
ofstream wr("wk_saw.txt");
num--;
wr<<num<<endl;
for(i=0;i<num;i++)
{
wr<<wkshort[i].name<<" "<<wkshort[i].age<<endl;
}
wr.close();
}
}
if(!flag)
if(num==0)
{
cout<<"现在已经删空文件内容,退出删除操作."<<endl;
return;
}
else
{
cout<<endl<<"删除后的文件内容:"<<endl;
Disp();
}
else
cout<<endl<<"没有发现这个职工,重新输入:"<<endl;
}
}
Ⅳ 用C语言设计并实现一个员工信息管理系统
#include<iostream>
#include<cstring>
usingnamespacestd;
typedefstructwage{
charunit[8];
charname[10];
charsex[4];
charbirthdate[12];
chartitle[20];
doublebasewage;
doublesubsidy;
doubletax;
doubleexpenses;
doubleresialwage;
}WAGE;
voidComputerResialwage(WAGEa[],intn){
for(inti=0;i<n;++i)
a[i].resialwage=a[i].basewage+a[i].subsidy-a[i].tax-a[i].expenses;
}
voidPrintTitle(void){
cout<<"单位姓名性别出生年月职称基本工资津贴个税水电费实发工资 ";
for(inti=0;i<79;++i)cout<<"*";cout<<endl;
}
voidRowShow(WAGEa[],inti){
cout<<a[i].unit<<"";
if(strlen(a[i].name)==4){
a[i].name[6]=a[i].name[4];
a[i].name[5]=a[i].name[3];
a[i].name[4]=a[i].name[2];
a[i].name[2]=a[i].name[3]='';
}
cout<<a[i].name<<""<<a[i].sex<<""<<a[i].birthdate;
if(strlen(a[i].title)==4){
a[i].title[6]=a[i].title[4];
a[i].title[5]=a[i].title[3];
a[i].title[4]=a[i].title[2];
a[i].title[2]=a[i].title[3]='';
}
cout<<""<<a[i].title<<"";
cout.precision(2);
cout.width(8);
cout<<fixed<<a[i].basewage<<"";cout.width(6);
cout<<fixed<<a[i].subsidy<<"";
cout.width(8);
cout<<fixed<<a[i].tax<<"";
cout.width(6);
cout<<fixed<<a[i].expenses<<"";
cout.width(8);
cout<<fixed<<a[i].resialwage<<endl;
}
voidShow(WAGEa[],intn){
for(inti=0;i<n;++i)RowShow(a,i);
}
voidSearch1(WAGEa[],intn){
inti,flag=1;
for(i=0;i<n;++i){
if(strcmp(a[i].unit,"理学院")==0&&a[i].basewage>900.00&&
strcmp(a[i].title,"副教授")==0&&strcmp(a[i].sex,"男")==0){
RowShow(a,i);
flag=0;
}
}
if(flag)cout<<"(没找到符合条件者) ";
}
voidSearch2(WAGEa[],intn){
inti,flag=1;
for(i=0;i<n;++i){
if(strcmp(a[i].unit,"理学院")==0&&a[i].basewage<1200.00&&
strcmp(a[i].title,"教授")==0&&strcmp(a[i].sex,"男")==0){
RowShow(a,i);
flag=0;
}
}
if(flag)cout<<"(没找到符合条件者) ";
}
intmain(){
WAGEa[]={
{"理学院","赵志军","男","1957-06-25","教授",1150,411,176.6,90},
{"商学院","于铭","女","1979-10-21","助教",500,471,208.9,91},
{"工学院","许炎锋","女","1954-03-08","教授",1250,630,306.2,96},
{"理学院","王嘉","女","1971-06-06","讲师",850,475,100.3,89},
{"工学院","李新江","男","1962-10-02","教授",950,399,49.5,87},
{"商学院","郭海英","女","1963-02-07","副教授",950,332,77.6,85},
{"工学院","马淑恩","女","1960-06-09","副教授",900,791,60.5,45},
{"理学院","王金科","男","1956-09-10","教授",1050,480,325.6,93},
{"理学院","李东慧","女","1950-08-07","教授",1350,364,52.3,94},
{"工学院","张宁","女","1980-01-01","助教",500,395,78,89},
{"商学院","王孟","男","1966-09-08","讲师",800,463,220.3,98},
{"工学院","马会爽","女","1970-02-09","讲师",800,368,101.1,69},
{"工学院","史晓赟","女","1952-06-06","教授",1200,539,520.3,50},
{"理学院","刘燕凤","女","1959-08-07","教授",1200,892,180.9,86},
{"工学院","齐飞","男","1961-04-05","副教授",1200,626,245.6,74},
{"商学院","张娟","女","1975-09-25","助教",650,374,625.3,86},
{"理学院","潘成文","男","1965-10-09","讲师",950,402,1050,90},
{"工学院","邢易","女","1981-02-25","助教",600,325,300,90},
{"商学院","谢枭豪","女","1950-11-18","教授",1350,516,200,90},
{"工学院","胡洪静","女","1952-06-24","教授",1350,277,100,86},
{"工学院","李云飞","男","1969-05-04","讲师",960,729,56,89},
{"商学院","张奇","女","1970-05-28","讲师",960,331,69,89},
{"理学院","夏小波","女","1968-08-01","讲师",960,482,89,45},
{"工学院","王玮","女","1972-11-05","讲师",960,340,98,79},
{"理学院","张帝","女","1950-03-26","教授",1300,335,124,90},
{"商学院","孙帅","男","1966-05-24","讲师",900,748,326,79},
{"工学院","卜辉娟","女","1960-05-23","教授",960,481,651,78},
{"工学院","李辉玲","女","1978-09-09","助教",630,379,400,77},
{"理学院","刘亚静","男","1969-08-09","副教授",890,377,23,66},
{"工学院","尹娴","女","1958-06-09","教授",1050,955,59,65},
{"商学院","马春英","男","1964-12-06","讲师",850,387,78,69},
{"工学院","孟梦","女","1965-08-09","副教授",850,753,485.6,93},
{"工学院","梁晓萌","女","1975-06-09","助教",650,551,136.5,99},
{"理学院","张然","女","1973-03-03","讲师",800,761,203.1,100},
{"工学院","彭雁南","男","1978-05-09","助教",650,200,200,90}
};
inti,n=sizeof(a)/sizeof(a[0]);
if(n==0)return1;
ComputerResialwage(a,n);
PrintTitle();
for(i=0;i<n;++i)RowShow(a,i);
for(i=0;i<79;++i)cout<<"*";
cout<<endl;cout<<" 理学院,基本工资高于900元的男副教授有: ";
PrintTitle();
Search1(a,n);
for(i=0;i<79;++i)cout<<"*";
cout<<endl;
cout<<" 理学院,基本工资低于1200元的男教授有: ";
PrintTitle();
Search2(a,n);
for(i=0;i<79;++i)cout<<"*";
cout<<endl<<endl;
return0;
}
Ⅵ C语言实现公司职员信息管理系统
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 200
int id=0; /*全局变量,添加数据时自增.*/
int *p;
char delechar[]="qq1145219983";
struct score
{
int c;
int java;
int vb;
int sql;
int asp;
};
struct user /*结构体,学生数据各项属性定义.*/
{
char name[50];
char sex[10];
char no[20];
int userid;
struct score grade ;
};
struct user users[MAX]; /*全局结构体数组,定义可存储学生数.*/
void adser(); /*添加数据的函数说明.*/
void updateuser(); /*修改数据的函数说明.*/
void deleteuser(); /*删除数据的函数说明.*/
void selectuser(); /*查询数据的函数说明.*/
void selectno(); /*按学号查询函数说明.*/
void selectall(); /*查询全部学生函数声明.*/
void selectgrade();
void upgrade(int a);
int average(int i);
int verify(int a);
int verifyg(int a);
int load();
void save();
int main()
{
int conn;
id=load();
system("title 学生成绩信息管理系统");
printf("***************\nqq:1145219983\nMy Name:wei!\n***************\n");
for(;;) /*无限循环,用于每次执行完各操作函数时返回主菜单.*/
{
printf("\n\n\n\n"); /*主菜单开始*/
printf("***********************************\n"); /*主菜单开始*/
printf("=======学生成绩信息系统============\n");
printf("***********************************\n");
printf(">>> 1 添加.\n");
printf(">>> 2 修改.\n");
printf(">>> 3 删除.\n");
printf(">>> 4 查询.\n");
printf(">>> 5 清屏.\n");
printf(">>> 其他任意键退出.\n");
printf("***********************************\n");
printf("***********************************\n\n\n");
printf("输入操作:"); /*主菜单结束*/
scanf("%d",&conn); /*输入数字,给全局变量conter赋值,用于判断添加,删除数据等操作.*/
if (conn==1||conn==2||conn==3||conn==4||conn==5) /*判断输入数字是否在1到5之间*/
{
switch(conn) /*如果上面判断是在1到4间,则执行switch,判断conter是1到4间的哪一个.*/
{
case 1 : adser(); save(); break; /*是1,则执行添加函数,转至添加函数进行操作.*/
case 2 : updateuser(); save(); break; /*是2,则执行修改函数,转至修改函数进行操作.*/
case 3 : deleteuser(); save(); break; /*是3,则执行删除函数,转至删除函数进行操作.*/
case 4 : selectuser(); break; /*是4,则执行查询函数,转至查询函数进行操作.*/
case 5 : system("cls"); break;
default : exit(0); /*都不是,则退出程序.*/
}
}
else exit(0);
}
}
void adser() /*添加数据函数,*/
{
char ch;
int i=0;
printf("姓名:");
scanf("%s",users[id].name);
printf("性别:");
scanf("%s",users[id].sex);
printf("输入成绩:\n");
printf("c语言:");
scanf("%d",&users[id].grade.c);
users[id].grade.c=verifyg(users[id].grade.c);
printf("Java:");
scanf("%d",&users[id].grade.java);
users[id].grade.java=verifyg(users[id].grade.java);
printf("Vb:");
scanf("%d",&users[id].grade.vb);
users[id].grade.vb=verifyg(users[id].grade.vb);
printf("Sql:");
scanf("%d",&users[id].grade.sql);
users[id].grade.sql=verifyg(users[id].grade.sql);
printf("Asp:");
scanf("%d",&users[id].grade.asp);
users[id].grade.asp=verifyg(users[id].grade.asp);
while(i==0)
{
printf("学号:");
scanf("%s",users[id].no);
i=verify(id);
}
if(i!=0)
{
users[id].userid=id;
id++;
printf("\n完成!\n\n");
}
}
void updateuser() /*修改数据函数,*/
{
char upno[10],ch;
int conn;
int b=0;
int i,j;
printf("输入学号:");
scanf("%s",upno);
for(i=0;i<id;i++)
{
if(strcmp(users[i].no,upno)==0) /*遍历所有数据,判断输入的学号于数据里面的学号是否相同,不同则不执行修改.*/
{
printf("\n将要修改以下资料:\n");
printf("姓名:%s\n性别:%3s, 学号:%10s , 平均份:%3d \nC:%d , Java:%d , Vb:%d , Sql:%d , Asp:%d\n\n",users[i].name,users[i].sex,users[i].no,average(i),users[i].grade.c,users[i].grade.java,users[i].grade.vb,users[i].grade.sql,users[i].grade.asp);
printf("\n\n按任意键继续,按0返回...\n\n");
ch=getch(); if(ch==48) {j=1; break;}
printf("修改: 1.姓名 , 2.性别 , 3.学号 , 4.成绩 , 0.主目录 , 其他键退出.\n");
printf("请选择:");
scanf("%d",&conn);
if(conn==1||conn==2||conn==3||conn==4)
switch(conn)
{
case 1 : printf("姓名:");scanf("%s",users[i].name); j=1; printf("\n完成!\n\n"); break;
case 2 : printf("性别:");scanf("%s",users[i].sex); j=1; printf("\n完成!\n\n"); break;
case 3 : while(b==0){printf("学号:");scanf("%s",users[i].no);b=verify(i);}if(b!=0){j=1;b=0;printf("\n完成!\n\n");} break;
case 4 : j=1; upgrade(i); break;
}
else if(conn==0) {j=1; break;}
else exit(0);
if(j!=1) printf("\n没有此学生!\n\n");
}
}
}
void upgrade(int a) //修改成绩
{
int conn;
int i;
for(;;)
{
printf("修改成绩: 1.C , 2.Java , 3.Vb , 4.Sql , 5.Asp , 0.主目录 , 其他键退出.\n");
printf("输入操作:");
scanf("%d",&conn);
if(conn==1||conn==2||conn==3||conn==4||conn==5)
{
switch(conn)
{
case 1 : printf("C:");scanf("%d",&users[a].grade.c); break;
case 2 : printf("Java:");scanf("%d",&users[a].grade.java); break;
case 3 : printf("Vb:");scanf("%d",&users[a].grade.vb); break;
case 4 : printf("Sql:");scanf("%d",&users[a].grade.sql); break;
case 5 : printf("Asp:");scanf("%d",&users[a].grade.asp); break;
}
printf("完成!\n\n");
}
else if(conn==0)
break;
else
exit(0);
}
}
void deleteuser() /*删除数据函数,*/
{
char deno[10];
int i,j,k=0;
struct user temp;
printf("学号:");
scanf("%s",deno);
for(i=0;i<id;i++) /*遍历所有数据,判断输入的学号于数据里面的学号是否相同,不同则不执行删除操作,.*/
{
if(strcmp(users[i].no,deno)==0)
{
for(j=i;j<id-1;j++)
users[j]=users[j+1];
id--;
k=1;
printf("删除成功...\n");
}
}
if(k==0)
printf("没有此学生!\n");
}
void selectuser() /*查询控制函数,*/
{
int conn;
for(;;)
{
printf("***********************************\n");
printf(">>> 1.查询全部学生.\n");
printf(">>> 2.按学号查询.\n");
printf(">>> 0.主目录\n");
printf(">>> 其他键退出.\n");
printf("***********************************\n\n");
printf("输入操作:");
scanf("%d",&conn);
if(conn==1||conn==2)
{
switch(conn)
{
case 1 : selectall(); break;
case 2 : selectno(); break;
}
}
else if(conn==0)
break;
else
exit(0);
}
}
void selectall() /*查询所有数据函数,*/
{
int i;
if(id==0)
{
printf("\n\n没有数据,按任意键返回...\n\n");
getch();
}
else
{
printf("\n\n┏━━━━━━━━━━━━清单━━━━━━━━━━━━┓\n");
printf("┣━━━━━━━━━━━━━━━━━━━共%-6ld条记录┫\n",id);
for(i=0;i<id;i++)
{
if(i%5==0 && i!=0)
{
printf("┃下一页...");
getch();
}
printf("\x0d┃姓名:%-10s性别:%-6s学号:%-12s平均分:%d┃\n┃成绩:[C:%d] [Java:%d] [Vb:%d] [Sql:%d] [Asp:%d] ┃\n",users[i].name,users[i].sex,users[i].no,average(i),users[i].grade.c,users[i].grade.java,users[i].grade.vb,users[i].grade.sql,users[i].grade.asp);
printf("┠——————————————————————————┨\n");
}
printf("┗━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n\n\n");
}
}
void selectno() /*按学号查询数据函数,*/
{
char seno[10];
int i,ii=0;
printf("输入学号:");
scanf("%s",seno);
for(i=0;i<id;i++)
{
if(strcmp(users[i].no,seno)==0)
{
printf("\n\n*****************************清单******************************\n");
printf("||%-59s||\n",users[i].name);
printf("||===========================================================||\n");
printf("||性别:[%3s], 学号:[%10s ], 平均份:[%3d ], ||\n",&users[i].sex,&users[i].no,average(i));
printf("||--------------------------<成绩>---------------------------||\n");
printf("||C:[%3d ], Java:[%3d ], Vb:[%3d ], Sql:[%3d ], Asp:[%3d ], ||\n",users[i].grade.c,users[i].grade.java,users[i].grade.vb,users[i].grade.sql,users[i].grade.asp);
printf("||===========================================================||\n");
ii=1;
printf("***************************************************************\n\n\n");
}
}
if(ii!=1)
printf("没有此学生!\n");
}
int average(int i) //平均分
{
int a;
a=(users[i].grade.c + users[i].grade.java + users[i].grade.vb + users[i].grade.sql + users[i].grade.asp)/5;
return(a);
}
int verify(int a) //验证学号是否重复
{
int i,b;
for(i=0;i<id;i++)
{
if(i==a)
continue;
if(strcmp(users[a].no,users[i].no)==0)
{
printf("\n已有学号为%s的学生!\n重新输入:",users[a].no);
b=0;
break;
}
else b=1;
//printf("[%s] [[%s]]\n",users[a].no,users[i].no);
}
return(b);
}
int verifyg(int a) //验证成绩是否超出范围
{
while(a<0||a>100)
{
printf("\n错误.范围:0~100 重新输入:");
scanf("%d",&a);
}
return (a);
}
int load()
{
int num=0,i;
char temp;
FILE *fp;
if((fp=fopen("olize.dat","rb"))!=NULL)
{
fscanf(fp,"%d",&num);
//printf("[[ %d ]]\n",num);
for(i=0;i<num;i++)
{
fscanf(fp,"%s%s%s%d%d%d%d%d",users[i].name,users[i].sex,users[i].no,&users[i].grade.c,&users[i].grade.java,&users[i].grade.vb,&users[i].grade.sql,&users[i].grade.asp);
//printf("[[%s,%s,%s,%d,%d,%d,%d,%d]]\n\n",users[i].name,users[i].sex,users[i].no,users[i].grade.c,users[i].grade.java,users[i].grade.vb,users[i].grade.sql,users[i].grade.asp);
}
fclose(fp);
}
return (num);
}
void save()
{
int num,i,j;
struct user temp;
FILE *fp;
if((fp=fopen("olize.dat","wb"))==NULL)
{
printf("保存数据失败,数据文件无法打开...\n\n\n按任意键退出...");
getch();
exit(0);
}
for(i=0;i<id;i++)
for(j=i+1;j<id;j++)
if(average(i)<average(j))
{temp=users[i];users[i]=users[j];users[j]=temp;}
fprintf(fp,"%d\r\n",id);
for(i=0;i<id;i++)
fprintf(fp,"%-15s%-4s%-20s%-4d%-4d%-4d%-4d%-4d\r\n",users[i].name,users[i].sex,users[i].no,users[i].grade.c,users[i].grade.java,users[i].grade.vb,users[i].grade.sql,users[i].grade.asp);
fclose(fp);
}
这份代码是学生成绩信息,你修改一下就好啦,本质上一样的
Ⅶ 用C语言设计职工信息管理系统
#include<iostream>
#include<string>
#include<fstream>
usingnamespacestd;
constn=50;//定义系统可录入的员工最大数值
stringename[n];
longenum[n];
charesex[n];
inteage[n];
charemarriage[n];
intedepart[n];
inteposition[n];
intedegree[50];
inteworktime[n];
floatepay[n];
classemployee
{
public:
stringemployeename;
longemployeenum;
charemployeesex;
intemployeeage;
charemployeemarriage;
intemployeedepart;
intemployeeposition;
intemployeedegree;
intemployeeworktime;
floatemployeepay;
staticlongemployeemaxnum;
staticfloatemployeebasepay;
voidnewinfo();
voidshowinfo();
voidshowall();
voidshowdepart(intdepart);
voidshowdegree(intdegree);
voidshowage(intmin,intmax);
voidshownum(longnumber);
voidrefreshinfo();
voiddeleteinfo();
floatpay(intemployeegrade);
staticintmaxnum();
};
classdboperate
{
public:
stringemployeename;
longemployeenum;
charemployeesex;
intemployeeage;
charemployeemarriage;
intemployeedepart;
intemployeeposition;
intemployeedegree;
intemployeeworktime;
floatemployeepay;
staticlongemployeemaxnum;
staticfloatemployeebasepay;
voidwritein(intiflag);
voidreadout();
voidrefreshmaxnum(intiflag);//i=1or-1or0
};
longemployee::employeemaxnum=1000;
floatemployee::employeebasepay=1500;
intemployee::maxnum()//返回系统已经存储的人数
{
intmn=0;
ifstreammyf;
myf.open("employeemaxnum.txt");
myf>>mn;
cout<<mn<<endl;
myf.close();
returnmn;
}
voidemployee::newinfo()//添加新成员函数
{
cout<<"新员工姓名:";
cin>>employee::employeename;
employee::employeenum=employeemaxnum+employee::maxnum()+1;
cout<<"新员工性别(f为女性,m为男性):";
cin>>employee::employeesex;
cout<<"新员工年龄:";
cin>>employee::employeeage;
cout<<"新员工婚姻状况(y为已婚,n为未婚):";
cin>>employee::employeemarriage;
cout<<"新员工学历,请输入相应学历的序号:"<<endl;
cout<<"[1:初中2:高中3:本科4:硕士5:博士]";
cin>>employee::employeedegree;
while(employee::employeedegree!=1&&employee::employeedegree!=2&&employee::employeedegree!=3&&employee::employeedegree!=4&&employee::employeedegree!=5)
{
cout<<"输入有误,请重新输入:"<<endl;
cout<<"[1:初中2:高中3:本科4:硕士5:博士]";
cin>>employee::employeedegree;
}
cout<<"新员工所在部门,请输入相应部门的序号:"<<endl;
cout<<"[1:董事会2:市场部3:公关部4:客服中心5:信息中心]";
cin>>employee::employeedepart;
while(employee::employeedepart!=1&&employee::employeedepart!=2&&employee::employeedepart!=3&&employee::employeedepart!=4&&employee::employeedepart!=5)
{
cout<<"输入有误,请重新输入:"<<endl;
cout<<"[1:董事会2:市场部3:公关部4:客服中心5:信息中心]";
cin>>employee::employeedepart;
}
cout<<"新员工职位,请输入相应职位的序号:"<<endl;
cout<<"[1:临时职员2:正式职员3:主任4:部门经理5:董事长]";
cin>>employee::employeeposition;
while(employee::employeeposition!=1&&employee::employeeposition!=2&&employee::employeeposition!=3&&employee::employeeposition!=4&&employee::employeeposition!=5)
{
cout<<"输入有误,请重新输入:"<<endl;
cout<<"[1:临时职员2:正式职员3:主任4:部门经理5:董事长]";
cin>>employee::employeeposition;
}
cout<<"新员工的工作时(不需要输入单位):";
cin>>employee::employeeworktime;
employee::employeepay=employee::pay(employee::employeeposition);
dboperatedbo;
dbo.readout();
intmaxnum=employee::maxnum();
enum[maxnum]=employee::employeenum;
ename[maxnum]=employee::employeename;
esex[maxnum]=employee::employeesex;
eage[maxnum]=employee::employeeage;
emarriage[maxnum]=employee::employeemarriage;
edegree[maxnum]=employee::employeedegree;
edepart[maxnum]=employee::employeedepart;
eposition[maxnum]=employee::employeeposition;
eworktime[maxnum]=employee::employeeworktime;
epay[maxnum]=employee::employeepay;
dbo.writein(1);
cout<<"添加新成员成功!"<<endl;
return;
}
voidemployee::showinfo()//程序主体数据输出函数
{
intchoice1,choice2,min,max;
longsearchnum;
employeee;
cout<<"请选择查询方式:"<<endl;
cout<<"******************************************"<<endl;
cout<<"*输出全体职工信息---------------------1"<<endl;
cout<<"*按职工部门输出-----------------------2"<<endl;
cout<<"*按职工学历输出-----------------------3"<<endl;
cout<<"*按职工年龄输出-----------------------4"<<endl;
cout<<"*按职工编号输出-----------------------5"<<endl;
cout<<"******************************************"<<endl;
cin>>choice1;
switch(choice1)
{
case1:showall();break;
case2:cout<<"请输入要查询职工的部门编号:[1:董事会2:市场部3:公关部4:客服中心5:信息中心]";
cin>>choice2;
e.showdepart(choice2);break;
case3:cout<<"请输入要查询职工的学历编号:[1:初中2:高中3:本科4:硕士5:博士]";
cin>>choice2;
e.showdegree(choice2);break;
case4:cout<<"请输入要查询的年龄范围:";
cout<<"最小值:";
cin>>min;
cout<<"最大值:";
cin>>max;
e.showage(min,max);break;
case5:cout<<"请输入要查询的员工号:";
cin>>searchnum;
e.shownum(searchnum);break;
default:cout<<"出错啦!"<<endl;break;
}
}
voidemployee::showall()//全体员工输出函数
{inti;<br>longnumber;<br>for(i=0;i<employee::maxnum();i++)<br>{<br>number=enum[i];<br>shownum(number);<br>}
}
voidemployee::showdepart(intdepart)//按员工所在部门输出函数
{
inti;
switch(depart)
{
case1:cout<<"董事会的成员有:>"<<endl;break;
case2:cout<<"市场部的成员有:>"<<endl;break;
case3:cout<<"公关部的成员有:>"<<endl;break;
case4:cout<<"客服中心成员有:>"<<endl;break;
case5:cout<<"信息中心成员有:>"<<endl;break;
default:cout<<"输入错误!>"<<endl;break;
}
for(i=0;i<employee::maxnum();i++)
{
if(edepart[i]==depart)
{
longnumber=enum[i];
shownum(number);
}elsecontinue;
}
}
voidemployee::showdegree(intdegree)//按员工学历输出函数
{
inti;
switch(degree)
{
case1:cout<<"初中学历的员工有:"<<endl;break;
case2:cout<<"高中学历的员工有:"<<endl;break;
case3:cout<<"本科学历的员工有:"<<endl;break;
case4:cout<<"硕士学位的员工有:"<<endl;break;
case5:cout<<"博士学位的员工有:"<<endl;break;
}
for(i=0;i<employee::maxnum();i++)
{
if(edegree[i]==degree)
{
longnumber=enum[i];
shownum(number);
}elsecontinue;
}
}
voidemployee::showage(intmin,intmax)//按员工年龄段输出函数
{
inti;
for(i=0;i<employee::maxnum();i++)
{
if(eage[i]>=min&&eage[i]<=max)
{
longnumber=enum[i];
shownum(number);
}
elsecontinue;
}
}
voidemployee::shownum(longnumber)//按员工编号输出函数
{
inti;
for(i=0;i<employee::maxnum();i++)
{
if(enum[i]==number)
{
cout<<"**********************************"<<endl;
cout<<"员工编号>"<<enum[i]<<endl;
cout<<"姓名>"<<ename[i]<<endl;
cout<<"性别>";
if(esex[i]=='f')cout<<"女"<<endl;
elseif(esex[i]=='m')cout<<"男"<<endl;
cout<<"年龄>"<<eage[i]<<"岁"<<endl;
cout<<"婚姻情况>";
if(emarriage[i]=='y')cout<<"已婚"<<endl;
elseif(emarriage[i]=='n')cout<<"未婚"<<endl;
cout<<"学历>";
switch(edegree[i])
{
case1:cout<<"初中"<<endl;break;
case2:cout<<"高中"<<endl;break;
case3:cout<<"本科"<<endl;break;
case4:cout<<"硕士"<<endl;break;
case5:cout<<"博士"<<endl;break;
}
cout<<"所在部门>";
switch(edepart[i])
{
case1:cout<<"董事会"<<endl;break;
case2:cout<<"市场部"<<endl;break;
case3:cout<<"公关部"<<endl;break;
case4:cout<<"客服中心"<<endl;break;
case5:cout<<"信息中心"<<endl;break;
}
cout<<"所任职务>";
switch(eposition[i])
{
case1:cout<<"临时成员"<<endl;break;
case2:cout<<"正式员工"<<endl;break;
case3:cout<<"主任"<<endl;break;
case4:cout<<"部门经理"<<endl;break;
case5:cout<<"董事长"<<endl;break;
}
cout<<"工作时长>"<<eworktime[i]<<"小时"<<endl;
cout<<"额定工资>"<<epay[i]<<"元"<<endl;
cout<<"**********************************"<<endl;
}
elsecontinue;
}
}
voidemployee::refreshinfo()//修改员工信息的函数
{
intcnum=1000;
dboperatedbo;
dbo.readout();
voidemployee::shownum(longnumber);
cout<<"请输入您要修改的员工编号:>";
cin>>cnum;
intmn;
mn=employee::maxnum();
for(inti=0;i<mn;i++)//遍历数据文件,查找要修改的员工数据
{
if(enum[i]==cnum)
{
employee::shownum(cnum);
cout<<"请输入该员工的新信息:"<<endl;
cout<<"新员工姓名:";//录入员工的新的数据,员工号保持不变
cin>>employee::employeename;
ename[i]=employee::employeename;
cout<<"新员工性别:[f为女性,m为男性]:";
cin>>employee::employeesex;
esex[i]=employee::employeesex;
cout<<"新员工年龄:";
cin>>employee::employeeage;
eage[i]=employee::employeeage;
cout<<"新员工婚姻状况(y为已婚,n为未婚):";
cin>>employee::employeemarriage;
emarriage[i]=employee::employeemarriage;
cout<<"新员工学历,请输入相应学历的序号:"<<endl;
cout<<"[1:初中2:高中3:本科4:硕士5:博士]";
cin>>employee::employeedegree;
while(employee::employeedegree!=1&&employee::employeedegree!=2&&employee::employeedegree!=3&&employee::employeedegree!=4&&employee::employeedegree!=5)
{
cout<<"输入有误,请重新输入:"<<endl;
cout<<"[1:初中2:高中3:本科4:硕士5:博士]";
cin>>employee::employeedegree;
}
edegree[i]=employee::employeedegree;
cout<<"新员工所在部门,请输入相应部门的序号:"<<endl;
cout<<"[1:董事会2:市场部3:公关部4:客服中心5:信息中心]";
cin>>employee::employeedepart;
while(employee::employeedepart!=1&&employee::employeedepart!=2&&employee::employeedepart!=3&&employee::employeedepart!=4&&employee::employeedepart!=5)
{
cout<<"输入有误,请重新输入:"<<endl;
cout<<"[1:董事会2:市场部3:公关部4:客服中心5:信息中心]";
cin>>employee::employeedepart;
}
edepart[i]=employee::employeedepart;
cout<<"新员工职位,请输入相应职位的序号:"<<endl;
cout<<"[1:临时职员2:正式职员3:主任4:部门经理5:董事长]";
cin>>employee::employeeposition;
while(employee::employeeposition!=1&&employee::employeeposition!=2&&employee::employeeposition!=3&&employee::employeeposition!=4&&employee::employeeposition!=5)
{
cout<<"输入有误,请重新输
Ⅷ C语言 职工信息管理系统
/*这是我开始做课程设计时写的*/
#include "stdio.h" /*标准输入输出函数库*/
#include "stdlib.h" /*标准函数库*/
#include "string.h" /*字符串函数库*/
#include "conio.h" /*屏幕操作函数库*/
#define HEADER1 " -------------------------------ZGGZ---------------------------------------- \n"
#define HEADER2 "| number| name | jbgz | jj | kk | yfgz | sk | sfgz | \n"
#define HEADER3 "|--------|-----------|--------|--------|--------|--------|--------|--------| \n"
#define FORMAT "|%-8s|%-10s |%8.2f|%8.2f|%8.2f|%8.2f|%8.2f|%8.2f| \n"
#define DATA p->num,p->name,p->jbgz,p->jj,p->kk,p->yfgz,p->sk,p->sfgz
#define END "---------------------------------------------------------------------------- \n"
#define N 60
int saveflag=0; /*是否需要存盘的标志变量*/
/*定义与职工有关的数据结构*/
typedef struct employee /*标记为employee*/
{
char num[10]; /*职工编号*/
char name[15]; /*职工姓名*/
float jbgz; /*基本工资*/
float jj; /*奖金*/
float kk; /*扣款*/
float yfgz; /*应发工资*/
float sk; /*税款*/
float sfgz; /*实发工资*/
}ZGGZ;
void menu() /*主菜单*/
{
system("cls"); /*调用DOS命令,清屏.与clrscr()功能相同*/
textcolor(10); /*在文本模式中选择新的字符颜色*/
gotoxy(10,5); /*在文本窗口中设置光标*/
cprintf(" The Employee' Salary Management System \n");
gotoxy(10,8);
cprintf(" *************************Menu********************************\n");
gotoxy(10,9);
cprintf(" * 1 input record 2 delete record *\n");
gotoxy(10,10);
cprintf(" * 3 search record 4 modify record *\n");
gotoxy(10,11);
cprintf(" * 5 insert record 6 count record *\n");
gotoxy(10,12);
cprintf(" * 7 sort reord 8 save record *\n");
gotoxy(10,13);
cprintf(" * 9 display record 0 quit system *\n");
gotoxy(10,14);
cprintf(" *************************************************************\n");
/*cprintf()送格式化输出至文本窗口屏幕中*/
}
void printheader() /*格式化输出表头*/
{
printf(HEADER1);
printf(HEADER2);
printf(HEADER3);
}
void printdata(ZGGZ pp) /*格式化输出表中数据*/
{
ZGGZ* p;
p=&pp;
printf(FORMAT,DATA);
}
void Disp(ZGGZ tp[],int n) /*显示数组tp[]中存储的记录,内容为employee结构中定义的内容*/
{
int i;
if(n==0) /*表示没有职工工资记录*/
{
printf("\n=====>Not employee record!\n");
getchar();
return;
}
printf("\n\n");
printheader(); /*输出表格头部*/
i=0;
while(i<n) /*逐条输出数组中存储的职工信息*/
{
printdata(tp[i]);
i++;
printf(HEADER3);
}
getchar();
}
void Wrong() /*输出按键错误信息*/
{
printf("\n\n\n\n\n***********Error:input has wrong! press any key to continue**********\n");
getchar();
}
void Nofind() /*输出未查找此职工的信息*/
{
printf("\n=====>Not find this employee record!\n");
}
/*************************************************************
作用:用于定位数组中符合要求的记录,并返回保存该记录的数组元素下标值
参数:findmess[]保存要查找的具体内容; nameornum[]保存按什么在数组中查找;
**************************************************************/
int Locate(ZGGZ tp[],int n,char findmess[],char nameornum[])
{
int i=0;
if(strcmp(nameornum,"num")==0) /*按职工编号查询*/
{
while(i<n)
{
if(strcmp(tp[i].num,findmess)==0) /*若找到findmess值的职工编号*/
return i;
i++;
}
}
else if(strcmp(nameornum,"name")==0) /*按职工姓名查询*/
{
while(i<n)
{
if(strcmp(tp[i].name,findmess)==0) /*若找到findmess值的姓名*/
return i;
i++;
}
}
return -1; /*若未找到,返回一个整数-1*/
}
/*输入字符串,并进行长度验证(长度<lens)*/
void stringinput(char *t,int lens,char *notice)
{
char n[255];
do{
printf(notice); /*显示提示信息*/
scanf("%s",n); /*输入字符串*/
if(strlen(n)>lens) printf("\n exceed the required length! \n"); /*进行长度校验,超过lens值重新输入*/
}while(strlen(n)>lens);
strcpy(t,n); /*将输入的字符串拷贝到字符串t中*/
}
/*输入数值,0<=数值)*/
float numberinput(char *notice)
{
float t=0.00;
do{
printf(notice); /*显示提示信息*/
scanf("%f",&t); /*输入如工资等数值型的值*/
if(t<0) printf("\n score must >=0! \n"); /*进行数值校验*/
}while(t<0);
return t;
}
/*增加职工工资记录*/
int Add(ZGGZ tp[],int n)
{
char ch,num[10];
int i,flag=0;
system("cls");
Disp(tp,n); /*先打印出已有的职工工资信息*/
while(1) /*一次可输入多条记录,直至输入职工编号为0的记录才结束添加操作*/
{
while(1) /*输入职工编号,保证该编号没有被使用,若输入编号为0,则退出添加记录操作*/
{
stringinput(num,10,"input number(press '0'return menu):"); /*格式化输入编号并检验*/
flag=0;
if(strcmp(num,"0")==0) /*输入为0,则退出添加操作,返回主界面*/
{return n;}
i=0;
while(i<n) /*查询该编号是否已经存在,若存在则要求重新输入一个未被占用的编号*/
{
if(strcmp(tp[i].num,num)==0)
{
flag=1;
break;
}
i++;
}
if(flag==1) /*提示用户是否重新输入*/
{ getchar();
printf("==>The number %s is existing,try again?(y/n):",num);
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
continue;
else
return n;
}
else
{break;}
}
strcpy(tp[n].num,num); /*将字符串num拷贝到tp[n].num中*/
stringinput(tp[n].name,15,"Name:");
tp[n].jbgz=numberinput("jbgz:"); /*输入并检验基本工资*/
tp[n].jj=numberinput("jiangjin:"); /*输入并检验奖金*/
tp[n].kk=numberinput("koukuan:"); /*输入并检验扣款*/
tp[n].yfgz=tp[n].jbgz+tp[n].jj-tp[n].kk; /*计算应发工资*/
tp[n].sk=tp[n].yfgz*0.12; /*计算税金,这里取应发工资的百分之一十二*/
tp[n].sfgz=tp[n].yfgz-tp[n].sk; /*计算实发工资*/
saveflag=1;
n++;
}
return n;
}
/*按职工编号或姓名,查询记录*/
void Qur(ZGGZ tp[],int n)
{
int select; /*1:按编号查,2:按姓名查,其他:返回主界面(菜单)*/
char searchinput[20]; /*保存用户输入的查询内容*/
int p=0;
if(n<=0) /*若数组为空*/
{
system("cls");
printf("\n=====>No employee record!\n");
getchar();
return;
}
system("cls");
printf("\n =====>1 Search by number =====>2 Search by name\n");
printf(" please choice[1,2]:");
scanf("%d",&select);
if(select==1) /*按编号查询*/
{
stringinput(searchinput,10,"input the existing employee number:");
p=Locate(tp,n,searchinput,"num");/*在数组tp中查找编号为searchinput值的元素,并返回该数组元素的下标值*/
if(p!=-1) /*若找到该记录*/
{
printheader();
printdata(tp[p]);
printf(END);
printf("press any key to return");
getchar();
}
else
Nofind();
getchar();
}
else if(select==2) /*按姓名查询*/
{
stringinput(searchinput,15,"input the existing employee name:");
p=Locate(tp,n,searchinput,"name");
if(p!=-1)
{
printheader();
printdata(tp[p]);
printf(END);
printf("press any key to return");
getchar();
}
else
Nofind();
getchar();
}
else
Wrong();
getchar();
}
/*删除记录:先找到保存该记录的数组元素的下标值,然后在数组中删除该数组元素*/
int Del(ZGGZ tp[],int n)
{
int sel;
char findmess[20];
int p=0,i=0;
if(n<=0)
{ system("cls");
printf("\n=====>No employee record!\n");
getchar();
return n;
}
system("cls");
Disp(tp,n);
printf("\n =====>1 Delete by number =====>2 Delete by name\n");
printf(" please choice[1,2]:");
scanf("%d",&sel);
if(sel==1)
{
stringinput(findmess,10,"input the existing employee number:");
p=Locate(tp,n,findmess,"num");
getchar();
if(p!=-1)
{
for(i=p+1;i<n;i++) /*删除此记录,后面记录向前移*/
{
strcpy(tp[i-1].num,tp[i].num);
strcpy(tp[i-1].name,tp[i].name);
tp[i-1].jbgz=tp[i].jbgz;
tp[i-1].jj=tp[i].jj;
tp[i-1].kk=tp[i].kk;
tp[i-1].yfgz=tp[i].yfgz;
tp[i-1].jbgz=tp[i].sk;
tp[i-1].sfgz=tp[i].sfgz;
}
printf("\n==>delete success!\n");
n--;
getchar();
saveflag=1;
}
else
Nofind();
getchar();
}
else if(sel==2) /*先按姓名查询到该记录所在的数组元素的下标值*/
{
stringinput(findmess,15,"input the existing employee name:");
p=Locate(tp,n,findmess,"name");
getchar();
if(p!=-1)
{
for(i=p+1;i<n;i++) /*删除此记录,后面记录向前移*/
{
strcpy(tp[i-1].num,tp[i].num);
strcpy(tp[i-1].name,tp[i].name);
tp[i-1].jbgz=tp[i].jbgz;
tp[i-1].jj=tp[i].jj;
tp[i-1].kk=tp[i].kk;
tp[i-1].yfgz=tp[i].yfgz;
tp[i-1].jbgz=tp[i].sk;
tp[i-1].sfgz=tp[i].sfgz;
}
printf("\n=====>delete success!\n");
n--;
getchar();
saveflag=1;
}
else
Nofind();
getchar();
}
return n;
}
/*修改记录。先按输入的职工编号查询到该记录,然后提示用户修改编号之外的值,编号不能修改*/
void Modify(ZGGZ tp[],int n)
{
char findmess[20];
int p=0;
if(n<=0)
{ system("cls");
printf("\n=====>No employee record!\n");
getchar();
return ;
}
system("cls");
printf("modify employee recorder");
Disp(tp,n);
stringinput(findmess,10,"input the existing employee number:"); /*输入并检验该编号*/
p=Locate(tp,n,findmess,"num"); /*查询到该数组元素,并返回下标值*/
if(p!=-1) /*若p!=-1,表明已经找到该数组元素*/
{
printf("Number:%s,\n",tp[p].num);
printf("Name:%s,",tp[p].name);
stringinput(tp[p].name,15,"input new name:");
printf("jbgz:%8.2f,",tp[p].jbgz);
tp[p].jbgz=numberinput("jbgz:");
printf("jiangjin:%8.2f,",tp[p].jj);
tp[p].jj=numberinput("jiangjin:");
printf("koukuan:%8.2f,",tp[p].kk);
tp[p].kk=numberinput("koukuan:");
tp[n].yfgz=tp[n].jbgz+tp[n].jj-tp[n].kk;
tp[n].sk=tp[n].yfgz*0.12;
tp[n].sfgz=tp[n].yfgz-tp[n].sk;
printf("\n=====>modify success!\n");
getchar();
Disp(tp,n);
getchar();
saveflag=1;
}
else
{Nofind();
getchar();
}
return ;
}
/*插入记录:按职工编号查询到要插入的数组元素的位置,然后在该编号之后插入一个新数组元素。*/
int Insert(ZGGZ tp[],int n)
{
char ch,num[10],s[10]; /*s[]保存插入点位置之前的编号,num[]保存输入的新记录的编号*/
ZGGZ newinfo;
int flag=0,i=0,kkk=0;
system("cls");
Disp(tp,n);
while(1)
{ stringinput(s,10,"please input insert location after the Number:");
flag=0;i=0;
while(i<n) /*查询该编号是否存在,flag=1表示该编号存在*/
{
if(strcmp(tp[i].num,s)==0) {kkk=i;flag=1;break;}
i++;
}
if(flag==1)
break; /*若编号存在,则进行插入之前的新记录输入操作*/
else
{ getchar();
printf("\n=====>The number %s is not existing,try again?(y/n):",s);
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
{continue;}
else
{return n;}
}
}
/*以下新记录的输入操作与Add()相同*/
while(1)
{ stringinput(num,10,"input new employee Number:");
i=0;flag=0;
while(i<n) /*查询该编号是否存在,flag=1表示该编号存在*/
{
if(strcmp(tp[i].num,num)==0) {flag=1;break;}
i++;
}
if(flag==1)
{
getchar();
printf("\n=====>Sorry,The number %s is existing,try again?(y/n):",num);
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
{continue;}
else
{return n;}
}
else
break;
}
strcpy(newinfo.num,num); /*将字符串num拷贝到newinfo.num中*/
stringinput(newinfo.name,15,"Name:");
newinfo.jbgz=numberinput("jbgz:"); /*输入并检验jbgz*/
newinfo.jj=numberinput("jiangjin:"); /*输入并检验jiangjin*/
newinfo.kk=numberinput("koukuan:"); /*输入并检验koukuan*/
newinfo.yfgz=newinfo.jbgz+newinfo.jj-newinfo.kk; /*计算yfgz*/
newinfo.sk=newinfo.yfgz*0.12; /*计算sk*/
newinfo.sfgz=newinfo.yfgz-newinfo.sk;
saveflag=1; /*在main()有对该全局变量的判断,若为1,则进行存盘操作*/
for(i=n-1;i>kkk;i--) /*从最后一个组织元素开始往向移一个元素位置*/
{ strcpy(tp[i+1].num,tp[i].num);
strcpy(tp[i+1].name,tp[i].name);
tp[i+1].jbgz=tp[i].jbgz;
tp[i+1].jj=tp[i].jj;
tp[i+1].kk=tp[i].kk;
tp[i+1].yfgz=tp[i].yfgz;
tp[i+1].sk=tp[i].sk;
tp[i+1].sfgz=tp[i].sfgz;
}
strcpy(tp[kkk+1].num,newinfo.num); /*在kkk的元素位置后插入新记录*/
strcpy(tp[kkk+1].name,newinfo.name);
tp[kkk+1].jbgz=newinfo.jbgz;
tp[kkk+1].jj=newinfo.jj;
tp[kkk+1].kk=newinfo.kk;
tp[kkk+1].yfgz=newinfo.yfgz;
tp[kkk+1].sk=newinfo.sk;
tp[kkk+1].sfgz=newinfo.sfgz;
n++;
Disp(tp,n);
printf("\n\n");
getchar();
return n;
}
/*统计公司的员工的工资在各等级的人数*/
void Tongji(ZGGZ tp[],int n)
{
int count10000=0,count5000=0,count2000=0,count0=0;
int i=0;
if(n<=0)
{ system("cls");
printf("\n=====>Not employee record!\n");
getchar();
return ;
}
system("cls");
Disp(tp,n);
i=0;
while(i<n)
{
if(tp[i].sfgz>=10000) {count10000++;i=i+1;continue;} /*实发工资>10000*/
if(tp[i].sfgz>=5000) {count5000++;i=i+1;continue;} /*5000<=实发工资<10000*/
if(tp[i].sfgz>=2000) {count2000++;i=i+1;continue;} /*2000<=实发工资<5000*/
if(tp[i].sfgz<2000) {count0++;i=i+1;continue;} /*实发工资<2000*/
}
printf("\n------------------------------the TongJi result--------------------------------\n");
printf("sfgz>= 10000:%d (ren)\n",count10000);
printf("5000<=sfgz<10000:%d (ren)\n",count5000);
printf("2000<=sfgz< 5000:%d (ren)\n",count2000);
printf("sfgz< 2000:%d (ren)\n",count0);
printf("-------------------------------------------------------------------------------\n");
printf("\n\npress any key to return");
getchar();
}
/*利用冒泡排序法实现数组的按实发工资字段的降序排序,从高到低*/
void Sort(ZGGZ tp[],int n)
{
int i=0,j=0,flag=0;
ZGGZ newinfo;
if(n<=0)
{ system("cls");
printf("\n=====>Not employee record!\n");
getchar();
return ;
}
system("cls");
Disp(tp,n); /*显示排序前的所有记录*/
for(i=0;i<n;i++)
{
flag=0;
for(j=0;j<n-1;j++)
if((tp[j].sfgz<tp[j+1].sfgz))
{ flag=1;
strcpy(newinfo.num,tp[j].num); /*利用结构变量newinfo实现数组元素的交换*/
strcpy(newinfo.name,tp[j].name);
newinfo.jbgz=tp[j].jbgz;
newinfo.jj=tp[j].jj;
newinfo.kk=tp[j].kk;
newinfo.yfgz=tp[j].yfgz;
newinfo.sk=tp[j].sk;
newinfo.sfgz=tp[j].sfgz;
strcpy(tp[j].num,tp[j+1].num);
strcpy(tp[j].name,tp[j+1].name);
tp[j].jbgz=tp[j+1].jbgz;
tp[j].jj=tp[j+1].jj;
tp[j].kk=tp[j+1].kk;
tp[j].yfgz=tp[j+1].yfgz;
tp[j].sk=tp[j+1].sk;
tp[j].sfgz=tp[j+1].sfgz;
strcpy(tp[j+1].num,newinfo.num);
strcpy(tp[j+1].name,newinfo.name);
tp[j+1].jbgz=newinfo.jbgz;
tp[j+1].jj=newinfo.jj;
tp[j+1].kk=newinfo.kk;
tp[j+1].yfgz=newinfo.yfgz;
tp[j+1].sk=newinfo.sk;
tp[j+1].sfgz=newinfo.sfgz;
}
if(flag==0) break;/*若标记flag=0,意味着没有交换了,排序已经完成*/
}
Disp(tp,n); /*显示排序后的所有记录*/
saveflag=1;
printf("\n =====>sort complete!\n");
}
/*数据存盘,若用户没有专门进行此操作且对数据有修改,在退出系统时, 会提示用户存盘*/
void Save(ZGGZ tp[],int n)
{
FILE* fp;
int i=0;
fp=fopen("c:\\zggz","wb");/*以只写方式打开二进制文件*/
if(fp==NULL) /*打开文件失败*/
{
printf("\n=====>open file error!\n");
getchar();
return ;
}
for(i=0;i<n;i++)
{
if(fwrite(&tp[i],sizeof(ZGGZ),1,fp)==1)/*每次写一条记录或一个结构数组元素至文件*/
{
continue;
}
else
{
break;
}
}
if(i>0)
{
getchar();
printf("\n\n=====>save file complete,total saved's record number is:%d\n",i);
getchar();
saveflag=0;
}
else
{system("cls");
printf("the current link is empty,no employee record is saved!\n");
getchar();
}
fclose(fp); /*关闭此文件*/
}
void main()
{
ZGGZ gz[N]; /*定义ZGGZ结构体*/
FILE *fp; /*文件指针*/
int select; /*保存选择结果变量*/
char ch; /*保存(y,Y,n,N)*/
int count=0; /*保存文件中的记录条数(或元素个数)*/
fp=fopen("C:\\zggz","ab+");
/*以追加方式打开二进制文件c:\zggz,可读可写,若此文件不存在,会创建此文件*/
if(fp==NULL)
{
printf("\n=====>can not open file!\n");
exit(0);
}
while(!feof(fp))
{
if(fread(&gz[count],sizeof(ZGGZ),1,fp)==1) /*一次从文件中读取一条职工工资记录*/
count++;
}
fclose(fp); /*关闭文件*/
printf("\n==>open file sucess,the total records number is : %d.\n",count);
getchar();
menu();
while(1)
{
system("cls");
menu();
printf("\n Please Enter your choice(0~9):"); /*显示提示信息*/
scanf("%d",&select);
if(select==0)
{
if(saveflag==1) /*若对数组的数据有修改且未进行存盘操作,则此标志为1*/
{ getchar();
printf("\n==>Whether save the modified record to file?(y/n):");
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
Save(gz,count);
}
printf("\n===>thank you for useness!");
getchar();
break;
}
switch(select)
{
case 1:count=Add(gz,count);break; /*增加职工工资记录*/
case 2:count=Del(gz,count);break; /*删除职工工资记录*/
case 3:Qur(gz,count);break; /*查询职工工资记录*/
case 4:Modify(gz,count);break; /*修改职工工资记录*/
case 5:count=Insert(gz,count);break; /*插入职工工资记录*/
case 6:Tongji(gz,count);break; /*统计职工工资记录*/
case 7:Sort(gz,count);break; /*排序职工工资记录*/
case 8:Save(gz,count);break; /*保存职工工资记录*/
case 9:system("cls");Disp(gz,count);break; /*显示职工工资记录*/
default: Wrong();getchar();break; /*按键有误,必须为数值0-9*/
}
}
}
Ⅸ 职工信息管理系统.c语言
#include<string.h>
void menu()
{
int n,w1;
do
{
printf("\t\t************************************************\n\n");
printf("\t\t************************************************\n\n");
printf("\t\t *** choose function ************\n\n");
printf("\t\t *** 1 Enter new data ************\n\n");
printf("\t\t *** 2 Modify data ************\n\n");
printf("\t\t *** 3 Search by people.xueli and num*****\n\n");
printf("\t\t *** 4 Browse data ************\n\n");
printf("\t\t *** 5 add data ************\n\n");
printf("\t\t *** 6 Exit ************\n\n");
printf("\t\t************************************************\n\n");
printf("\t\t************************************************\n\n");
printf("Choose your number(1-6):[ ]\b\b");
scanf("%d",&n);
if(n<1||n>6)
w1=1;
else w1=0;
}
while(w1==1);
switch(n)
{
case 1:enter();break;
case 2:modify();break;
case 3:search();break;
case 4:browse();break;
case 5:add();break;
case 6:exit(0);
}
}
main()
{
system("cls");
menu();
}
#define N 100
struct people
{
char num[100];
char name[15];
char sex[20];
char age[20];
char xueli[20];
char gong[20];
char address[20];
char telephone[20];
}people[N];
# include <stdio.h>
enter()
{
int i,n;
printf("How many people(0-%d)?:",N-1);
scanf("%d",&n);
printf("\n Enter data now\n\n");
for(i=0;i<n;i++)
{
printf("\n Input %dth people record.\n",i+1);
input(i);
}
if(i!=0)save(n);
printf_back();
}
browse()
{
int i,j,n;
n=load();
printf_face();
for(i=0;i<n;i++)
{
if((i!=0)&&(i%10==0))
{
printf("\n\nPass any key to continue ....");
getch();
puts("\n\n");
}
printf_one(i) ;
}
printf("\tThere are %d record.\n",n);
printf("\nPass any key to back ...");
getch();
menu();
}
add()
{
int i,n,m,k;
FILE*fp;
n=load();
printf("How many people are you want to add(0-%d)?:",N-1-n);
scanf("%d",&m);
k=m+n;
for(i=n;i<k;i++)
{
printf("\nInput %dth people record.\n",i-n+1 );
input(i);
}
if((fp=fopen("Pro.txt","ab"))==NULL)
{
printf("cannot open file\n");
}
for(i=n;i<k;i++)
if(fwrite(&people[i],sizeof(struct people),1,fp)!=1)
printf("file write error\n");
fclose(fp);
printf_back();
}
search()
{
int i,n,k,w1=1,w2,w3,w4,m,a;
struct people p;
n=load();
do
{
printf("\n\nWhich way do you want to choose? \n\t1).By xueli 2).By num [ ]\b\b");
scanf("%d",&m);
switch(m)
{
case 1:
do
{ k=-1;
printf("\n\nEnter xeuli that you want to search! xueli.");
scanf("%s",p.xueli);
printf_face();
for(i=0;i<n;i++)
if(strcmp(p.xueli,people[i].xueli)==0)
{ k=i;
printf_one(k);break;
}
if(k==-1)
{ printf("\n\nNO exist!please");
printf("\n\nAre you again?\n\t1).again 2).NO and back [ ]\b\b");
scanf("%d",&w1);
if(w1==2)
printf_back();
}
}
while(k==-1&&w1==1);break;
case 2:
do
{k=-1;
printf("\n\nEnter num that you want to search! num.");
scanf("%s",p.num);
printf_face();
for(i=0;i<n;i++)
if(strcmp(p.num,people[i].num)==0)
{k=i;
printf_one(k);break;
}
if(k==-1)
{printf("\n\nNO exist!please");
printf("\n\nAre you again?\n\t1).again 2).NO and back [ ]\b\b");
scanf("%d",&w1);
if(w1==2)
printf_back();
}
}
while(k==-1&&w1==1);break;
}
w4=0;w3=0;
if(k!=-1)
{printf("\n\nWhat do you want to do?\n\t 1).Search 2).Modify 3).Delete 4).Back menu [ ]\b\b");
scanf("%d",&w2);
switch(w2)
{case 2:w3=modify_data(k,n);break;
case 3:{printf("\nAre you sure?\n\t 1).Sure 2).No and back [ ]\b\b");
scanf("%d",&w4);
if(w4==1)
for(a=k;a<n;a++)
{strcpy(people[a].num,people[a+1].num);
strcpy(people[a].name,people[a+1].name);
strcpy(people[a].sex,people[a+1].sex);
strcpy(people[a].age,people[a+1].age);
strcpy(people[a].xueli,people[a+1].xueli);
strcpy(people[a].gong,people[a+1].gong);
strcpy(people[a].address,people[a+1].address);
strcpy(people[a].telephone,people[a+1].telephone);
}
break;
}
}
if(w3==1||w4==1)
{save(n);
printf("\n\nSuccessful.^_^.");
printf("\n\nWhant do you want to do? \n\t 1).Search another 2).Back [ ]\b\b" );
scanf("%d",&w2);
}
}
}
while(w2==1);
menu();
}
modify()
{struct people p;
FILE *fp;
int i,n,k,w0=1,w1,w2=0;
n=load();
do
{
k=-1;
printf_face();
for(i=0;i<n;i++)
{if((i!=0)&&(i%10==0))
{printf("\n\nRemember NO.which needed modify.pass any key to contiune ...");
getch();
puts("\n\n");
}
printf_one(i);
}
do
{printf("\n\nEnter NO.that you want to modify! NO.:");
scanf("%s",p.num);
for(i=0;i<n;i++)
if(strcmp(p.num,people[i].num)==0)
{k=i;
p=people[i];
}
if(k==-1)printf("\n\nNO exist!please again");
}while(k==-1);
printf_face();
printf_one(k);
w1=modify_data(k,n);
if(w1==1)
{printf("\nSuccessful ^_^.\n\nAre you modify another ?\n\n\t 1).Yes 2).Back with save\t[ ]\b\b");
scanf("%d",&w0);
w2=1;
}
else
{w0=0;
if(w2==1)
people[k]=p;
}
if(w0!=1&&w2==1)
save(n);
}while(w0==1);
menu();
}
save(int n)
{FILE *fp;
int i;
if((fp=fopen("Pro.txt","wb"))==NULL)
{printf("\nCannot open file\n");
return NULL;
}
for(i=0;i<n;i++)
if(people[i].num!=0)
if(fwrite(&people[i],sizeof(struct people),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
load()
{FILE *fp;
int i;
if((fp=fopen("Pro.txt","rb"))==NULL)
{printf("\nCannot open file\n");
return NULL;
}
for(i=0;!feof(fp);i++)
fread(&people[i],sizeof(struct people),1,fp);
fclose(fp);
return(i-1);
}
input(int i)
{
no_input(i,i);
printf("num:");
scanf("%s",people[i].num);
printf("name:");
scanf("%s", people[i].name) ;
printf("sex:");
scanf("%s",people[i].sex);
printf("age:");
scanf("%s",people[i].age);
printf("xueli:");
scanf("%s",people[i].xueli);
printf("gong:");
scanf("%s",people[i].gong);
printf("address:");
scanf("%s",people[i].address);
printf("telephone:");
scanf("%s",people[i].telephone);
}
modify_data(int i)
{int c,w1;
do
{puts("\nmodify by=>\n\n 1).num 2).name 3).sex 4).ages 5).xueli 6)gong 7)address 8)telephone ");
printf("Which you needed?:[ ]\b\b");
scanf("%d",&c);
if(c>8||c<1)
{puts("\nChoice error!Please again!");
getchar();
}
}while(c>8||c<1);
do
{switch(c)
{
case 1:printf("num:");scanf("%s",people[i].num);break;
case 2:printf("name:");scanf("%s",people[i].name);break;
case 3:printf("sex:");scanf("%s",people[i].sex);break;
case 4:printf("age:");scanf("%s",people[i].age);break;
case 5:printf("xueli:");scanf("%s",people[i].xueli);break;
case 6:printf("gong:");scanf("%s",people[i].gong);break;
case 7:printf("address:");scanf("%s",people[i].address);break;
case 8:printf("telephone:");scanf("%s",people[i].telephone);break;
}
puts("\nNow:\n");
printf_face();
printf_one(i);
printf("\nAre you sure?\n\n\t 1).Sure 2).No and remodify 3).Back without save in this time [ ]\b\b");
scanf("%d",&w1);
}
while(w1==2);
return(w1);
}
no_input(int i,int n)
{int j,k,w1;
do
{w1=0;
for(j=0;people[i].num[j]!='\0';j++)
if(people[i].num[j]>'9')
{puts("Input error!Only be made up of(0-9).Please reinput!\n");
w1=1;break;
}
if(w1!=1)
for(k=0;k<n;k++)
if(k!=i&&strcmp(people[k].num,people[i].num)==0)
{puts("This record is exist.please reinput!\n");
}
}
while(w1==1);
}
printf_face()
{
printf("\nnum name sex ages xueli gong address telephone \n");
}
printf_one(int i)
{
int j;
printf("%7s%7s%7s%7s%7s%7s%10s%12s\n",people[i].num,people[i].name,people[i].sex,people[i].age,people
[i].xueli,people[i].gong,people[i].address,people[i].telephone);
}
printf_back()
{
int j,w;
printf("\n\n\tSuccessful.^_^\n\n");
printf("What do you want you to do?\n\n\t1).Browse all now\t2).Back: [ ]\b\b");
scanf("%d",&w);
if(w==1)
browse();
else menu();
}
Ⅹ 用c语言编写设计,职工信息管理系统。
我给你个大概提示吧,
首先你要做的是个大体的框架
分三个权限一是管理员权限,人事部门权限以及员工权限。
1.管理员权限实现包括员工基本信息增删改查功能。
2.人事权限包括员工拓展信息,比如工资,奖金等等数据的维护和更新。
3.员工权限包括个人信息查询以及问题反馈。
三个双向链表,节点数据存入以上所有信息。
链表操作不多说了吧。。。
文件读写问题,这里考虑到如果是一般情况的话直接调用readwrite函数就行了
如果内容过多还是连接数据库吧。
系统开始的初始化和更新也很重要。