You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
4.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
#include<string.h>
#include<conio.h>
#define N 80
typedef struct
{
char num[N];
char name[20];
char tele[15];
char add[20];
char emal[15];
}STUDENT;
STUDENT stu[N] ;
int menu();
int shuru(STUDENT stu[N]);
void xianshi(STUDENT stu[],int n);
int shanchu(STUDENT stu[],int n);
void chazhao(STUDENT stu[],int n);
void xiugai(STUDENT stu[],int n);
int tianjia(STUDENT stu[],int n);
int tuichu();
int main()
{
int length,m=0;
while(m>=0)
{
switch (menu())
{
case 0:length=shuru(stu);break;
case 1: xianshi(stu,length);break;
case 2:length=shanchu(stu,length);break;
case 3:chazhao(stu,length);break;
case 4:xiugai(stu,length);break;
case 5:length=tianjia(stu,length);break;
case 6:m=tuichu();break;
default:printf("输入错误,请重新输入\n");
}
}
}
int menu()
{
int m;
printf(" 欢迎使用通讯录管理系统 \n");
printf(" 主菜单 \n");
printf("\t\t\t 0.输入通讯录\n");
printf("\t\t\t 1.显示通讯录\n");
printf("\t\t\t 2.删除通讯录\n");
printf("\t\t\t 3.查找通讯录\n");
printf("\t\t\t 4.修改通讯录\n");
printf("\t\t\t 5.添加通讯录\n");
printf("\t\t\t 6.退出通讯录\n");
do{
printf("\t\t\t 请输入选项0-6\n");
scanf("%d",&m);
}while(m<0||m>6);
return m;
}
int shuru(STUDENT stu[N])
{
int i,n;
printf("\n请输入要加入通讯录的数目 \n");
scanf("%d",&n);
printf("请输入信息 \n");
for(i=0;i<n;i++)
{
printf("请输入编号:\n");
scanf("%s",stu[i].num);
printf("\n请输入姓名:\n");
scanf("%s",stu[i].name);
printf("\n请输入电话:\n");
scanf("%s",stu[i].tele);
printf(" \n请输入地址:\n");
scanf("%s",stu[i].add);
printf(" \n请输入emal:\n");
scanf("%s",stu[i].emal);
printf("编号:%s\n姓名:%s\n电话:%s\n地址:%s\nemal:%s\n",stu[i].num,stu[i].name,stu[i].tele,stu[i].add,stu[i].emal);
}
return n;
}
void xianshi(STUDENT stu[],int n)
{
int i;
for(i=0;i<=n-1;i++)
{
printf("编号:%s\n姓名:%s\n电话:%s\n地址:%s\nemal:%s\n",stu[i].num,stu[i].name,stu[i].tele,stu[i].add,stu[i].emal);
}
}
int find(STUDENT stu[],int n)
{
int i;
char s[20];
printf("请输入的姓名\n");
scanf("%s",s);
for(i=0;i<n;i++)
if(strcmp(s,stu[i].name)==0)
return i;
}
int shanchu(STUDENT stu[],int n)
{
int i,j,ch;
i=find(stu,n);
if(i>n-1)
{
printf("没有找到要删除的记录,是否重新输入1/0(1代表是0代表否)\n");
scanf("%d",&ch);
if(ch==1)
n=shanchu(stu,n);
}
else
{
printf("编号:%s\n姓名:%s\n电话:%s\n地址:%s\nemal:%s\n",stu[i].num,stu[i].name,stu[i].tele,stu[i].add,stu[i].emal);
printf("是否确定要删除:%d是%2d否\n",1,0);
}
scanf("%d",&ch);
if(ch==1)
{
for(j=i+1;j<N;j++)
{
strcpy(stu[j-1].name,stu[j].name);
strcpy(stu[j-1].tele,stu[j].tele);
strcpy(stu[j-1]. add,stu[j]. add);
strcpy(stu[j-1].emal,stu[j].emal);
}
n--;
printf(" 删除成功!\n");
}
return n;
}
void chazhao(STUDENT stu[],int n)
{
int i,ch;
i=find(stu,n);
if(i>n-1)
printf("没有找到要查找的记录,是否重新输入1/0\n");
scanf("%d",&ch);
if(ch==1)
chazhao(stu,n);
else
printf("编号:%s\n姓名:%s\n电话:%s\n地址:%s\nemal:%s\n",stu[i].num,stu[i].name,stu[i].tele,stu[i].add,stu[i].emal);
}
void xiugai(STUDENT stu[],int n)
{
int i,ch;
i=find(stu,n);
if(i>n-1)
{
printf("没有找到要修改的记录,是否重新输入1/0\n");
scanf("%d",&ch);
if(ch==1)
xiugai(stu,n);
}
else
{
printf("编号:%s\n姓名:%s\n电话:%s\n地址:%s\nemal:%s\n",stu[i].num,stu[i].name,stu[i].tele,stu[i].add,stu[i].emal);
printf("是否确定要修改:%d是%2d否\n",1,0);
}
scanf("%d",&ch);
if(ch==1)
{
printf("编号:\n");
scanf("%s",stu[i].num);
printf("\n姓名\n");
scanf("%s",stu[i].name);
printf(" \n电话:\n");
scanf("%s",stu[i].tele);
printf(" \n地址:\n");
scanf("%s",stu[i].add);
printf(" \nnemal:\n");
scanf("%s",stu[i].emal);
printf(" 修改成功!\n");
}
}
int tianjia(STUDENT stu[],int n)
{
int i,j;
if(N<=n+1)
printf("储存已满");
else
{
printf("请输入要插入的位置\n");
scanf("%d",&i);
for(j=n-1;j>=i;j--)
{
strcpy(stu[j+1].name,stu[j].name);
strcpy(stu[j+1].tele,stu[j].tele);
strcpy(stu[j+1].add,stu[j].add);
strcpy(stu[j+1].emal,stu[j].emal);
}
printf("请输入要插入的信息:\n");
printf("编号:\n");
scanf("%s",stu[i].num);
printf("\n请输入姓名:\n");
scanf("%s",stu[i].name);
printf(" \n请输入电话:\n");
scanf("%s",stu[i].tele);
printf(" \n请输入地址:\n");
scanf("%s",stu[i].add);
printf(" \n请输入emal:\n");
scanf("%s",stu[i].emal);
printf("添加成功!\n");
n++;
}
return n;
}
int tuichu()
{
int n;
n=-1;
printf(" 谢谢使用 ");
return n;
}