C语言大作业——教师工资管理系统
主要的难点在于文件读取
数据结构用的是链表
源码放上,直接粘贴复制就可以,我的C程大作业
具体的问题不懂的可以评论和私信,总之还是简单的
放张图片
程序设计报告可以私信我
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
typedef struct teach{
int number;
char name[10];
char sex[4];
char unit[10];
char address[15];
char phone[11];
float salary;
float allowance;
float life;
float shouldPay;
float telBill;
float waterBill;
float rent;
float income_tax;
float cleanBill;
float fund;
float total_deduct;
float realPay;
struct teach* next;
}teach;
teach *head=NULL;
FILE *fp;
teach * number();
teach * name();
void show(teach *pr);
void show_all();
void read_file();
void kill(teach *pr);
void save();
void menu();
void add();
void change(teach *pr);
void revise();
void search();
void dele();
int test_number(int a);
int main()
{
read_file();
menu();
}
int test_number(int a)
{
int t=1,f=0;
teach *p;
if(head==NULL)
{
return f;
}
else
{
p=head;
while(p->number!=a)
{
p=p->next;
if(p==NULL)
return f;
}
printf("教师号已存在,请重新输入\n");
return t;
}
}
void save()//存档
{
char filename[]="teacher.txt";
fp=fopen(filename,"w");
if(head==NULL)
{
}
else
{
teach *p=head;
while(p!=NULL)
{
fprintf(fp,"%s,%s,%s,%s,%s,%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",p->name,p->sex,p->unit,p->address,p->phone,p->number,p->salary,p->allowance,p->life,p->shouldPay
,p->telBill,p->waterBill,p->rent,p->income_tax,p->cleanBill,p->fund,p->total_deduct,p->realPay);
p=p->next;
}
}
fclose(fp);
}
void read_file()//文件读取
{
char filename[]="teacher.txt";
fp=fopen(filename,"r+");
if(fp==NULL)
{
fp=fopen(filename,"w");
if(fp==NULL)
printf("\n\t文件创建失败");
}
else
{
int k,l=0,c=0;
while((k=fgetc(fp))!=EOF)
{
if(k=='\n')
{
if(c!=1)
l++;}
c++;
}
int number;
char name[10];
char sex[4];
char unit[10];
char address[15];
char phone[11];
float salary;
float life;
float allowance;
float shouldPay;
float telBill;
float waterBill;
float rent;
float income_tax;
float cleanBill;
float fund;
float total_deduct;
float realPay;
teach *p=(teach *)malloc(sizeof(teach));
rewind(fp);
for(int i=0;i<l;i++)
{
fscanf(fp,"%[^,],%[^,],%[^,],%[^,],%[^,],%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n",name,sex,unit,address,phone,&number,&salary,&allowance,&life,&shouldPay
,&telBill,&waterBill,&rent,&income_tax,&cleanBill,&fund,&total_deduct,&realPay);
teach *pn=(teach *)malloc(sizeof(teach));
pn->number=number;
strcpy(pn->name,name);
strcpy(pn->sex,sex);
strcpy(pn->unit,unit);
strcpy(pn->address,address);
strcpy(pn->phone,phone);
pn->salary=salary;
pn->life=life;
pn->allowance=allowance;
pn->shouldPay=shouldPay;
pn->telBill=telBill;
pn->waterBill=waterBill;
pn->rent=rent;
pn->income_tax=income_tax;
pn->cleanBill=cleanBill;
pn->fund=fund;
pn->total_deduct=total_deduct;
pn->realPay=realPay;
pn->next=NULL;
p->next=pn;
p=pn;
if(head==NUL