简单通讯录

#include <iostream>
#include <cstring>
#define N 100
using namespace std;
int counter=1;
struct txt
{
    char name[N][N];
    char place[N][N];
    char tel[N][N];
    char email[N][N];
};
txt add;
void Add()
{

    cout<<"输入姓名:";
    cin>>add.name[counter];
    cout<<endl<<"输入籍贯:";
    cin>>add.place[counter];
    cout<<endl<<"输入电话号码:";
    cin>>add.tel[counter];
    cout<<endl<<"输入电子邮箱:";
    cin>>add.email[counter];
    counter++;
}
void Sear()
{
    int i;
    char csear[N];
    int flag=0;
    memset(csear,0,sizeof(csear));
    cout<<"请输入:";
    cin>>csear;
    for(i=1;i<=counter;i++)
    {
        if(!strcmp(csear,add.name[i])||!strcmp(csear,add.place[i])||!strcmp(csear,add.tel[i])||!strcmp(csear,add.email[i]))
        {
            cout<<"姓名:"<<add.name[i]<<endl<<"籍贯:"<<add.place[i]<<endl<<"电话号码:"<<add.tel[i]<<endl<<"电子邮箱:"<<add.email[i]<<endl;
            flag=1;
        }
    }
    if(!flag)
    {
        cout<<"该条信息不存在"<<endl;
    }
}
void Alert()//修改
{
    char alert[N];
    memset(alert,0,sizeof(alert));
    cout<<"输入要修改的姓名或籍贯或电话或邮箱:";
    cin>>alert;
    int i;
    for(i=1;i<=counter;i++)
    {
        if(!strcmp(alert,add.name[i]))
        {
            memset(add.name[i],0,sizeof(add.name[i]));
            cout<<"修改为: ";
            cin>>add.name[i];
            break;
        }
        else if(!strcmp(alert,add.place[i]))
        {
            memset(add.place[i],0,sizeof(add.place[i]));
            cout<<"修改为: ";
            cin>>add.place[i];
            break;
        }
        else if(!strcmp(alert,add.tel[i]))
        {
            memset(add.tel[i],0,sizeof(add.tel[i]));
            cout<<"修改为: ";
            cin>>add.tel[i];
            break;
        }
        else if(!strcmp(alert,add.email[i]))
        {
            memset(add.email[i],0,sizeof(add.email[i]));
            cout<<"修改为: ";
            cin>>add.email[i];
            break;
        }
    }
}
void Glance()
{
    for(int i=1;i<counter;i++)
    {
        cout<<"姓名:"<<add.name[i]<<endl<<"籍贯:"<<add.place[i]<<endl<<"电话号码:"<<add.tel[i]<<endl<<"电子邮箱:"<<add.email[i]<<endl;
    }
}
void Delete()
{
    char del[N];
    cout<<"输入想要删除的信息所包含的名字或电话或籍贯或邮箱:";
    memset(del,0,sizeof(del));
    cin>>del;
    int flag=0;
    for(int i=1;i<counter;i++)
    {
        if(!strcmp(del,add.name[i])||!strcmp(del,add.place[i])||!strcmp(del,add.tel[i])||!strcmp(del,add.email[i]))
        {
            memset(add.name[i],0,sizeof(add.name[i]));
            memset(add.email[i],0,sizeof(add.email[i]));
            memset(add.place[i],0,sizeof(add.place[i]));
            memset(add.tel[i],0,sizeof(add.tel[i]));
            flag=1;
        }
    }
    if(!flag)
    {
        cout<<"不存在这条信息"<<endl;
    }
}
int main()
{
    cout<<"添加联系人:1"<<endl<<"查询------:2"<<endl
    <<"修改------:3"<<endl<<"浏览------:4"<<endl<<"删除------:5"<<endl<<"退出------:6"<<endl;
    int a;
    while(1)
    {
        cin>>a;
        switch(a)
        {
            case(1):Add();break;
            case(2):Sear();break;
            case(3):Alert();break;//修改
            case(4):Glance();break;//浏览
            case(5):Delete();break;
            case(6):return 0;
            default:cout<<"输入错误,再输一遍";
        }
    }
    return 0;
}

转载于:https://www.cnblogs.com/Scale-the-heights/p/4322375.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值