同学录C语言程序设计,C语言同学录实现

实现一个通讯录;

通讯录可以用来存储1000个人的信息,每个人的信息包括:

姓名、性别、年龄、电话、住址

提供方法:

1.添加联系人信息

2.删除指定联系人信息

3.查找指定联系人信息

4.修改指定联系人信息

5.显示所有联系人信息

6.清空所有联系人

contacts.h

#ifndef CONTACTS_H

#define CONTACTS_H

#endif

#include

#include

#include

#define NAME_LENGTH 100

#define SEX_LENGTH 20

#define TELE_LENGTH 20

#define ADDS_LENGTH 20

#define MAX 1000

struct peopleInfo

{

char name[NAME_LENGTH];

char sex [SEX_LENGTH];

int age;

char tele[TELE_LENGTH];

char adds[ADDS_LENGTH];

};

struct contacts

{

struct peopleInfo person[MAX];

int count_user;

};

typedef struct contacts *pContacts;

int add_contacts(pContacts pcon);

int del_contacts(pContacts pcon);

int Modify_contacts(pContacts pcon);

int show_contacts(pContacts pcon);

int find_contacts(pContacts pcon);

int clear_contacts(pContacts pcon);

contac.cpp

#include

int find_entry(pContacts pcon)

{

int i=0;

char name[NAME_LENGTH];

printf("请输入要查找的名字\n");

scanf("%s",&name);

for(i==0;icount_user;i++)

{

if (strcmp(pcon->person->name,name)==0)

{

return i;

}

}

return -1;

}

int add_contacts(pContacts pcon)

{

if (pcon->count_user==MAX)

{

printf("通讯录已满\n");

return -1;

}

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

scanf("%s",pcon->person[pcon->count_user].name);

printf("请输入性别\n");

scanf("%s",pcon->person[pcon->count_user].sex);

printf("请输入年龄\n");

scanf("%d",pcon->person[pcon->count_user].age);

printf("请输入电话\n");

scanf("%s",pcon->person[pcon->count_user].tele);

printf("请输入地址\n");

scanf("%s",pcon->person[pcon->count_user].adds);

pcon->count_user++;

return 1;

}

int del_contacts(pContacts pcon)

{

int rel=find_entry(pcon);

if (rel!=-1)

{

for (int i=rel;icount_user;i++)

{

pcon->person[i]=pcon->person[i+1];

}

pcon->count_user--;

return 1;

}

else

{

printf("不存在\n");

return -1;

}

}

int clear_contacts(pContacts pcon)

{

pcon->count_user=0;

return 1;

}

int find_contacts(pContacts pcon)

{

int ret=find_entry(pcon)

if (ret!=-1)

{

printf("%s",pcon->person->name);

printf("%s",pcon->person->sex);

printf("%s",pcon->person->tele);

printf("%s",pcon->person->adds);

printf("%d",pcon->person->age);

return 1;

}

else

{

printf("不存在\n");

return -1;

}

}

int Modify_contacts(pContacts pcon)

{

int rel=find_entry(pcon);

if (rel!=-1)

{

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

scanf("%s",pcon->person[pcon->count_user].name);

printf("请输入性别\n");

scanf("%s",pcon->person[pcon->count_user].sex);

printf("请输入年龄\n");

scanf("%d",pcon->person[pcon->count_user].age);

printf("请输入电话\n");

scanf("%s",pcon->person[pcon->count_user].tele);

printf("请输入地址\n");

scanf("%s",pcon->person[pcon->count_user].adds);

pcon->count_user++;

return 1;

}

else

{

printf("不存在\n");

return -1;

}

}

int show_contacts(pContacts pcon)

{

int i=0;

printf("\tname\tsex\t\tage\t\ttele\t\t\taddr\n");

for (i=0;icount_user;i++)

{

printf("%10s\t",pcon->person->name);

printf("%5s\t",pcon->person->sex);

printf("%10d\t",pcon->person->age);

printf("%15s\t",pcon->person->tele);

printf("%20s\t",pcon->person->adds);

}

printf("\n");

}

main.cpp

#include

int main()

{

int n;

struct contacts ;

people.count_user=0;

printf("请输入一个数:\n");

scanf("%d",&n);

switch (n)

{

case 1 :

add_contacts(&people);

break;

case 2 :

del_contacts(&people);

break;

case 3 :

show_contacts(&people);

break;

case 4 :

Modify_contacts(&people);

break;

case 5 :

clear_contacts(&people);

break;

default:

printf("输入错误\n");

break;

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值