课程设计报告学院:天津理工大学华信软件学院专业名称:软件工程课程设计科目C语言课程设计所在班级:一班学生学号:20105945学生姓名:吴健指导教师:陈立娜完成时间:2011年4月-6月教师工资管理系统每个教师的信息为:教师号、姓名、性别、单位名称、家庭住址、联系、基本工资、津贴、生活补贴、应发工资、费、水电费、房租、所得税、卫生费、公积金、合计扣款、实发工资注:应发工资=基本工资+津贴+生活补贴;合计扣款=费+水电费+房租+所得税+卫生费+公积金;实发工资=应发工资-合计扣款A、教师信息处理(1)输入教师信息 (2) 插入(修改)教师信息:(3) 删除教师信息:(4) 浏览教师信息: 提示:具体功能及操作参考题1B、教师数据处理:(1) 按教师号录入教师基本工资、津贴、生活补贴、费、水电费、房租、所得税、卫生费、公积金等基本数据2) 教师实发工资、应发工资、合计扣款计算 提示:计算规则如题目3) 教师数据管理 提示:输入教师号,读出并显示该教师信息,输入新数据,将改后信息写入文件(4) 教师数据查询: 提示:输入教师号或其他信息,即读出所有数据信息,并显示出来5) 教师综合信息输出 提示:输出教师信息到屏幕。
1. 课程设计目的和要求 A. 巩固和加强《c语言程序设计》课程的理论知识B. 掌握c语言的基本概念,语法,语义和数据类型的使用特点C. 掌握c语言程序设计的方法及编程技巧,能正确使用c语言编写程序D. 进一步理解和运用结构化程序设计的思想和放法E. 使学生掌握调试程序的基本方法及上机操作方法F. 通过查询手册和文献资料,培养学生独立分析问题和解决问题的能力G. 初步掌握开发一个小型实用系统的基本方法H. 培养学生的创新能力和创新思维I. 培养学生良好的程序设计风格进一步理解和运用2.课程设计题目及内容教师工资管理系统每个教师的信息为:教师名,姓名,性别,单位名称,家庭住址,联系,基本工资,津贴,生活补贴,应发工资,费,水电费,房租,所得税,卫生费,公积金,合计扣款,实发工资注:应发工资=基本工资+津贴+生活补贴;合计扣款=费+水电费+房租+所得税+卫生费+公积金;实发工资=应发工资—合计扣款1教师信息处理J. 输入教师信息K. 插入(修改)教师信息L. 删除教师信息;M. 浏览教师信息;(提示:具体功能及操作参考题12教师数据处理;A. 按教师号录入教师基本工资,津贴,生活补贴,费,水电费,房租,所得税,卫生费,公积金等基本信息;B. 教师实发工资、应发公资、合计扣款;C. 教师数据管理;(提示:输入教师号,读出并显示该教师信息,输入新数据,将改后信息写入文件。
D. 教师数据查询;(提示:输入教师好或其他信息,即读出所有数据信息,并显示出来E. 教师综合信息输出;(提示;输出教师信息到屏幕一、 需求分析① 教师信息处理A输入教师信息B插入修改教师信息C删除教师信息D浏览教师信息② 教师数据处理A按教师号录入教师基本工资、津贴、生活补贴、费、水电费、房租、所得税、卫生费、公积金等基本数据B教师实发工资,应发工资,合计扣款计算C教师数据管理D教师数据查询E教师综合信息输出二总体设计4.总体设计、输出界面选择操作选择0读取文件执行freeall()退出系统选择1输入数据Break结束选择2浏览数据break选择3查询数据Break选择4选择5删除数据修改数据BreakBreak输出:无效选项Break结束建立动态链表开辟一个新结点,并使p1,p2指向它读入一个老师数据给P1所指的结点head=NULL n=0当读入的p1->num!=0表尾结点的指针变量置NULLn=n+1真 n=1 假head=p1 p2->next=p1把p1所指的结点把p1所指的结点作为第一结点连接到表尾p2=p1在开辟一个新结点,使p1指向它读入一个老师数据给p1所指结点删除结点真链表是一个空表假 p1=head当num!=p1->num以及p1所指的结点不是表尾结点结点 p2=p1 p1=p1->next是 p1是要删除的结点否是 p1所指的头结点否输出找 head=p1->next p2->next= 不到的信息 p1->next 息输出空表插入结点p1=head,p0=stud是原来的链表是空表否当p0->num>p1->num以及p1所指的不是表尾结点将p0所 p2指向p1位置指的结 p1向后移一个结点点作为 p0->num<=p1->num唯一的真假结点是p1指向头结点否 p1->next=p0head=p0 p2->next=p0 p0->next=NULL p0->next=p1 p0->next=p1修改调用query函数查找到相关结点地址修改相关结点的值域是否存在该教师信息修改完毕三、详细设计源程序#include#include#include#define LEN sizeof(struct teacher)struct teacher *creat();struct teacher{ intnum; char name[10]; char sex[8]; char unit[10]; char address[10]; longtelnum; float salary_1; float allowance; floatlife_allow; float salary_2; floattel_fee; float tax; floathealth_fee; floatwater_fee; float rent; float grant; floattotal_fee; floatactual_salary; struct teacher *next;};int n;struct teacher *head;FILE *fp;struct teacher *creat(void) { struct teacher *p1,*p2; n=0; p1=p2=(struct teacher *)malloc(LEN); printf("教师号:");scanf("%d",&p1->num);fflush(stdin);printf("教师姓名:");gets(p1->name);printf("教师性别:");gets(p1->sex);printf("单位名称:");gets(p1->unit);printf("家庭地址:");gets(p1->address);printf("号码:");scanf("%ld",&p1->telnum);fflush(stdin);printf("基本工资:");scanf("%f",&p1->salary_1);fflush(stdin);printf("津贴:");scanf("%f",&p1->allowance);fflush(stdin); printf("生活补贴:");scanf("%f",&p1->life_allow);fflush(stdin);printf("费:");scanf("%f",&p1->tel_fee);fflush(stdin);printf("个人所得税:");scanf("%f",&p1->tax);fflush(stdin);printf("房租:");scanf("%f",&p1->rent);fflush(stdin);printf("公积金:");scanf("%f",&p1->grant);fflush(stdin);printf("水电费:");scanf("%f",&p1->water_fee);fflush(stdin);printf("卫生费:");scanf("%f",&p1->health_fee);fflush(stdin); p1->salary_2=p1->salary_1+p1->allowance+p1->life_allow; p1->total_fee=p1->tel_fee+p1->water_fee+p1->rent+p1->tax+p1->health_fee+p1->grant; p1->actual_salary=p1->salary_2-p1->total_fee; head=NULL; while(p1->num!=0) { n=n+1; if(n==1)head=p1; else p2->next=p1; p2=p1; p1=(struct teacher*)malloc(LEN); printf("教师号:");scanf("%d",&p1->num);fflush(stdin);printf("教师姓名:");gets(p1->name);printf("教师性别:");gets(p1->sex);printf("单位名称:");gets(p1->unit);printf("家庭地址:");gets(p1->address);printf("号码:");scanf("%ld",&p1->telnum);fflush(stdin);printf("基本工资:");scanf("%f",&p1->salary_1);fflush(stdin);printf("津贴:");scanf("%f",&p1->allowance);fflush(stdin); printf("生活补贴:");scanf("%f",&p1->life_allow);fflush(stdin);printf("费:");scanf("%f",&p1->tel_fee);fflush(stdin);printf("个人所得税:");scanf("%f",&p1->tax);fflush(stdin);printf("房租:");scanf("%f",&p1->rent);fflush(stdin);printf("公积金:");scanf("%f",&p1->grant);fflush(stdin);printf("水电费:");scanf("%f",&p1->water_fee);fflush(stdin);printf("卫生费:");scanf("%f",&p1->health_fee);fflush(stdin); p1->salary_2=p1->salary_1+p1->allowance+p1->life_allow; p1->total_fee=p1->tel_fee+p1->water_fee+p1->rent+p1->tax+p1->health_fee+p1->grant; p1->actual_salary=p1->salary_2-p1->total_fee; } p2->next=NULL; return(head);}void print(struct teacher *head){ struct teacher *p; printf("\nNow,These %d records are:\n",n); p=head; if(head!=NULL) do { printf("教师号:%5d\t\t",p->num); printf("教师姓名:%-10s\n",p->name); printf("教师性别:%-6s\t\t",p->sex); printf("单位名称:%-10s\n",p->unit); printf("家庭地址:%-10s\t",p->address); printf("号码:%8ld\n",p->telnum); printf("基本工资:%5.0f\t\t",p->salary_1); printf("津贴:%5.0f\n",p->allowance); printf("生活补贴:%5.0f\t",p->life_allow); printf("\t费:%5.0f\n",p->tel_fee); printf("个人所得税:%5.0f\t",p->tax); printf("卫生费:%5.0f\n",p->health_fee); printf("水电费:%5.0f\t\t",p->water_fee); printf("房租:%5.0f\n",p->rent); printf("公积金:%5.0f\t\t",p->grant); printf("应发工资:%5.0f\n",p->salary_2); printf("合计扣款:%5.0f\t\t",p->total_fee); printf("实发工资:%5.0f\n\n\n",p->actual_salary); p=p->next; }while(p!=NULL);}struct teacher *insert(struct teacher*head,struct teacher *teach){ struct teacher *p0,*p1,*p2; p1=head; p0=teach; if(head==NULL) { head=p0;p0->next=NULL; } else { while((p0->num>p1->num)&&(p1->next!=NULL)) {p2=p1;p1=p1->next;} if(p0->numnum) { if(head==p1)head=p0; else p2->next=p0; p0->next=p1; } else {p1->next=p0;p0->next=NULL;} } n=n+1; return(head);}struct teacher *del(struct teacher *head,int number){ struct teacher *p1,*p2; if(head==NULL){printf("\nlist null\n");return(head);} p1=head; while(number!=p1->num&&p1->next!=NULL) {p2=p1;p1=p1->next;} if(number==p1->num) { if(p1==head)head=p1->next; else p2->next=p1->next; printf("删除:%d\n",number); n=n-1; } else printf("%ld is not found\n",number); return(head);}void save(){ int i;struct teacher *p1; p1=head; if((fp=fopen("teacher_list","wb"))==NULL) {printf("cannot open file\n"); return;} for(i=0;inext;} fclose(fp);}void load(){struct teacher *p1,*p2; if((fp=fopen("teacher_list","rb"))==NULL) {printf("cannot open file\n"); return; } p1=p2=(struct teacher *)malloc(LEN);head=p1;do { if(fread(p1,sizeof(struct teacher),1,fp)!=1) {printf("file error\n");goto end;} if(p1->next!=NULL) {p2=p1; p1=(struct teacher *)malloc(LEN); p2->next=p1; } else break; }while(1); end: fclose(fp);} void query(struct teacher *p){ int no; p=head; printf("please input num:\n"); scanf("%d",&no); while(p->num!=no) p=p->next; printf("基本工资:%5.0f\t\t",p->salary_1); printf("津贴:%5.0f\n",p->allowance); printf("生活补贴:%5.0f\t",p->life_allow); printf("\t费:%5.0f\n",p->tel_fee); printf("个人所得税:%5.0f\t",p->tax); printf("卫生费:%5.0f\n",p->health_fee); printf("水电费:%5.0f\t\t",p->water_fee); printf("房租:%5.0f\n",p->rent); printf("公积金:%5.0f\t\t",p->grant); printf("应发工资:%5.0f\n",p->salary_2); printf("合计扣款:%5.0f\t\t",p->total_fee); printf("实发工资:%5.0f\n\n\n",p->actual_salary); } void edit(struct teacher *p){ int a; printf("please input num:\n"); scanf("%d",&a); printf("%d\n\n",a); for(;;) {if(p->num==a) { printf("教师号:%5d\t\t",p->num); printf("教师姓名:%-10s\n",p->name); printf("教师性别:%-6s\t\t",p->sex); printf("单位名称:%-10s\n",p->unit); printf("家庭地址:%-10s\t",p->address); printf("号码:%8ld\n",p->telnum); printf("基本工资:%5.0f\t\t",p->salary_1); printf("津贴:%5.0f\n",p->allowance); printf("生活补贴:%5.0f\t",p->life_allow); printf("\t费:%5.0f\n",p->tel_fee); printf("个人所得税:%5.0f\t",p->tax); printf("卫生费:%5.0f\n",p->health_fee); printf("水电费:%5.0f\t\t",p->water_fee); printf("房租:%5.0f\n",p->rent); printf("公积金:%5.0f\t\t",p->grant); printf("应发工资:%5.0f\n",p->salary_2); printf("合计扣款:%5.0f\t\t",p->total_fee); printf("实发工资:%5.0f\n\n\n",p->actual_salary); printf("请输入新数据:\n"); printf("教师号:");scanf("%d",&p->num);fflush(stdin);printf("教师姓名:"); gets(p->name);printf("教师性别:"); gets(p->sex);printf("工作单位:"); gets(p->unit);printf("家庭地址:"); gets(p->address);printf("号码:");scanf("%ld",&p->telnum);fflush(stdin);printf("基本工资:");scanf("%f",&p->salary_1);fflush(stdin);printf("津贴:");scanf("%f",&p->allowance);fflush(stdin); printf("生活补贴:");scanf("%f",&p->life_allow);fflush(stdin);printf("费:");scanf("%f",&p->tel_fee);fflush(stdin);printf("个人所得税:");scanf("%f",&p->tax);fflush(stdin);printf("房租:");scanf("%f",&p->rent);fflush(stdin);printf("公积金:");scanf("%f",&p->grant);fflush(stdin);printf("水电费:");scanf("%f",&p->water_fee);fflush(stdin);printf("卫生费:");scanf("%f",&p->health_fee);fflush(stdin); p->salary_2=p->salary_1+p->allowance+p->life_allow; p->total_fee=p->tel_fee+p->water_fee+p->rent+p->tax+p->health_fee+p->grant; p->actual_salary=p->salary_2-p->total_fee; break; } p=p->next; }} void welcome() { printf("\t\t\t+---------------------------+\n"); printf("\t\t\t| |\n"); printf("\t\t\t| 欢迎使用教师工资管理系统 |\n"); printf("\t\t\t| |\n"); printf("\t\t\t+---------------------------+\n"); printf("\n\n");} char mainmenu() { char choice; printf("\n温馨提示:为保证您的操作得到保存,请按正常顺序退出系统^_^\n"); printf("\n\n"); printf("\t\t\t--------------------------------\n"); printf("\t\t\t| 教师工资管理系统 |\n"); printf("\t\t\t--------------------------------\n"); printf("\t\t\t| [1]----输入教师信息 |\n"); printf("\t\t\t| [2]----插入教师信息 |\n"); printf("\t\t\t| [3]----删除教师信息 |\n"); printf("\t\t\t| [4]----浏览教师信息 |\n"); printf("\t\t\t| [5]----录入教师信息 |\n"); printf("\t\t\t| [6]----查询教师信息 |\n"); printf("\t\t\t| [7]----修改教师信息 |\n");printf("\t\t\t| [8]----加载教师信息 |\n"); printf("\t\t\t| [0]----退出系统 |\n"); printf("\t\t\t|*·*·*·*·*·*·*·*·*·*·|\n"); printf("\t\t\t--------------------------------\n"); printf("请输入您的选择:"); do {fflush(stdin);scanf("%c",&choice);fflush(stdin); }while(choice<'0'||choice>'8'); return(choice);}void main(){struct teacher *teach; intdel_num; char choice; while(1) { welcome(); choice=mainmenu(); switch(choice) { case '0': system("cls"); exit(0); case '1': printf("input records:\n"); head=creat(); break; case '2':printf("input the inserted record:\n"); teach=(struct teacher *)malloc(LEN); printf("教师号:");scanf("%d",&teach->num);fflush(stdin);printf("教师姓名:"); gets(teach->name);printf("教师性别:"); gets(teach->sex);printf("单位名称:"); gets(teach->unit);printf("家庭地址:"); gets(teach->address);printf("号码:");scanf("%ld",&teach->telnum);fflush(stdin);printf("基本工资:");scanf("%f",&teach->salary_1);fflush(stdin);printf("津贴:");scanf("%f",&teach->allowance);fflush(stdin); printf("生活补贴:");scanf("%f",&teach->life_allow);fflush(stdin);printf("费:");scanf("%f",&teach->tel_fee);fflush(stdin);printf("个人所得税:");scanf("%f",&teach->tax);fflush(stdin);printf("房租:");scanf("%f",&teach->rent);fflush(stdin);printf("公积金:");scanf("%f",&teach->grant);fflush(stdin);printf("水电费:");scanf("%f",&teach->water_fee);fflush(stdin);printf("卫生费:");scanf("%f",&teach->health_fee);fflush(stdin); teach->salary_2=teach->salary_1+teach->allowance+teach->life_allow; teach->total_fee=teach->tel_fee+teach->water_fee+teach->rent+teach->tax+teach->health_fee+teach->grant; teach->actual_salary=teach->salary_2-teach->total_fee; head=insert(head,teach); print(head); break; case '3': printf("input the delete number:"); scanf("%d",&del_num); getchar(); head=del(head,del_num); print(head); break; case '4': print(head); break; case '5': save(); break; case '6':query(head);break; case '7':edit(head);break; case '8':load();break; } }}调试与测试进入页面输入输出心得体会持续两周的课程设计给了我太多感触,题目很大,设计量很大,也很繁杂,非一人之力可以解决。
这样只是重新捡起书本来看,获得新知识提升自己的能力整个程序的设计是分模块实现具体的功能,每个模块分别由不同的函数每个同学都有自己的分工链表的建立实现输入信息功能,相比较于数组更加方便,更节省内存空间通过使用文件fread和fwrite函数方便的将数据信息写入文件以及将文件中的信息载入显示段通过这十几天的训练与设计我学会了很多,也更加熟悉c语言程序设计,从中得到很多乐趣,很快乐,感觉这些天我并没有浪费掉,而是利用了他,虽然天很热,可是能看见同学们自己设计的程序运行起来我还是很开心在学校留着设计程序真的很有意义,很锻炼人的能力,为自己以后独立编程打下基础。