用C语言编写一个通讯录管理系统

要求:
(1)要有进入系统的友好操作界面;
(2)程序开始时能读取文本文件中的通讯录信息到内存中,并以链式存储结构存储(自选存储结构也可以);
(3)在内存中能实现通讯录信息的查找、添加、修改和删除;
(4)最后更新过的通讯录信息能够继续被保存到文本文档中。
至少需要有的操作:
1.查找通讯录
2.删除通讯录
3.添加通讯录
4.编辑通讯录
5.保存刚才的操作并退出
还可以更多...
使用到的函数及其功能说明:
(1) int f(int n); (例子)
功能:函数计算并返回n的阶乘。

C语言编写一个通讯录管理系统的源代码如下:

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

/*定义保存通迅录的信息*/

structfriends

{

charname[20];/*名字*/

charprovince[20];/*省份*/

charcity[20];/*所在城市*/

charnation[20];/*民族*/

charsex[2];/*性别M/F*/

intage;/*年龄*/

}

扩展资料

1、在C++中应该使用inline内连函数替代宏调用,这样既可达到宏调用的目的,又避免了宏调用的弊端。

2、在C语言两个函数的名称不能相同,否则会导致编译错误。在C++中,函数名相同而参数不同的两个函数被解释为重载。

3、在大型程序中,使函数名易于管理和使用,不必绞尽脑汁地去处理函数名。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-06-09
用c语音开发管理类程序得累4你。c语言你就当过程式开发的入门学习用吧。c++你就当面向对象开发的入门学习用。要想用它俩开发还得深入学习mfc afx什么的一堆类库,不适合开发界面复杂的信息管理类程序,得用第三方的组件(组件适合c++开发,要求效率高嘛:)。入门了,学学VB,PB,Delphi,C#,java啊什么的,非常适合这类应用的开发工作。
第2个回答  推荐于2017-11-25
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
#define maxlen 15
struct persons
{
int num;
char name[20];
char e_addr[20];
char tel_no[15];
char sim_no;
char arch;
}persons[maxlen];

typedef struct lnode{
int num;
char name[20];
char e_addr[20];
char tel_no[15];
char sim_no;
char arch;
struct lnode *next;
}listnode,*linklist;

linklist head=NULL,r=NULL;
listnode *s,*p0,*p1,*p2,*p3,*p4,*p5,*p6,*p7,*p8,*p9;
int i;
char name1[10],ch;char tel_no1[15];char arch1;char sim_no1;char e_addr1[20];
char s1[20];
FILE *fp;

void creat()
{
int j;
long k;
fp=fopen("数据文件.txt","r t");
if(fp!=NULL)
{for(i=0;i<=maxlen;i++ )
{ j=fgetc(fp);
if(j==EOF)
return;
k=i;
fseek(fp,k*sizeof(struct persons),0);
fread(&persons[i],sizeof(struct persons),1,fp);

s=(linklist)malloc(sizeof(listnode));
s->num=persons[i].num;
strcpy(s->name,persons[i].name);
strcpy(s->e_addr,persons[i].e_addr);
strcpy(s->tel_no,persons[i].tel_no);
s->sim_no=persons[i].sim_no;
s->arch=persons[i].arch;
if(head==NULL)
{head=s;r=head;head->next=NULL;}
else
{r->next=s;
r=s;r->next=NULL;
}}fclose(fp);}
else
{ fp=fopen("数据文件.txt","w");
i=1;
}
}
void ShowA()
{p1=head;

while(p1!=NULL)
{if(p1->arch=='A')
{
cout<<endl;
cout<<p1->name<<endl;
cout<<p1->tel_no<<endl;
cout<<p1->sim_no<<endl;}
p1=p1->next;continue;}
}
void ShowB()
{p1=head;

while(p1!=NULL)
{if(p1->arch=='B')
{
cout<<endl;
cout<<p1->name<<endl;
cout<<p1->tel_no<<endl;
cout<<p1->sim_no<<endl;}
p1=p1->next;continue;}
}
void ShowC()
{p1=head;

while(p1!=NULL)
{if(p1->arch=='C')
{
cout<<endl;
cout<<p1->name<<endl;
cout<<p1->tel_no<<endl;
cout<<p1->sim_no<<endl;}
p1=p1->next;continue;}
}
void Show()
{char ch1;
printf(" Which arch do you want to show?\n");
cout<<" A:同学同事"<<"B:家人"<<"C:其他"<<endl;
cout<<"请选择:"<<endl;
cin>>ch1;
switch(ch1)
{case'A':ShowA();break;
case'B':ShowB();break;
case'C':ShowC();break;
default:cout<<"error"<<endl;
}
}

void Delete()
{ printf("\n\n\t 请输入要删除用户的姓名:");

cin>>name1;
p4=head;
if(strcmp(p4->name,name1)==0)
{ p4=p4->next;
head=p4;
}
else
{ while(strcmp(p4->next->name,name1)!=0)
p4=p4->next;
p5=p4->next;
p4->next=p5->next;
free(p5);
}
}
void Input()
{ s=(linklist)malloc(sizeof(listnode));

printf("\n\n\t 请输入该用户的信息:");

cout<<"name:";
cin>>s->name;
cout<<"tel_no:";
cin>>s->tel_no;
cout<<"sim_no:";
cin>>s->sim_no;
cout<<"e_addr:";
cin>>s->e_addr;
cout<<"arch:";
cin>>s->arch;

if(head==NULL)printf("\n\n");
else
{p8=head;
while(p8!=NULL&&strcmp(s->name,p8->name)!=0&&strcmp(s->tel_no,p8->tel_no)!=0)
p8=p8->next;
if(p8!=NULL)
{printf(" 您添加的用户已存在!");
free(s);}}

if(head==NULL)
{head=s;head->next=NULL;}
else
{r->next=s;
r=s;r->next=NULL;}
}

void Alter()
{

printf("\n\n\t 请输入姓名:");

cin>>name1;
p3=head;
while(p3!=NULL&&strcmp(name1,p3->name)!=0)
p3=p3->next;
if(p3==NULL)
printf("\n\n\t 您选择的用户不存在!");
else
{ printf("\n\n\t 请输入该用户的新信息!");

cout<<"name:";
cin>>name1;
cout<<"tel_no:";
cin>>tel_no1;
cout<<"e_addr:";
cin>>e_addr1;
cout<<"sim_no:";
cin>>sim_no1;
cout<<"arch:";
cin>>arch1;
while(p9!=NULL&&strcmp(name1,p9->name)!=0&&strcmp(tel_no1,p9->tel_no)!=0)
p9=p9->next;
if(p9==NULL)
{strcpy(p3->name,name1);
strcpy(p3->tel_no,tel_no1);
strcpy(p3->e_addr,e_addr1);
p3->sim_no=sim_no1;
p3->arch=arch1;
}
else
printf(" 您添加的用户已存在!");

}
}
void Dial()
{int a;char b;
cout<<"1.拨叫用户:"<<endl;
cout<<"2.使用单键拨号:"<<endl;
cin>>a;
p0=head;
if(a==1)
{cout<<" 请输入拨叫用户的姓名:";
cin>>name1;
while(strcmp(name1,p0->name)!=0&&p0!=NULL)
p0=p0->next;
if(p0==NULL)
cout<<" 您选择的用户不存在!";
else
/*for(c=0;c<15;c++)
{cout<<endl;
cout<<(*p0).tel_no[c];}*/
{cout<<endl;
cout<<p0->tel_no;
cout<<endl;}
}
else
{cout<<"请输入单键号码:";
cin>>b;
while(p0!=NULL&&b!=p0->sim_no)
p0=p0->next;
if(p0==NULL)
cout<<" 您输入的单键号码不存在!";
else
{cout<<endl;
cout<<p0->name<<endl;
cout<<p0->tel_no;
cout<<endl;}
}
}

void Save()
{ int j;
fp=fopen("数据文件.txt","w");
for(p2=head,j=0;p2!=NULL;j++ ,p2=p2->next)
{
strcpy(persons[j].name,p2->name);
strcpy(persons[j].tel_no,p2->tel_no);
persons[j].sim_no=p2->sim_no;
strcpy(persons[j].e_addr,p2->e_addr);
persons[j].arch=p2->arch;
fwrite(&persons[j],sizeof(struct persons),1,fp);
}
}

void main()
{ creat();
do
{
printf(" **********************************************************");
printf("\n\n\n\n\t 欢迎来到通讯录!");
printf("\n\n\t\t 请选择操作:");
printf("\n\t\t1. 显示通讯录");
printf("\n\t\t2. 删除通讯录");

printf("\n\t\t3. 添加通讯录");
printf("\n\t\t4. 编辑通讯录");
printf("\n\t\t5. 拨号功能");
printf("\n\t\t6. 保存刚才的操作并退出\n");
printf(" **********************************************************");
printf("\n\n\n");
printf("\t 选择您想要的操作:");
cin>>ch;
switch(ch)
{ case '1': Show();
break;
case '2': Delete();
break;
case '3': Input();
break;
case '4': Alter();
break;
case '5': Dial();
break;
case '6': Save();
fclose(fp);
exit(0);
break;
default:
printf("\n\t*********************************\n");
printf("\n\t The num should 1-6!!! \n");
printf("\n\t**********************************");
break;
}
}while(1);
}

转的.......woyuyuchao本回答被提问者和网友采纳
第3个回答  2012-05-31
是否可以用C++写呢追问

我们只学了C语言呐!C++还不会呢。所以最好用C语言.. 不过我也不懂C++可不可以。最好有个说明,因为我不太会呢,都不懂是什么用途。。帮帮忙吧!!

相似回答