C语言课程设计通讯录管理系统
- 格式:doc
- 大小:43.00 KB
- 文档页数:6
#include
#include
#include
#include
#define N 100
int M=5;
struct student
{ char num[10];char name[10];char tel[10];};
void myprint();
void mycreat(struct student *p,int);
void mydisplay(struct student *p,int);
void mysearch(struct student *p,int);
void mymodify(struct student *p,int);
void mydelete(struct student *p,int);
void myadd(struct student *p,int);
void main()
{
char choose='\0',yes_no='\0';
struct student record[N]={0};
do
{
myprint();
printf("请选择(0-6):");
choose=getche();
switch(choose)
{
case '1':mycreat(record,M);break;
case '2':mydisplay(record,M);break;
case '3':mysearch(record,M);break;
case '4':mymodify(record,M);break;
case '5':myadd(record,M);break;
case '6':mydelete(record,M);break;
case '0':exit(0);
default :printf("\nerror...\n");
}
printf("\n继续选择吗(y/n)?\n");
do
{yes_no=getch();}
while(yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n'); }while(yes_no=='Y'||yes_no=='y');
}
void myprint()
{
system("cls");
printf(" 请输入选项编号(0-6): \n");
printf("1--创建通讯录\n");
printf("2--显示通讯录\n");
printf("3--查询通讯录\n");
printf("4--修改通讯录\n");
printf("5--添加通讯录\n");
printf("6--删除通讯录\n");
printf("0--退出\n");
}
void mycreat(struct student *p,int n)
{
struct student *q=p;
FILE *fp=NULL;
fp=fopen("d:\\jilu.dat","w");
if(fp==NULL){printf("error"); return;}
for(p=q;p-q { printf("\n"); printf("第%d条记录:\n",p-q+1); printf("学号:"); do {gets(p->num);} while(strcmp(p->num,"")==0); printf("姓名:"); gets(p->name); printf("电话:"); gets(p->tel); fprintf(fp,"%23s%15s%15s\n",p->num,p->name,p->tel); } } void mydisplay(struct student *p,int n) { FILE *fp=NULL; fp=fopen("d:\\jilu.dat","r"); if(fp==NULL){printf("error"); return;} system("cls"); printf(" 学号姓名电话\n"); while(n>0) { fscanf(fp,"%23s%15s%15s",p->num,p->name,p->tel); printf("%23s%15s%15s\n",p->num,p->name,p->tel); p++;n--; } } void mysearch(struct student *p,int n) { struct student *q=p; int flag=0; char c='\0',nm[10]="",nam[10]=""; printf("\n按照学号查询(h)或姓名查询(m):\n"); c=getche(); if(c=='h'||c=='H') { printf("请输入要查询记录的学号:");gets(nm); for(p=q;p-q if(strcmp(nm,p->num)==0) { printf(" 学号姓名电话\n"); printf("%23s%15s%15s\n",p->num,p->name,p->tel); flag=1; } if(flag==0) printf("wrong...\n"); } else if(c=='m'||c=='M') { printf("请输入要查询记录的姓名:");gets(nam); for(p=q;p-q if(strcmp(nam,p->name)==0) { printf(" 学号姓名电话\n"); printf("%23s%15s%15s\n",p->num,p->name,p->tel); flag=1; } if(flag==0) printf("wrong...\n"); } else printf("wrong...\n"); } void mymodify(struct student *p,int n) { struct student *q=p; FILE *fp=NULL; char nam[10]=""; mydisplay(p,n); printf("请输入您想要修改记录的姓名:\n");gets(nam); for(p=q;p-q if(strcmp(nam,p->name)==0) break; if(p-q==n)