哪位大神能帮我用c语言写个程序,是职工工资管理系统的,要求如下: 80
将10名职工的数据(职工号、职工名、性别、年龄、工资)从键盘输入,然后送到磁盘文件worker1.dat中保存起来。(1)从磁盘文件中读出这些数据,依次打印出来。(2)对...
将10名职工的数据(职工号、职工名、性别、年龄、工资)从键盘输入,然后送到磁
盘文件worker1.dat中保存起来。
(1) 从磁盘文件中读出这些数据,依次打印出来。
(2) 对职工数据按工资高低排序,将排好序的各记录存放在文件worker2.dat中。
(3) 将职工号为单数和偶数的职工信息分别存放另两个磁盘文件worker3.dat和worker4.dat中,并从这两个文件中读出职工信息在显示器上显示出来。 展开
盘文件worker1.dat中保存起来。
(1) 从磁盘文件中读出这些数据,依次打印出来。
(2) 对职工数据按工资高低排序,将排好序的各记录存放在文件worker2.dat中。
(3) 将职工号为单数和偶数的职工信息分别存放另两个磁盘文件worker3.dat和worker4.dat中,并从这两个文件中读出职工信息在显示器上显示出来。 展开
1个回答
2013-05-17
展开全部
分数太低了。这个不好做啊。
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <conio.h>
#define N 2
typedef struct Workers
{
int id;
char name[9];
char sex;
int age;
int sal;
struct Workers *next;
} worker;
worker *head;
int odd=0,even=0;
void initList()
{
head=(worker *)malloc(sizeof(worker));
head->next=NULL;
}
void getMsg()
{
int i;
worker *newD,*p=head;
while(p->next)
{
p=p->next;
}
for(i=0;i<N;i++)
{
newD=(worker *)malloc(sizeof(worker));
newD->next=NULL;
printf("please enter date\nid name sex age salary \n");
scanf("%d %s %c %d %d",&newD->id,newD->name,&newD->sex,&newD->age,&newD->sal);
p->next=newD;
p=p->next;
}
}
void saveData()
{
FILE *fpwd,*fpwo;
worker *p=head;
FILE *fp=fopen("output.txt","wb+");
fpwd=fopen("worker3.txt","wb+");
fpwo=fopen("worker4.txt","wb+");
odd=even=0;
while(p->next)
{
p=p->next;
fwrite(p,sizeof(worker),1,fp);
if(p->id%2==0){
even++;
fwrite(p,sizeof(worker),1,fpwo);}
else{
even++;
fwrite(p,sizeof(worker),1,fpwd);}
}
fclose(fp);
fclose(fpwd);
fclose(fpwo);
}
void readData()
{
FILE *fp;int i;
worker *p,*newD;
p=head;
fp=fopen("output.txt","rb+");
while(p->next)
{
p=p->next;
}
for(i=0;i<N;i++)
{
newD=(worker *)malloc(sizeof(worker));
newD->next=NULL;
fread(newD,sizeof(worker),1,fp);
p->next=newD;
p=p->next;
}
fclose(fp);
}
void showodd()
{
FILE *fp;int i;
fp=fopen("worker3.txt","rb+");
printf("以下为奇数\n");
while(!feof(fp))
{
worker date;
fread(&date,sizeof(worker),1,fp);
printf("%d %s %c %d %d\n",date.id,date.name,date.sex,date.age,date.sal);
}
fclose(fp);
}
void showeven()
{
FILE *fp;int i;
fp=fopen("worker4.txt","rb+");
printf("以下为偶数\n");
while(!feof(fp))
{
worker date;
fread(&date,sizeof(worker),1,fp);
printf("%d %s %c %d %d\n",date.id,date.name,date.sex,date.age,date.sal);
}
fclose(fp);
}
void main()
{
while(1){
worker *p;
char ch;
initList();
p=head;
printf("\nplease select 1,2,others \n");
ch=getch();
if(ch=='1')
{
getMsg();
saveData();
}
else if(ch=='2')
{
readData();
while(p->next)
{
p=p->next;
printf("%d %s %c %d %d\n",p->id,p->name,p->sex,p->age,p->sal);
}
}
else
{
printf("are u need to show odd and even \n");
ch=getch();
if(ch=='1')
{
showodd();
showeven();
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询