用c语言编写通讯录 5

题目三通讯录1.设计要求:基本功能:a)添加个人信息b)查询个人信息c)删除个人信息d)修改个人信息e)信息排序f)输出全部信息拓展功能:采用文件形式对通讯录进行操作,包... 题目三 通讯录
1. 设计要求:
基本功能:
a) 添加个人信息
b) 查询个人信息
c) 删除个人信息
d) 修改个人信息
e) 信息排序
f) 输出全部信息
拓展功能:
采用文件形式对通讯录进行操作,包括:
a) 写入文件
b) 读取文件
创新(自拟)功能:
程序实现的其它功能由个人自拟。

2. 设计要求具体说明
通讯录至少应该有以下数据项:姓名,家庭住址,手机号码,邮编,E-mail。
输入信息时要检查数据项手机、邮编、E-mail的合法性,手机号码:11位数字;邮编:6位数字;E-mail:包含@字符,且@两边都非空。
对通讯录应该包含有以下操作(包括基本功能和拓展功能):
a) 向通讯录中添加信息;
b) 在通讯录中按姓名或手机号查找个人信息;
c) 删除通讯录中的个人信息;
d) 修改通讯录中的个人信息,并保存入文件;
e) 按不同数据项排序后列表输出通讯录中所有人的信息。通讯录中记录的数量没有限制。
f) 将通讯录中的数据写入文件和从文件读入数据。
程序启动时先从文件读入数据,如果文件中没有数据则给出提示;写入文件时有两种方式,一为覆盖所有原有的内容; 二为只将本次操作所修改的个人信息写入文件
g) 程序启动时先从文件读入数据,如果文件中没有数据则给出提示退出程序。

3. 设计提示
定义合适的结构体类型,使用链表或数组的方式组织数据。
展开
 我来答
沸慢柔j
2010-07-08
知道答主
回答量:15
采纳率:0%
帮助的人:4.4万
展开全部
自己写的,看一下

// 头文件部分

//============================
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>

#include <conio.h>

// 初始化数据部分
int Menu();
void Start();
void Write();
void Read();
void Search();
void Detele();
void beauty();
void Rework();
void Lock();
int Judge();
//============================
struct Student{
char name[20];
char Tel[20];
char QQ[20];
int age;
}xy[100];
char wenjian[10000];
char Number[10];
char number=0;
int GOTO;
//
int main()
{
Start();
for(;;)
{
GOTO=Menu();
if(GOTO==1)
{
for(;;)
{
Write();
int judge=Judge();
if(judge==2)
{
break;
}
}
}
if(GOTO==2)
{
for(;;)
{
Read();
system("pause");
break;
}
}
if(GOTO==3)
{
for(;;)
{
Search();
int judge=Judge();
if(judge==2)
{
break;
}
}
}
if(GOTO==4)
{
for(;;)
{
Rework();
int judge=Judge();
if(judge==2)
{
break;
}
}
}
if(GOTO==5)
{
Detele();
break;
}
if(GOTO==6)
{
beauty();
break;
}
if(GOTO==7)
{
}
if(GOTO==8)
{
printf("");
break;
}
if(GOTO==9)
{
printf("\t\t\t退出系统\n\n");
return 0;
}
if(GOTO==0)
{
printf("");
break;
}
}
// beauty();
//
// Write();
// Read();
// Search();
// Rework();
// Detele();
return 0;
}

void Write()
{
printf("\t\t\t请输入好友名字\n");
scanf("%s",&xy[number].name);
printf("\t\t\t请输入好友电话号码\n");
scanf("%s",&xy[number].Tel);
printf("\t\t\t请输入好友QQ号码\n");
scanf("%s",&xy[number].QQ);
printf("\t\t\t请输入好友年龄\n");
scanf("%d",&xy[number].age);

FILE *file;
if((file=fopen("Friend.txt","rt"))==NULL)
{
file=fopen("Friend.txt","wt");
fprintf(file,"%-20s%-20s%-20s%-20s","姓名","电话","QQ","年龄");
}
file=fopen("Friend.txt","at");
fprintf(file,"%-20s%-20s%-20s%-20d\n",xy[number].name,xy[number].Tel,xy[number].QQ,xy[number].age);
fclose(file);
number++;
Number[0]=number;
FILE * Sta;
if((Sta=fopen("number.txt","r"))=NULL)
{
Sta=fopen("number.txt","wt");
exit(1);
}
Sta=fopen("number.txt","wt");
fprintf(Sta,"%d",Number[0]);

fclose(Sta);
}

void Read()
{
printf("\t\t\t您通讯录中一共有%d位好友\n",Number[0]);

FILE* read;
if((read=fopen("Friend.txt","r"))=NULL)
{
printf("\t\t\t您通讯中当前没有好友,请返回添加\n");
}
read=fopen("Friend.txt","rt");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
for(int i=0;i<number;i++)
{

fscanf(read,"%s%s%s%d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,&xy[i].age);

printf("%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);

}
/* fread(wenjian,10000,1,read);
for(int i=0;i<number*80+80;i++)
{
printf("%c",wenjian[i]);

}
printf("\n");
*/

fclose(read);
}

void beauty()
{

int d;
do{
printf("choose");
scanf("%d",&d);
}while(d<1&&d>5);
if(d==1)
{
system("color 27");
printf("===1===");

}
if(d==2)
{
system("color 37");
printf("===2===");
}
if(d==3)
{
system("color 47");
printf("===3===");
}
if(d==4)
{
system("color 57");
printf("===4===");
}
if(d==5)
{
system("color 67");
printf("===5===");
}

}
void Start()
{
FILE* Start;
if((Start=fopen("number.txt","r"))==NULL)
{
Start=fopen("number.txt","w");
number=0;
Number[0]=number;
fscanf(Start,"%d",&Number[0]);
printf("\t\t\t您的通讯录中还没有任何好友,赶快添加吧.此次操作需要重新运行程序。\n");
exit(1);
}
Start=fopen("number.txt","r");
fscanf(Start,"%d",&Number[0]);

number=Number[0];

fclose(Start);

}

void Search()
{
int change=0;
char Searchname[20];
printf("\t\t\t输入要查找的好友的名字\n\n");
scanf("%s",&Searchname);
fflush(stdin);
printf("\t\t\t您要查找的好友是 %s \n\n",Searchname);

FILE *Search;
Search=fopen("Friend.txt","rt");

for(int i=0;i<=number;i++)
{

fscanf(Search,"%s%s%s%d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,&xy[i].age);

if(strcmp(xy[i].name,Searchname)==0)
{
printf("\t\t\t下面是该好友的信息:\n\n");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
printf("%-20s%-20s%-20s%-20d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,xy[i].age);
change=1;
}

fclose(Search);
}
if(change==0)
{
printf("\t\t\t您要查找的好友不存在,请返回菜单添加。\n");
}
}

void Rework()
{
char Rework[20];
printf("\t\t\t输入要修改的好友的名字\n\n");
scanf("%s",&Rework);

printf("\t\t\t您要修改 %s 的信息\n\n",Rework);
int Change=0;
FILE *Search;
Search=fopen("Friend.txt","rt");

for(int i=0;i<=number;i++)
{

fscanf(Search,"%s%s%s%d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,&xy[i].age);

if(strcmp(xy[i].name,Rework)==0)
{
printf("\t\t\t下面是该好友的信息:\n\n");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
Change=1;
int Choose;
printf("%-20s%-20s%-20s%-20d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,xy[i].age);
//---------------------------------------------------------------------
do
{
printf("\t\t\tchoose\t\t\t1-----3");

scanf("%d",&Choose);
}while(Choose>3||Choose<1);
if(Choose==1){

printf("\t\t\t请输入好友电话号码\n");
scanf("%s",&xy[i].Tel);
}
if(Choose==2)
{
printf("\t\t\t请输入好友QQ号码\n");
scanf("%s",&xy[i].QQ);
}
if(Choose==3)
{
printf("\t\t\t请输入好友年龄\n");
scanf("%d",&xy[i].age);
}

Search=fopen("Friend.txt","wt");
for(int sta=0;sta<i;sta++)
{
fprintf(Search,"%-20s%-20s%-20s%-20d\n",xy[sta].name,xy[sta].Tel,xy[sta].QQ,xy[sta].age);
}
if(sta==i)
{
fprintf(Search,"%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);
i++;
}
for(i;i<=number;i++)
{
fprintf(Search,"%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);
}
printf("\t\t\t修改后的信息为:\n\n");
Read();

}

fclose(Search);
}
if(Change==0)
{
printf("\t\t\t您要查找的好友不存在,请返回菜单添加。\n");
}
}
void Detele()
{

int change=0;
char delete_friend[20];
printf("\t\t\t输入要删除的好友的名字\n\n");
scanf("%s",&delete_friend);
fflush(stdin);
printf("\t\t\t您要删除的好友是 %s \n\n",delete_friend);

FILE *DeleteF;
DeleteF=fopen("Friend.txt","rt");

for(int i=0;i<=number;i++)
{

fscanf(DeleteF,"%s%s%s%d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,&xy[i].age);

if(strcmp(xy[i].name,delete_friend)==0)
{
printf("\t\t\t下面是该好友的信息:\n\n");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
printf("%-20s%-20s%-20s%-20d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,xy[i].age);
change=1;

DeleteF=fopen("Friend.txt","wt");
for(int st=0;st<i;st++)
{
fprintf(DeleteF,"%-20s%-20s%-20s%-20d\n",xy[st].name,xy[st].Tel,xy[st].QQ,xy[st].age);

}
i++;
for(i;i<=number;i++)
{
printf("%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);
fprintf(DeleteF,"%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);
}
}
//--------------------------------------------------------------------------------

if(change==1)
{
printf("\t\t\t删除后的通讯录信息为:\n\n");

number--;
Number[0]=number;
FILE * St;
if((St=fopen("number.txt","r"))=NULL)
{
St=fopen("number.txt","wt");
exit(1);
}
St=fopen("number.txt","wt");
fprintf(St,"%d",Number[0]);

fclose(St);

fclose(DeleteF);
Start();
Read();
}
}

if(change==0)
{
printf("\t\t\t您要删除的好友不存在。\n");
}

}

void Lock()
{

}

int Menu()
{
printf("\t\t*****欢迎进入通讯管理界面*****\n\n");

printf("\t\t\t1.添加我的好友\n");
printf("\t\t\t2.显示所有好友\n");
printf("\t\t\t3.查找我的好友\n");
printf("\t\t\t4.修改好友信息\n");
printf("\t\t\t5.删除我的好友\n");
printf("\t\t\t6.设置背景颜色\n");
printf("\t\t\t7.设置管理密码\n");
printf("\t\t\t8.使用注意事项\n");
printf("\t\t\t9.退出通讯系统\n");
printf("\t\t\t0.作者想说的话\n");
printf("\t\t******************************\n\n");

do{
printf("\t\t\t请输入你的选择:\n\n");
scanf("%d",&GOTO);
}while(GOTO>9||GOTO<1);
return GOTO;
}

int Judge()
{
char JUDGE;
do
{
printf("\t\t\t是否继续当前操作\n\n Y(yes) / N(no)\n");
printf("\t\t\t输入你的选择\n");
JUDGE=getch();
if(JUDGE=='y'||JUDGE=='Y')
{
return 1;
}
if(JUDGE=='n'||JUDGE=='N')
{
return 2;
}
}while(JUDGE!='y'||JUDGE!='n');

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
推荐于2016-05-03
展开全部
#include<stdio.h>
#include<string.h>
#include<alloc.h>

FILE *fp;
int i;
char ch;

/*Address Struct Definition*/
struct member
{ int number;
char name[20];
char telephone[13];
char address[50];
char post[6];
}members[50];

void Data_Menu()
{ printf("\n---------------------------menu---------------------------\n");
printf(" 1.Add");
printf(" 2.Delete");
printf(" 3.Search");
printf(" 4.Save");
printf(" 5.Showall")
printf(" 6.Exit");
printf("\n-----------------------------------------------------------\n");
}

void Data_Load()
{ int j;
long k;
fp=fopen("members.txt","rt");
if(fp!=NULL)
{ for(i=1;i<50;i++)
{ j=fgetc(fp);
if(j==EOF)
{ return;
}
k=i-1;
fseek(fp,k*sizeof(struct member),SEEK_SET);
fread(&members[i],sizeof(struct member),1,fp);
}
}
else
{ fp=fopen("members.txt","w");
i=1;
}
}

void Data_Add(int j)
{ printf("\n");
members[j].number=j;
printf("\n\tNo:%d",j);
printf("\n\tName:");
scanf("%s",members[j].name);
printf("\tTelephone:");
scanf("%s",members[j].telephone);
printf("\tAddress:");
scanf("%s",members[j].address);
printf("\tPost:");
scanf("%s",members[j].post);
}

void Data_Show(int j)
{ printf("\n\tNo:%d",members[j].number);
printf("\n\tName:%s",members[j].name);
printf("\n\tTelephone:%s",members[j].telephone);
printf("\n\tAddress:%s",members[j].address);
printf("\n\tPost:%s",members[j].post);
}

void Data_Showall(int j)
{ printf("\n\tNo:%d",members[j].number);
printf("\n\tName:%s",members[j].name);
printf("\n\tTelephone:%s",members[j].telephone);
printf("\n\tAddress:%s",members[j].address);
printf("\n\tPost:%s",members[j].post);
}

void Data_Save()
{ int j;
fp=fopen("members.txt","w");
for(j=1;j<=i;j++)
{ fwrite(&members[j],sizeof(struct member),1,fp);}
}

main()
{ char *search_name;
int j,k;
Data_Load();
i--;
do
{Data_Menu();
printf(" Please Choose:");
ch=getche();
switch(ch)
{ case '1':
while(i<50)
{ i++;
Data_Add(i);
break;
}
if(i==50)
{printf("\n\tMessage is Filled!\n");}
break;
case '2':
if(i<1)
{ printf("\n\tNo Records\n");
break;
}
printf("\n\tDelete No:");
scanf("%d",&k);
for(j=k;j<i;j++){
strcpy(members[j].name,members[j+1].name);
strcpy(members[j].telephone,members[j+1].telephone);
strcpy(members[j].address,members[j+1].address);
strcpy(members[j].post,members[j+1].post);
}
i--;
break;
case '3':
printf("\n\tPlease Input Search Name:");
search_name = (char *)malloc(20);
gets(search_name);
for(j=1;j<=i;j++)
{ if(strcmp(search_name,members[j].name)==0){
Data_Show(j);
break;
}
}
free(search_name);
break;
case '4':
Data_Save();
printf(" Date is Saved!\n");
fclose(fp);
break;
case '6':
printf("\n\t");
printf(" Do You Want To Save Message(y/n)");
if(getche()=='y')
{Data_Save();}
fclose(fp);
exit(0);
break;
default:
break;
case '5':
for(j=1;j<=i;j++)
Data_Showall(j);
break;
}
}while(1);
}

ustb的?这个要tc编译
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式