C语言课程设计示例Word文件下载.docx
- 文档编号:7820849
- 上传时间:2023-05-09
- 格式:DOCX
- 页数:22
- 大小:95.04KB
C语言课程设计示例Word文件下载.docx
《C语言课程设计示例Word文件下载.docx》由会员分享,可在线阅读,更多相关《C语言课程设计示例Word文件下载.docx(22页珍藏版)》请在冰点文库上搜索。
2.数据结构
本系统中主要的数据结构就是职工的信息,包含职工号、姓名、性别、出生年月、学历、职务、工资、住址、电话等,在处理过程中各项可以作为一个职工的不同属性来进行处理。
3.程序流程
系统的执行应从功能菜单的选择开始,依据用户的选择来进行后续的处理,直到用户选择退出系统为止,其间应对用户的选择做出判断及异常处理。
系统的流程图如图2所示:
图2程序流程图
3详细设计
3.1编写目的
根据项目概要设计说明书,在项目概要设计的基础之上,对系统进行详细设计,以便下一步进行程序编码工作。
3.2详细设计
1.数据结构
(1)性别:
enumSex{male,female};
(2)学历:
enumEducation{high,junior,college,master,doctor};
(3)日期:
structDate
{
intyear;
intmonth;
intday;
};
(4)职工信息:
structInfo
charnum[5];
/*职工号*/
charname[8];
/*姓名*/
enumSexsex;
/*性别*/
structDatebirthday;
/*出生年月*/
enumEducationeducation;
/*学历*/
charduty[8];
/*职务*/
doublewage;
/*工资*/
charaddr[12];
/*地址*/
charphone[8];
/*电话*/
2.各个功能模块的处理流程
对应于总体设计时的系统功能模块图,各个功能模块的处理流程如下:
(1)信息输入模块
打开职工信息文件;
while(继续输入)
读入职工信息;
将读入信息添加到职工信息文件中;
提示是否继续输入;
}
关闭职工信息文件;
(2)信息浏览模块
while(不到文件结束)
从文件中顺序读出一个职工的信息;
按指定格式输出该职工的信息;
(3)信息查询模块
while(继续查询)
if(按编号查询)
{
读入查询的职工编号;
打开职工信息文件;
while(不到文件结束)
顺序读出一个职工的信息;
if(该职工信息的编号符合条件)
输出该职工的信息;
}
关闭职工信息文件;
提示共有几条符合条件的记录;
elseif(按姓名查询)
读入查询的职工姓名;
if(该职工信息的姓名符合条件)
else
提示输入不合适;
提示是否继续查询;
(4)信息修改模块
while(继续修改)
打开临时文件;
提示并读入待修改的职工的编号;
将职工的信息进行修改;
将职工的信息写入临时文件中;
关闭原信息文件;
关闭临时文件;
删除原信息文件;
将临时文件的名字改为原信息文件的名字;
(5)信息删除模块
while(继续删除)
提示并读入待删除的职工号;
查找是否有符合条件的职工记录;
if(有符合条件的记录)
创建一个新的临时文件;
while(原信息文件中记录未读完)
读出原信息文件中的下一条记录;
if(此条记录不是待删除记录)
写入临时文件中去;
提示没有符合条件的记录存在;
(6)菜单选择模块:
给出信息提示;
清屏;
绘制菜单(包含输入、显示、查询、修改、删除、退出);
提示菜单选择并读入到变量;
返回变量的值。
4参考程序
#include<
stdio.h>
string.h>
stdlib.h>
conio.h>
enumSex{male,female};
/*性别*/
enumEducation{high,junior,college,master,doctor};
/*学历*/
structDate/*日期*/
charnum[10];
/*职工号*/
charname[15];
/*姓名*/
/*出生年月*/
charduty[15];
/*职务*/
/*工资*/
charaddr[30];
/*地址*/
charphone[15];
/*电话*/
charmenu()/*菜单选择函数*/
charn;
/*n记录选择的菜单*/
clrscr();
/*清屏*/
puts("
\t\tWelcometoemployeemanagementsystem"
);
\t\t*********************MENU********************\n"
\t\t\t\t1.Appendinform\n"
\t\t\t\t2.Displayinform\n"
\t\t\t\t3.Searchinform\n"
\t\t\t\t4.Modifyinform\n"
\t\t\t\t5.Deleteinform\n"
\t\t\t\t6.Exit\n"
\t\t*********************************************\n"
printf("
Choiceyournumber(1-6):
[]\b\b"
while
(1)
n=getchar();
getchar();
if(n<
'
1'
||n>
6'
)
printf("
Inputerror,pleaseinputagain(1-6):
else
break;
returnn;
voidappend()/*信息添加函数*/
structInfoinfo;
FILE*fp;
charch;
chartemp[10];
if((fp=fopen("
inform.txt"
"
ab"
))==NULL)
\tCannotopentheinformfile!
"
getch();
exit
(1);
do
\tnum:
gets(info.num);
\tname:
gets(info.name);
\tsex(maleorfemale):
gets(temp);
if(!
strcmp(temp,"
female"
))info.sex=female;
elseinfo.sex=male;
\tbirthday(yyyy/mm/dd):
scanf("
%d/%d/%d"
&
info.birthday.year,&
info.birthday.month,\
&
info.birthday.day);
getchar();
\teducation:
doctor"
))info.education=doctor;
elseif(!
master"
))info.education=master;
college"
))info.education=college;
junior"
))info.education=junior;
elseinfo.education=high;
\tduty:
gets(info.duty);
\twage:
info.wage=atof(temp);
\taddress:
gets(info.addr);
\tphone:
gets(info.phone);
fwrite(&
info,sizeof(info),1,fp);
\tAnymore?
(Y/N):
ch=getchar();
}while(ch=='
Y'
||ch=='
y'
fclose(fp);
voidprint1()
%-8s%-10s%-8s%-12s%-15s%-8s%-15s%-15s%-10s\n"
nun"
\
"
name"
sex"
birthday"
education"
duty"
wage"
address"
phone"
voidprint2(structInfoinfo)
%-8s%-10s"
info.num,info.name);
if(info.sex==male)printf("
%-8s"
male"
elseprintf("
%-4d/%-2d/%-4d"
info.birthday.year,\
info.birthday.month,info.birthday.day);
if(info.education==high)printf("
%-15s"
high"
elseif(info.education==junior)printf("
elseif(info.education==college)printf("
elseif(info.education==master)printf("
%-8s%-15.2lf"
info.duty,info.wage);
%-15s%-10s\n"
info.addr,info.phone);
voiddisplay()/*职工信息显示函数*/
inttotal=0;
rb"
while(fread(&
info,sizeof(info),1,fp)==1)
total++;
if(total==1)print1();
print2(info);
if((total!
=0)&
&
(total%5==0))
\n\n\tPressanykeytocontinue......"
\n\n"
print1();
\n\n\tThereare%drecordinall!
total);
voidsearch()/*信息查询函数*/
intflag;
/*flag为1按编号查询,flag为2按姓名查询*/
inttotal=0;
/*记录符合条件的记录的个数*/
charch[10];
charf;
rewind(fp);
\n\nSearchby(1:
num2:
name):
{
%d"
flag);
if(flag<
1||flag>
2)
Inputerror,pleaseinputagain(1:
break;
if(flag==1)/*按编号进行查询*/
Pleaseinputthenumyouwanttosearch:
gets(ch);
total=0;
/*符合条件的记录数*/
if(strcmp(ch,info.num)==0)
if(total==1)print1();
}
else/*按姓名进行查询*/
Pleaseinputthenameyouwanttosearch:
if(strcmp(ch,info.name)==0)
\n\n\tThereare%drecordincluded!
\n"
Searchanymore?
f=getchar();
}while(f=='
||f=='
voidmodify()/*信息修改函数*/
FILE*fp1,*fp2;
if((fp1=fopen("
if((fp2=fopen("
temp.txt"
wb"
\tCannotcreatthetempfile!
Pleaseinputthenumyouwanttomodify:
flag=0;
info,sizeof(info),1,fp1)==1)
\n\nPleaseinputthenewinformation:
flag=1;
info,sizeof(info),1,fp2);
fclose(fp1);
fclose(fp2);
if(flag==1)
Modifysucess!
remove("
rename("
Cannotfindthisrecord!
Modifyanymore?
voiddelete()/*信息删除函数*/
Pleaseinputthenumyouwanttode
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 课程设计 示例
![提示](https://static.bingdoc.com/images/bang_tan.gif)