当前位置:文档之家› C语言课程设计报告

C语言课程设计报告

C语言课程设计论文学生姓名:陈丹学生学号:所在班级:信息与计算科学一班任课教师:马老师通讯录管理系统【设计目的】设计“通讯录管理系统”使其具有数据插入、修改、删除、显示和查询等功能。

(1)数据包括:人名、工作单位、电话号码和E-mail地址。

(2)可对记录中的姓名和电话号码进行修改。

(3)可增加或删除记录。

(4)可显示所有保存的记录。

(5)可按人名或电话号码进行查询。

【设计思路】根据要求,电话簿数据以文本文件存放在文件中,故需要提供文件的输入、输出等操作;还需要保存记录以进行修改,删除,查找等操作;另外还应提供键盘式选择菜单实现功能选择。

【总体设计】图1 系统功能模块图【详细设计】1.主函数主函数设计要求简洁,只提供部分提示语和函数的调用【程序】图2. 主函数流程图V oid menu() /*主界面*/{int n, w1;void enter(); void add(); void modify(); void browse(); void deleter(); void search(); do{puts("\t******************************菜单*****************************\t\n\n"); puts("\t\t\t\t1.新建联系人");puts("\t\t\t\t2.添加联系人");puts("\t\t\t\t3.修改");puts("\t\t\t\t4.删除");puts("\t\t\t\t5.浏览");puts("\t\t\t\t6.查找");puts("\t\t\t\t7.退出");puts("\n\n\t***************************通讯录******************************\t\n"); printf("请选择服务种类(1-7) : [ ]\b\b");scanf("%d",&n);if(n<1||n>7){w1=1;getchar();}else w1=0;}while(w1==1);switch(n){case 1: enter(); break; /*输入模块*/case 2: add(); break; /*添加模块*/附录:源代码#define N 50#include<stdio.h>#include<string.h>struct people{char name[20]; char company[50]; char num[15]; char mail[20];}peop[N];void printf_face(){ printf("\n\t姓名\t单位\t电话号码\t邮箱\n"); }void printf_one(int i){ printf("\t%s\t%s\t%s\t%s\n",peop[i].name,peop[i].company,peop[i].num,peop[i].mail); }void printf_n(int n){ int j;for(j=0;j<n;j++){ if((j!=0)&&(j%10==0)) {printf("\n\nPress any key to continue...:"); getchar(); puts("\n\n");} printf_one(j);} getchar();}int load(){ FILE *fp;int i;if((fp=fopen("file","rb"))==NULL){ printf("\nCan not open file\n");exit(0);}for(i=0;!feof(fp);i++)fread(&peop[i],sizeof(struct people),1,fp);fclose(fp);return(i-1);}int modify_data(int i,int n){ int c,w1; void input(int i); void menu();do{ puts("\n修改选项=>\n\n 1).姓名2).单位3).电话号码4).邮箱5).所有数据6).取消并返回");printf("请选择?: [ ]\b\b");scanf("%d",&c);if(c>6||c<1) {puts("\nChoose error! Please again!"); getchar();}}while(c>6||c<1);do{ switch(c){ case 1: printf("name:"); scanf("%s",peop[i].name); break;case 2: printf("company:"); scanf("%s",peop[i].company); break;case 3: printf("number:"); scanf("%s",peop[i].num); break;case 4: printf("e-mail:"); scanf("%s",peop[i].mail); break;case 5: input(i); break;case 6: menu();}puts("\nNow:\n");printf_face(); printf_one(i);printf("\n确定?\n\n\t1).是2).不,重新修改3).返回不保存[ ]\b\b");scanf("%d",&w1);}while(w1==2);return(w1);}void input(int i){ printf_face(); printf("\t");scanf("%s\t%s\t%s\t%s",peop[i].name,peop[i].company,peop[i].num,peop[i].mail); }void save(int n){ FILE *fp; int i;if((fp=fopen("file","wb"))==NULL){ printf("\nCan not open file\n");exit(0);}for(i=0;i<n;i++)if(peop[i].name[0]!='\0')if(fwrite(&peop[i],sizeof(struct people),1,fp)!=1)printf("file write error\n");fclose(fp);}void printf_back(){int w; void browse(); void menu();printf("\n\n\t^_^.Successful. ^_^\n\n");printf("What do you want to do?\n\n\t1).浏览所有\t2).返回: [ ]\b\b");scanf("%d",&w);if(w==1) browse();else menu();}void main(){void menu();menu();}void menu(){int n, w1;void enter(); void add(); void modify(); void browse(); void deleter(); void search(); do{puts("\t************************菜单************************ "); puts("\t\t*******************1.新建联系人*******************"); puts("\t\t*******************2.添加联系人*******************"); puts("\t\t*******************3.修改*******************"); puts("\t\t*******************4.删除*******************"); puts("\t\t*******************5.浏览*******************"); puts("\t\t*******************6.查找*******************"); puts("\t\t*******************7.退出*******************"); puts("\n\n\t********************通讯录********************* "); printf("请选择服务种类(1-7) : [ ]\b\b");scanf("%d",&n);if(n<1||n>7){w1=1;getchar();}else w1=0;}while(w1==1);switch(n){case 1: enter(); break;case 2: add(); break;case 3: modify(); break;case 4: deleter(); break;case 5: browse(); break;case 6: search(); break;case 7: exit(0);}}void enter(){ int i,n;printf("How many people(0-%d)?:",N-1);scanf("%d",&n);printf("请输入数据:\n");for(i=0;i<n;i++){printf("\n输入第%d个记录.\n",i+1);input(i);}if(i!=0) save(n);printf_back();}void add(){ int i,n,k,t;n=load();printf("How many people do you want to add(0-%d)?:",N-n-1);scanf("%d",&t); k=n+t;for(i=n;i<k;i++){ printf("\n输入第%d个记录.\n",i-n+1); input(i);}save(k); printf_back();}void modify(){ struct people s; int i,n,k,w0=1,w1,w2=0;n=load();do{ k=-1; printf_face(); printf_n(n);do{ printf("\n\nEnter name that you want to modify!\nName:");scanf("%s",);for(i=0;i<n;i++)if(strcmp(,peop[i].name)==0) {k=i; s=peop[i];}if(k==-1) printf("\n\n没有记录请重新输入!");}while(k==-1);printf_face(); printf_one(k);w1=modify_data(k,n);if(w1==1) {printf("\n\t^_^.Successful ^_^.\n\n是否继续?\n\n\t1).是2).保存返回\t[ ]\b\b");scanf("%d",&w0); w2=1;}else{w0=0; if(w2==0) peop[k]=s;}if((w0!=1)&&(w2==1)) save(n);}while(w0==1); menu();}void browse(){ int n;n=load();printf_face(); printf_n(n);printf("\t共有%d 记录.\n",n);printf("\nPress any key to back...");getchar();menu();}void search(){ int w0,k,i,n,w1,w2; struct people s; n=load();do{printf("请选择查找类别: 1).姓名2).电话号码[ ]\b\b");scanf("%d",&w1); if(w1<1||w1>2) {printf("输入错误!请重新输入!\n"); w2=1;}}while(w2==1);if(w1==1){do{ k=-1;do{ printf("\n\nEnter name that tou want to search!\nName:");scanf("%s",);for(i=0;i<n;i++)if(strcmp(,peop[i].name)==0) {k=i; s=peop[i];}if(k==-1) printf("\n\n没有记录请重新输入!");}while(k==-1);printf_face(); printf_one(k);printf("\nWhat do you want to do?\n\t1).继续2).返回菜单[ ]\b\b");scanf("%d",&w0);}while(w0==1);menu();}else{ do{ k=-1;do{ printf("\n\nEnter number that tou want to search!\nNum:");scanf("%s",s.num);for(i=0;i<n;i++)if(strcmp(s.num,peop[i].num)==0) {k=i; s=peop[i];}if(k==-1) printf("\n\n没有记录请重新输入!");}while(k==-1);printf_face(); printf_one(k);printf("\nWhat do you want to do?\n\t1).继续2).返回菜单[ ]\b\b");scanf("%d",&w0);}while(w0==1);menu();}}void deleter(){struct people s; int i,n,k,w0,w1;n=load();do{ k=-1; printf_face(); printf_n(n);do{ printf("\n\nEnter name that you want to delete!\nName:");scanf("%s",);for(i=0;i<n;i++)if(strcmp(,peop[i].name)==0) {k=i; s=peop[i];}if(k==-1) printf("\n\n没有记录请重新输入!");}while(k==-1);printf_face(); printf_one(k);printf("\n确定?\n\t1).是2).返回[ ]\b\b");scanf("%d",&w0);if(w0==1) {peop[k].name[0]='\0'; save(n);} else break;printf("\n\t^_^.Successful^_^.\n");printf("What do you want to do?\n\t1).继续2).返回[ ]\b\b");scanf("%d",&w1);}while(w1==1);menu();}【设计体会】通过为期一周的课程设计,我们对《C语言》这门课程有了更深一步的了解。

相关主题