C语言程序设计期末大作业—教师工资管理系统(附程序设计报告)

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
  • 39
    点赞
  • 146
    收藏
    觉得还不错? 一键收藏
  • 42
    评论
评论 42
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值