范例C语言课程设计报告.docx

上传人:b****4 文档编号:12283185 上传时间:2023-04-17 格式:DOCX 页数:39 大小:27.58KB
下载 相关 举报
范例C语言课程设计报告.docx_第1页
第1页 / 共39页
范例C语言课程设计报告.docx_第2页
第2页 / 共39页
范例C语言课程设计报告.docx_第3页
第3页 / 共39页
范例C语言课程设计报告.docx_第4页
第4页 / 共39页
范例C语言课程设计报告.docx_第5页
第5页 / 共39页
点击查看更多>>
下载资源
资源描述

范例C语言课程设计报告.docx

《范例C语言课程设计报告.docx》由会员分享,可在线阅读,更多相关《范例C语言课程设计报告.docx(39页珍藏版)》请在冰豆网上搜索。

范例C语言课程设计报告.docx

范例C语言课程设计报告

范例:

职工信息管理系统

一.需求分析

1.1编写目的:

通过对用户需求进行调查分析,写出需求分析文档作为项目设计的基本准则要求,以及作为系统分析员进行系统分析和测试人员进行测试时的手册

1.2需求概述:

设计一个职工信息管理系统,使之能提供以下功能:

Ø录入职工信息并保存

Ø显示所有职工信息

Ø查询职工信息

Ø修改职工信息并保存

Ø删除职工信息

1.3需求说明:

职工信息包括职工号、姓名、性别、出生年月、学历、职务、工资、住址、电话等,并且要求职工号不重复;

录入的职工信息要求用文件形式保存,并可以对其进行浏览、查询、修改、删除等基本操作;

职工信息的显式要求有一定的规范格式;

对职工信息应能够分别按工资及按学历两种方式进行,要求能返回所有符合条件的职工的信息;

对职工信息的修改应逐个地进行,一个职工信息的更改不应影响其他的职工记录;

所设计的系统应以菜单方式工作,应为用户提供清晰的使用提示,依据用户的选择来进行各种处理,并要求在此过程中能够尽可能的兼容用户使用过程中的异常情况

二.总体设计

2.1编写目的:

根据需求分析文档,初步提出问题的解决方案,以及软件系统的体系结构和数据结构的设计方案并写出书面文档总体设计说明书,为下一步进行详细设计做准备。

2.2总体设计:

1.该系统可以按功能进行模块划分,其模块图如下:

系统模块图

其中:

信息输入模块完成职工信息的输入功能,输入信息包括职工号、姓名、性别、出生年月、学历、职务、工资、住址、电话等;

信息浏览模块完成已录入职工信息的显示;

信息查询模块完成职工信息的查询,查询时对应有按工资查询和按学历查询两种方式;

信息修改模块完成职工信息的修改功能;

信息删除模块完成职工信息的删除功能;

菜单选择模块完成用户命令的接收,此模块也是职工信息管理系统的入口,用户所要进行的各种操作均需在此模块中进行选择并进而调用其他模块实现相应的功能;

2.数据结构

本系统中主要的数据结构就是职工的信息,包含职工号、姓名、性别、出生年月、学历、职务、工资、住址、电话等,在处理过程中各项可以作为一个职工的不同属性来进行处理

3.程序流程

系统的执行应从功能菜单的选择开始,依据用户的选择来进行后续的处理,直到用户选择退出系统为止,其间应对用户的选择做出判断及异常处理。

系统的流程图如下:

程序流程图

三.详细设计

3.1编写目的:

根据项目概要设计说明书,在项目概要设计的基础之上,对系统进行详细设计,以便下一步进行程序编码工作。

3.2详细设计:

对应于总体设计时的系统功能模块图,各个功能模块的处理逻辑如下:

1.信息输入模块:

打开职工信息文件;

while( 继续输入)

{

读入职工信息;

 将读入信息添加到职工信息文件中;

 提示是否继续输入;

}

关闭职工信息文件;

2.信息浏览模块:

打开职工信息文件;

while(不到文件结束)

{

从文件中顺序读出一个职工的信息;

 按指定格式输出该职工的信息;

}

关闭职工信息文件;

3.信息查询模块:

while(仍继续查询)

{

 if(按工资查询)

{

读入查询的职工工资条件;

打开职工信息文件;

 while(不到文件结束)

{

 顺序读出一个职工的信息;

  if(该职工信息的工资符合条件)输出该职工的信息;

}

关闭职工信息文件;

提示共有几条符合条件的记录;

}

else

if(按学历查询)

{

读入学历查询的条件;

打开职工信息文件;

  while(不到文件结束)

 {

  顺序读出一个职工的信息;

   if(该职工信息的学历符合条件)输出该职工的信息;

}

关闭职工信息文件;

提示符合条件的记录数;

}

else提示输入不合适;

  提示是否继续查询;

}

4.信息修改模块:

while(继续修改)

从给出信息文件中所有的记录情况;

提示并读入待修改的记录的职工的职工号;

打开职工信息文件;

查找并读出该职工的信息到一个中间变量中;

提示并读入要针对该职工的哪个属性进行修改;

根据用户的选择提示并读入所要修改属性的新值;

在该职工的中间变量中修改刚刚读入的属性值;

提示是否确定要进行修改;

如果用户确定则将中间变量重新写回到原职工信息文件中;

关闭职工信息文件;

}

5.信息删除模块:

while(继续删除)

{

显示所有职工的信息;

提示并读入待删除的职工的职工号;

打开职工信息文件;

查找是否有符合条件的职工记录;

if(有符合条件的记录)

{

提示是否确认该删除操作;

if(用户确认此操作)

{

创建一个新的临时文件;

打开原信息文件;

while(原信息文件中记录未读完)

{

读出原信息文件中的下一条记录;

if(此条记录不是待删除记录)写入临时文件中去;

}

关闭原信息文件;

关闭临时文件;

读方式打开临时文件;

写方式重建与原信息文件同名的新信息文件;

将临时文件中的内容写入到新信息文件中去;

关闭新信息文件;

关闭临时文件;

删除临时文件;

}

}

else提示没有符合条件的记录存在;

}

6.菜单选择模块:

给出信息提示;

清屏;

绘制菜单(包含输入、显示、查询、修改、删除、退出);

提示菜单选择并读入到变量;

根据读入变量的值调用不同的模块函数;

数据结构:

性别:

enumSex{male,female};

学历:

enumEducation{high,junior,college,master,doctor};

日期:

structDate

{intyear;

intmonth;

intday;

};

职工信息:

structInfo

{

charnum[5];/*职工号*/

charname[8];/*姓名*/

enumSexsex;/*性别*/

structDatebirthday;/*出生年月*/

enumEducationeducation;/*学历*/

charduty[8];/*职务*/

doublewage;/*工资*/

charaddr[12];/*地址*/

charphone[8];/*电话*/

};

#include

#include

#include

enumSex{male,female};/*性别*/

enumEducation{high,junior,college,master,doctor};/*学历*/

structDate/*日期*/

{

intyear;

intmonth;

intday;

};

structInfo

{

charnum[5];/*职工号*/

charname[8];/*姓名*/

enumSexsex;/*性别*/

structDatebirthday;/*出生年月*/

enumEducationeducation;/*学历*/

charduty[8];/*职务*/

doublewage;/*工资*/

charaddr[12];/*地址*/

charphone[8];/*电话*/

};

voidmenu();

intload(char*a)/*计算参数所指定的文件中的记录的个数的函数*/

{

structInfoinfo;

FILE*fp;

inti;

if((fp=fopen(a,"rb"))==NULL)

{printf("\nCannotopenfile\n");getch();

return0;

}

for(i=0;!

feof(fp);i++)

fread(&info,sizeof(structInfo),1,fp);

fclose(fp);

return(i-1);/*返回记录个数*/

}

voidappend()/*信息添加函数*/

{

structInfoinfo;

FILE*fp;

intflag=1;

chartemp[10];

if((fp=fopen("inform.txt","ab"))==NULL)

if((fp=fopen("inform.txt","wb"))==NULL)

{

printf("\tCannotopentheinformfile!

");

getch();

exit

(1);

}

do

{

printf("\tnum:

");gets(info.num);

printf("\tname:

");gets(info.name);

printf("\tsex:

");gets(temp);

if(!

strcmp(temp,"female"))info.sex=female;

elseinfo.sex=male;

printf("\tbirthday(yyyy/mm/dd):

");scanf("%d/%d/%d",&info.birthday.year,&info.birthday.month,&info.birthday.day);getchar();

printf("\teducation:

");gets(temp);

if(!

strcmp(temp,"doctor"))info.education=doctor;

elseif(!

strcmp(temp,"master"))info.education=master;

elseif(!

strcmp(temp,"college"))info.education=college;

elseif(!

strcmp(temp,"junior"))info.education=junior;

elseinfo.education=high;

printf("\tduty:

");gets(info.duty);

printf("\twage:

");gets(temp);info.wage=atof(temp);

printf("\taddress:

");gets(info.addr);

printf("\tphone:

");gets(info.phone);

if(fwrite(&info,sizeof(info),1,fp)!

=1)

{

printf("\nfileinputwrong!

\n");

getch();

exit

(1);

}

printf("Anymore?

\t1).Yes\t2).No:

[]\b\b");

scanf("%d",&flag);getchar();

}while(flag==1);

fclose(fp);

menu();

}

voiddisplay()/*职工信息显示函数*/

{

intamount;/*信息文件中的记录总数*/

structInfoinfo;

FILE*fp;

inttotal=0;

chartemp[10],temp1[10];

amount=load("inform.txt");

if((fp=fopen("inform.txt","rb"))==NULL)

{

printf("\tCannotopentheinformfile!

");

getch();

exit

(1);

}

printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex","birthday","education","duty","wage","address","phone");

for(;total

{

if(fread(&info,sizeof(info),1,fp)!

=1)

{

printf("\nfilereadwrong!

\n");

getch();

exit

(1);

}

total++;

if(info.sex==male)strcpy(temp,"male");

elsestrcpy(temp,"female");

if(info.education==doctor)strcpy(temp1,"doctor");

elseif(info.education==master)strcpy(temp1,"master");

elseif(info.education==college)strcpy(temp1,"college");

elseif(info.education==junior)strcpy(temp1,"junior");

elsestrcpy(temp1,"high");

printf("%-5s%-8s%-8s%-4d/%-2d/%-2d%-10s%-8s%-8.2lf%-12s%-8s\n",info.num,info.name,temp,info.birthday.year,info.birthday.month,info.birthday.day,temp1,info.duty,info.wage,info.addr,info.phone);

if((total!

=0)&&(total%10==0))

{

printf("\n\n\tPressanykeytocontinue......");

getch();

puts("\n\n");

printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex","birthday","education","duty","wage","address","phone");

}

}

fclose(fp);

printf("\n\n\tThereare%drecordinall!

",total);

getch();

menu();

}

voidsearch()/*信息查询函数*/

{

intamount;/*信息文件中的记录总数*/

intcon=0;/*已处理的文件记录总数*/

structInfoinfo;

FILE*fp;

intflag=-1,flag1=-1;/*flag为1按工资查询,flag为2按学历查询;flag1为0表等于,为1表大于,为2表小于*/

inttotal=0;/*记录符合条件的记录的个数*/

chartemp[10],temp1[10],degree[10],express[10];

charoperator;

doublevalue;

enumEducationgrade1;

inti=0;/*读入表达式时用于字符串到数值的转换及控制学历的合法输入*/

amount=load("inform.txt");

do

{

printf("\n\nChoiceyouritemthattosearchby:

\t1).wage\t2).education:

[]\b\b");

scanf("%d",&flag);getchar();

}while(!

(flag==1||flag==2));

if(flag==1)/*按工资进行查询*/

{

flag1=-1;

do

{

printf("Pleaseinputtherelativeexpression(>valueor

");

gets(express);

i=1;

do

{

temp[i-1]=express[i];

i++;

}while(express[i-1]!

='\0');

operator=express[0];

value=atof(temp);

if(operator=='>')flag1=1;

elseif(operator=='<')flag1=2;

elseif(operator=='=')flag1=0;

elseprintf("\ntheexpressformatmustbe>valueor

}while(!

(flag1==1||flag1==2||flag1==0));

if((fp=fopen("inform.txt","rb"))==NULL)

{

printf("\tCannotopentheinformfile!

");

getch();

exit

(1);

}

total=0;/*符合条件的记录数*/

for(con=0;con

{

if(fread(&info,sizeof(info),1,fp)!

=1)

{

printf("\nfilereadwrong!

\n");

getch();

exit

(1);

}

if(flag1==0&&info.wage==value)

{

total++;

if(total==1)printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex","birthday","education","duty","wage","address","phone");

if(info.sex==male)strcpy(temp,"male");

elsestrcpy(temp,"female");

if(info.education==doctor)strcpy(temp1,"doctor");

elseif(info.education==master)strcpy(temp1,"master");

elseif(info.education==college)strcpy(temp1,"college");

elseif(info.education==junior)strcpy(temp1,"junior");

elsestrcpy(temp1,"high");

printf("%-5s%-8s%-8s%-4d/%-2d/%-2d%-10s%-8s%-8.2lf%-12s%-8s\n",info.num,info.name,temp,info.birthday.year,info.birthday.month,info.birthday.day,temp1,info.duty,info.wage,info.addr,info.phone);

if((total!

=0)&&(total%10==0))

{

printf("\n\n\tPressanykeytocontinue......");

getch();

puts("\n\n");

printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex","birthday","education","duty","wage","address","phone");

}

}

elseif(flag1==1&&info.wage>value)

{

total++;

if(total==1)printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex","birthday","education","duty","wage","address","phone");

if(info.sex==male)strcpy(temp,"male");

elsestrcpy(temp,"female");

if(info.education==doctor)strcpy(temp1,"doctor");

elseif(info.education==master)strcpy(temp1,"master");

elseif(info.education==college)strcpy(temp1,"college");

elseif(info.education==junior)strcpy(temp1,"junior");

elsestrcpy(temp1,"high");

printf("%-5s%-8s%-8s%-4d/%-2d/%-2d%-10s%-8s%-8.2lf%-12s%-8s\n",info.num,info.name,temp,info.birthday.year,info.birthday.month,info.birthday.day,temp1,info.duty,info.wage,info.addr,info.phone);

if((total!

=0)&&(total%10==0))

{

printf("\n\n\tPressanykeytocontinue......");

getch();

puts("\n\n");

printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex","birthday","education","duty","wage","address","phone");

}

}

elseif(flag1==2&&info.wage

{

total++;

if(total==1)printf("%-5s%-8s%-8s%-11s%-10s%-8s%-8s%-12s%-8s\n","nun","name","sex","birthday","education","duty","wage","a

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > 财会金融考试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1