资源描述
《C语言课程设计》
课程设计报告
题 目
身份证信息管理软件
年级专业
2010级电子信息工程
完成日期
2011
年
6
月
17
日
目 录
1. 课程设计目的···········································3
2. 分析与设计·············································3
3.核心代码清单············································5
4. 设计中的问题··········································14
5. 课程设计总结··········································14
6. 参考书目··············································14
1. 课程设计目的:
1) 巩固和加深对C语言课程的基本知识的理解和掌握;
2) 掌握和提高C语言编程和程序调试的基本能力;
3) 利用C语言进行基本的软件设计,并掌握软件开发的基本过程和基本方法以及良好的编程风格;
4) 掌握书写程序设计说明书的方法;
5) 提高运用C语言解决实际问题的能力。
2. 分析与设计:
1) 系统需求:
公民身份信息是国家最宝贵的基础信息资源之一,是制定与实施各种政策和指导经济建设的重要依据。利用现代信息技术进行公民身份信息资源的充分开发与利用,掌握人口信息的动态变化,对于国家加强社会管理,实现社会信息化将起到积极的推动作用。对于促进社会主义现代化建设和经济体制改革、打击犯罪、方便群众、保护公民的合法权益等都具有十分重要的意义。其建设的最终目标是实现与国家其它有关公民信息的系统实现互连互通,数据高度共享。为建立国家公民个人信用体系,为国家经济建设和社会发展做出贡献。因此,我想设计一个身份证信息管理软件,用于对省份正信息的分类、管理和统计,从而方便公安机关和普通民众的查询。
2) 设计思路:
应用结构体对身份证信息进行添加、删除、查寻、修改、保存、统计和文件操作等。
3) 综合任务:
本次训练需要编写一个身份证信息管理系统。此系统可以完成录入身份证信息、查询身份证信息、修改和删除身份证信息;录入信息后可统计相关的(诸如一定年龄段的人数等)信息,并将信息存储在文件中。
4) 技术方案:
① 建立身份证信息结构体链表;
② 对ID_card文件的打开、输入、关闭等操作;
③ 对 ID_card 文件的读取、查找、统计等操作;
④ 对身份证姓名、年龄、出生年月等校验和正误的判断;
⑤ 用switch函数控制各子程序的调用;
⑥ 程序中应用指针、字符串、结构体嵌套、递归、函数调用等知识;
⑦ 应用库函数strcpy、strcmp、stnrcmp、switch等。
开始(欢迎界面)
选择所需操作
4.寻找信息
2.添加信息
1.创建新系统
3.删除信息
5.统计信息
选择所需操作
选号符合规定
选择所需统计操作
选号符合规定
选号符合规定
按年龄查找
按出生日期
按姓名查找
按年龄段
按出生年份
结束
是
是
是
否
否
否
5) 身份证管理系统的框架图如下所示:
6) 测试数据截屏:
7) 详细设计说明
① 结构体:
struct ID_card
{ char name[20];
char sex;
char nation[10];
int year;
int month;
int day;
char addr[80];
char num;
struct ID_card *next;
};
② 相关函数:
struct ID_card *creat()/*创建新信息函数*/
struct ID_card *insert(struct ID_card *head,struct ID_card *name)/*插入信息函数*/
struct ID_card *delete(struct ID_card *head,char * num)/*删除信息函数*/
struct ID_card *search_birth(struct ID_card *head,int birthyear,int birthmonth,int birthday)/*通过出生日期寻找信息*/
struct ID_card *search_age(struct ID_card *head,int now_age)/*通过年龄寻找信息*/
struct ID_card *search_name(struct ID_card *head,char s_name[20])/* 通过姓名寻找信息*/
struct ID_card *count_age(struct ID_card *head,int age_s,int age_e)/*统计某一年龄段的人数*/
struct ID_card *count_year(struct ID_card *head,birthyear)/*统计某一年出生的人数*/
通过动态分配存储空间,建立链表并存储信息来建立通讯录。
3. 核心代码清单:
include <stdio.h>
#include <malloc.h>
#define LEN sizeof(struct ID_card)
#define YEAR 2011
struct ID_card
{
char name[20];
char sex;
char nation[10];
int year;
int month;
int day;
char addr[150];
char num[20];
struct ID_card *next;
};
int n;
struct ID_card *creat()
{
struct ID_card *head;
struct ID_card *p1,*p2;
n=0;
p1=p2=(struct ID_card *)malloc(LEN);
printf("Please input the name:");
scanf("%s",&p1->name);
printf("\nPlease input the sex:");
scanf("%s",&p1->sex);
printf("\nPlease input the nation:");
scanf("%s",&p1->nation);
printf("\nPlease input the birth-year:");
scanf("%d",&p1->year);
printf("\nPlease input the birth-month:");
scanf("%d",&p1->month);
printf("\nPlease input the birthday:");
scanf("%d",&p1->day);
printf("\nPlease input the address:");
scanf("%s",&p1->addr);
printf("\nPlease input the IDcard-number:");
scanf("%s",&p1->num);
head=NULL;
while(p1->name!=0)
{ n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct ID_card *)malloc(LEN);
printf("Please input the name:");
scanf("%s",&p1->name);
printf("Please input the sex:");
scanf("%c",&p1->sex);
printf("Please input the nation:");
scanf("%s",&p1->nation);
printf("Please input the birth-year:");
scanf("%d",&p1->year);
printf("Please input the birth-month:");
scanf("%d",&p1->month);
printf("Please input the birthday:");
scanf("%d",&p1->day);
printf("Please input the address:");
scanf("%s",&p1->addr);
printf("Please input the IDcard-number:");
scanf("%s",&p1->num);
}
p2->next=NULL;
return(head);
}
struct ID_card *insert(struct ID_card *head,struct ID_card *name)
{
struct ID_card *p1,*p2;
p1=(struct ID_card *)malloc(LEN);
printf("Please input the name:");
scanf("%s",&p1->name);
printf("Please input the sex:");
scanf("%s",&p1->sex);
printf("Please input the nation:");
scanf("%s",&p1->nation);
printf("Please input the birth-year:");
scanf("%d",&p1->year);
printf("Please input the birth-month:");
scanf("%d",&p1->month);
printf("Please input the birthday:");
scanf("%d",&p1->day);
printf("Please input the address:");
scanf("%s",&p1->addr);
printf("Please input the IDcard-number:");
scanf("%s",&p1->num);
p2=head;
if(head=NULL)
{
head=p1;
p1->next=NULL;
}
else
{
p2->next=p1;
p1->next=NULL;
}
return(head);
}
struct ID_card *delete(struct ID_card *head,char num)
{
struct ID_card *p1,*p2;
if(head==NULL)
{
printf("The system has no information!\n");
return(head);
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)
{
printf("The identity information to be deleted is:\n");
printf("Name:%s\nSex:%c\nNation:%s\nBirth:%d nian %d yue %d ri\nAddress:%s\nID card number:%s\n",p1->name,p1->sex,p1->nation,p1->year,p1->month,p1->day,p1->addr,p1->num);
head=p1->next;
}
else
p2->next=p1->next;
printf("The identity information to be deleted is:\n");
printf("Name:%s\nSex:%c\nNation:%s\nBirth:%d nian %d yue %d ri\nAddress:%s\nID card number:%s\n",p1->name,p1->sex,p1->nation,p1->year,p1->month,p1->day,p1->addr,p1->num);
free(p1);
}
else
printf("System does not have information on the ID number!\n");
return(head);
}
struct ID_card *search_age(struct ID_card *head,int now_age)
{
int b_year;
struct ID_card *p;
b_year=YEAR-now_age;
p=head;
while(strcmp(p->year,b_year)!=0&&p->next!=NULL)
p=p->next;
if(strcmp(p->year,b_year)==0)
printf("Name:%s\nSex:%c\nNation:%s\nBirth:%d nian %d yue %d ri\nAddress:%s\nID card number:%s\n",p->name,p->sex,p->nation,p->year,p->month,p->day,p->addr,p->num);
if(p->year!=b_year&&p->next==NULL)
printf("System does not have information about the age!\n");
return(head);
}
struct ID_card *search_name(struct ID_card *head,char s_name[20])
{
struct ID_card *p;
p=head;
while(strcmp(p->name,s_name)!=0&&p->next!=NULL)
p=p->next;
if(strcmp(p->name,s_name)==0)
printf("Name:%s\nSex:%c\nNation:%s\nBirth:%d nian %d yue %d ri\nAddress:%s\nID card number:%s\n",p->name,p->sex,p->nation,p->year,p->month,p->day,p->addr,p->num);
if(p->name!=s_name&&p->next==NULL)
printf("System does not have information about the name!\n");
return(head);
}
void main()
{
struct ID_card *head,*name;
int birthyear,birthmonth,birthday,now_age,age_s,age_e;
char num[20],s_name[20];
int a,b,c;
printf("*******************************************************\n");
printf(" Welcome to ID information management software!\n");
printf("*******************************************************\n");
printf("Please select your operating:\n");
printf("1.Creat a new ID card information system.\n");
printf("2.Insert the information in the system.\n");
printf("3.Delete information in the system.\n");
printf("4.Search ID card information.\n");
printf("5.For statistical operations.\n");
scanf("%d",&a);
printf("\n");
switch(a)
{
case 1:head=creat();break;
case 2:head=insert(head,name);break;
case 3:
{
printf("Please enter the ID number to delete:");
scanf("%s",num);
head=delete(head,* num);break;
}break;
case 4:
{
printf("Please select the operation you need to search\n");
printf("1.Search by date of birth\n");
printf("2.Search by age\n");
printf("3.Search by Name\n");
scanf("%d",&b);
printf("\n");
switch(b)
{
case 2:
{
printf("Please input the age of the person looking for information:");
scanf("%d",&now_age);
printf("\n");
search_age(head,now_age);
}break;
case 3:
{
printf("\nPlease input the name of the person looking for information:");
scanf("%s",s_name);
printf("\n");
search_name(head,s_name);
}break;
default:printf("Your operating errors!\n");
}break;
}
case 5:
{
printf("Please enter the statistics you need to operate:\n");
printf("1.Statistics of a number of age.\n");
printf("2.Statistics the number of births in a year.\n");
scanf("%d",&c);
printf("\n");
default:printf("Your operating errors!\n");
}
printf("Thank you for your visit!\n");
}
}
4. 设计中的问题:
由于链表的创建和文件操作上的课较少,加之程序设计时间较紧,上述源程序还有很多不完善之处。上述原代码中,struct ID_card *count_year(struct ID_card *head,birthyear),
struct ID_card *count_age(struct ID_card *head,int age_s,int age_e),
struct ID_card *search_birth(struct ID_card *head,int birthyear,int birthmonth,int birthday)三个函数没有调试通过;寻找信息函数没有调试成功,在查找时得到的信息不对;creat函数运行还不是很完善。总之,在编写程序时遇到了很多问题。也有一些问题得到了解决,如在编写insert函数时开始输入不了数据,后来查找资料,用malloc函数开辟了一个空间,可以完成数据的输入。在编写程序时我还是学到了很多。
5. 课程设计总结:
通过这次设计,加深了我对课本理论知识的理解,使我了解了软件开发的一些流程及注意事项,提高了我对C语言的运用能力,同时也培养了我的思维。作为学习体系的有机组成部分,这次课程设计的时间虽然不长,但不意味着没有意义。他的一个功能,在于运用学习成果,检验学习成果,看一看课堂学习与实际工作的距离,并通过综合分析找出学习中的不足,从而完善我们的学习与实践。
在此次课程设计过程中,我在收获知识的同时,也收获了一定的阅历。因为我在设计过程中查阅书本、查找资料,并通过努力编写了上面的290多行程序,培养了我独立思考、C语言编程以及其他一些能力。通过这次课程设计,我认为对于学习方法要有自己合理的见解,然后付诸行动实践出来,这样才能加深知识的理解,并且有所提高。
在此,也感谢老师和同学的热心帮助与细心知道,没有你们的帮助,我也不会做出这个课程设计。谢谢!
6. 参考书目:
1) 谭浩强编著,《C程序设计》,清华大学出版社,1991年
2) 谭浩强,C程序设计教程,清华大学出版社,2007年
物理与电子信息学院课程设计评定意见
指导教师评语
主要内容包括:设计报告内容的完整性和完成情况、报告格式的规范性、通过课程设计取得的收获等。
成绩: 签名: 年 月 日
注:本页与上一页用A3纸套印成封面和封底,课程设计报告正文用A4纸打印然后装订
15
展开阅读全文