我是靠谱客的博主 温婉指甲油,最近开发中收集的这篇文章主要介绍通讯录管理系统升级版,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

扯点题外话:虽然这是去年的课设作业,但是感觉最近有好多人问,我就干脆发出来算了

题目要求:

大体是这样的:给你一个手机,你这个手机有两个存储部分,分别是手机本地存储和手机卡存储,是不是很像老年机(笑,之后就是些基本的增删改查操作,然后为了方便管理,我这里存储数据用的是vector,c语言选手需要注意下(c++选手可以直接无视

ok,接下来就是基本的功能:

1.首先我们有一个父类手机类Phone_contacts

2.然后我们创建一个手机卡类继承于手机类SIM_card_contacts

3.不要忘记构造函数给父类赋值

4.重载输入输出(虽然没卵用

5.手机卡和手机联系人间的移动,复制等

6.可以实现去重操作,即同一联系人只会被保留一次

7/文件操作,可以实现记忆化存储读取(没bug哦

8.菜单UI太丑了轻点喷

下面直接上代码吧,懒得分文件了(诶,我有分完了的,但我不发,就是玩)

大概一千多行,可能很长,不过分的还可以,函数名应该属于人类能看懂的程度,实在看不懂可以私信我。

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <vector>
using namespace std;

class Phone_contacts
{
protected:
    string name;
    string tel;
public:
    Phone_contacts(string a = " ", string b = " "): name(a), tel(b) {};
    void set(string, string);
    string get_tel();
    string get_name();
    void modify();
    friend istream &operator >> (istream &in, Phone_contacts &qaq);
    friend ostream &operator << (ostream &out, Phone_contacts &qaq);
};
void Phone_contacts::set(string a, string b)
{
    name = a, tel = b;
}

void Phone_contacts::modify()
{
    int op;
    string a,b;
    cout << "请输入你要修改的信息" << endl;
    cout << "姓名输入1,电话号码输入2,都修改输入3" << endl;
    cin >> op;
    if (op == 1)
    {
        cout << "请输入新的姓名" << endl;
        cin >> a;
        name = a;
    }
    else if (op == 2)
    {
        cout << "请输入新的电话号码" << endl;
        cin >> a;
        tel = a;
    }
    else if (op == 3)
    {
        cout << "请依次输入新的姓名和电话号码" << endl;
        cin >> a >> b;
        name = a;
        tel = b;
    }
    else
    {
        cerr << "选择错误,请重试" << endl;
        abort();
    }
}


string Phone_contacts::get_name()
{
    return name;
}

string Phone_contacts::get_tel()
{
    return tel;
}

istream &operator >> (istream &in, Phone_contacts &qaq)
{
    cout << "请输入姓名" << endl;
    in >> qaq.name;
    cout << "请输入电话号码" << endl;
    in >> qaq.tel;
    return in;
}

ostream &operator << (ostream &out, Phone_contacts &qaq)
{
    out << qaq.name << qaq.tel;
    return out;
}


class SIM_card_contacts: public Phone_contacts
{
    string hometown;
    string qq;
public:
    void set(string a = " ", string b = " ", string c = " ", string d = " ")
    {
        Phone_contacts::set(a,b);
        hometown = c;
        qq = d;
    }
    void modify();
    string get_hometown();
    string get_qq();
    friend istream &operator >> (istream &in,  SIM_card_contacts &qaq);
    friend ostream &operator << (ostream &out, SIM_card_contacts &qaq);

};


void SIM_card_contacts::modify()
{
    int op;
    string a,b,c,d;
    cout << "请输入你要修改的信息" << endl;
    cout << "姓名输入1,电话号码输入2,籍贯输入3,qq输入4,都修改输入5" << endl;
    cin >> op;
    if (op == 1)
    {
        cout << "请输入新的姓名" << endl;
        cin >> a;
        name = a;
    }
    else if (op == 2)
    {
        cout << "请输入新的电话号码" << endl;
        cin >> a;
        tel = a;
    }
    else if (op == 3)
    {
        cout << "请输入新的籍贯" << endl;
        cin >> a;
        hometown = a;
    }
    else if (op == 4)
    {
        cout << "请输入新的qq" << endl;
        cin >> a;
        qq = a;
    }
    else if (op == 5)
    {
        cout << "请依次输入新的姓名和电话号码" << endl;
        cin >> a >> b >> c >> d;
        name = a;
        tel = b;
        hometown = c;
        qq = d;
    }
    else
    {
        cerr << "选择错误,请重试" << endl;
        abort();
    }
}

string SIM_card_contacts::get_hometown()
{
    return hometown;
}

string SIM_card_contacts::get_qq()
{
    return qq;
}

istream &operator >> (istream &in,  SIM_card_contacts &qaq)
{
    cout << "请输入姓名" << endl;
    in >> qaq.name;
    cout << "请输入电话号码" << endl;
    in >> qaq.tel;
    cout << "请输入籍贯" << endl;
    in >> qaq.hometown;
    cout << "请输入qq" << endl;
    in >> qaq.qq;
    return in;
}

ostream &operator << (ostream &out,  SIM_card_contacts &qaq)
{
    out << qaq.name << qaq.tel << qaq.hometown << qaq.qq;
    return out;
}


class address_book
{
public:
    virtual void Add() = 0;
    virtual void Delete() = 0;
    virtual void Display() = 0;
    virtual void Modify() = 0;
    virtual void query() = 0;
};


class mobile_phone_address_book: public address_book
{
    int cnt;
public:
    vector<Phone_contacts> my_phone_contacts;
    mobile_phone_address_book();
    ~mobile_phone_address_book();
    void Add();
    void Delete();
    void Display();
    void Modify();
    void query();
    void copy(string ,string);
    int get_cnt();
    void clear_phone();
};
mobile_phone_address_book:: mobile_phone_address_book()
{
    cnt = -1;
    string names, tels;
    Phone_contacts pp;
    ifstream infile;
	infile.open("test_1.txt", ios::in);
	if (!infile)
	{
		cerr << "读取文件失败" << endl;
        abort();
	}
    char s[100];
    infile.getline(s,100);
    infile.getline(s,100);
    while(infile >> names >> tels)
    {
        bool flag = false;
        pp.set(names,tels);
        for (auto &aa : my_phone_contacts)
        {
            if (aa.get_tel() == pp.get_tel())
            {
                cout << "已存在相同号码的联系人,无法添加" << endl;
                flag = true;
                break;
            }
        }
        if (!flag)
        {
            my_phone_contacts.push_back(pp);
            cnt ++;
        }
    }
    infile.close();
}

void mobile_phone_address_book::Add()
{
    if (cnt >= 1000)
    {
        cerr << "超过容量上限,无法继续存入" << endl;
        abort();
    }
    Phone_contacts pp;
    cin >> pp;
    for (auto &aa : my_phone_contacts)
    {
        if (aa.get_tel() == pp.get_tel())
        {
            cout << "已存在相同号码的联系人,无法进行添加" << endl;
            return;
        }
    }
    my_phone_contacts.push_back(pp);
    cnt ++;
}

void mobile_phone_address_book::Delete()
{
    if (cnt < 1)
    {
        cout << "不存在联系人,无法删除" << endl;
    }
    cout << "请输入想要删除联系人的电话号码" << endl;
    string tels;
    cin >> tels;
    bool flag = 0;
    vector<Phone_contacts>::iterator it;
    for (it = my_phone_contacts.begin();it != my_phone_contacts.end(); it ++)
    {
        if ((*it).get_tel() == tels)
        {
            my_phone_contacts.erase(it);
            flag = 1;
            cnt --;
            break;
        }
    }
    if (flag)
    {
        cout << "删除成功" << endl;
    }
    else
    {
        cout << "未找到该名联系人" << endl;
    }
}

void mobile_phone_address_book::Display()
{
    cout << "姓名" << "tt" << "电话号码" << endl;
    for (auto &aa : my_phone_contacts)
    {
        cout << aa.get_name() << 't' << aa.get_tel() << endl;
    }
}

void mobile_phone_address_book::Modify()
{
    int op = 0;
    cout << "请输入您想修改的值" << endl;
    cout << "按检索姓名请输入1,按电话号码检索请输入2" << endl;
    cin >> op;
    if (op == 1)
    {
        string pre_name;
        cout << "请输入要修改的名字" << endl;
        cin >> pre_name;
        for (auto &aa : my_phone_contacts)
        {
            if (aa.get_name() == pre_name)
            {
                aa.modify();
            }
        }
    }
    else if (op == 2)
    {
        string pre_tel;
        cout << "请输入要修改的电话号码" << endl;
        cin >> pre_tel;
        for (auto &aa : my_phone_contacts)
        {
            if (aa.get_tel() == pre_tel)
            {
                aa.modify();
            }
        }
    }
    else
    {
        cerr << "输入错误,请重试" << endl;
        abort();
    }
}

void mobile_phone_address_book::query()
{
    cout << "请输入您想要的查询方式" << endl;
    cout << "按姓名查询请输入1,按电话号码查询请输入2" << endl;
    int op;
    cin >> op;
    if (op == 1)
    {
        string q_name;
        cout << "请输入想要查询的姓名" << endl;
        cin >> q_name;
        for (auto &aa : my_phone_contacts)
        {
            if (aa.get_name() == q_name)
            {
                cout << "姓名为: " << aa.get_name() << "t" << "电话号码为: " << aa.get_tel() << endl;
            }
        }
    }
    else if (op == 2)
    {
        string q_tel;
        cout << "请输入想要查询的电话号码" << endl;
        cin >> q_tel;
        for (auto &aa : my_phone_contacts)
        {
            if (aa.get_tel() == q_tel)
            {
                cout << "姓名为: " << aa.get_name() << "t" << "电话号码为: " << aa.get_tel() << endl;
            }
        }
    }
    else
    {
        cerr << "输入错误,请重试" << endl;
        abort();
    }
}

int mobile_phone_address_book::get_cnt()
{
    return cnt;
}

void mobile_phone_address_book::copy(string pname, string ptel)
{
    if (cnt > 1000)
    {
        cerr << "超过容量上限,无法继续存入" << endl;
        abort();
    }
    for (auto &aa : my_phone_contacts)
    {
        if(aa.get_name() == pname && aa.get_tel() == ptel)
        {
            cout<<"所复制联系人的信息中,有原本原来已经存在,跳过存在联系人的复制"<<endl;
            return ;
        }
    }
    Phone_contacts temp;
    temp.set(pname,ptel);
    my_phone_contacts.push_back(temp);
    cnt ++;
}

void mobile_phone_address_book::clear_phone()
{
    my_phone_contacts.clear();
    cnt = 0;
}


mobile_phone_address_book::~mobile_phone_address_book()
{
    ofstream outfile;
    outfile.open("test_1.txt",ios::out);
    if (!outfile)
    {
        cerr << "读取文件失败" << endl;
        abort();
    }
    outfile << "====================通讯录管理系统====================" << endl;
    outfile << "姓名" << "ttt" << "电话号码" << endl;

    for (auto &aa : my_phone_contacts)
    {
        outfile << aa.get_name() << " " << aa.get_tel() << " " << endl;
    }
    outfile.close();
}


class phone_card_address_book: public address_book
{
    int cnt;
public:
    vector<SIM_card_contacts> my_sim_card_contacts;
    phone_card_address_book();
    ~phone_card_address_book();
    void Add();
    void Delete();
    void Display();
    void Modify();
    void query();
    void copy(string, string);
    int get_cnt();
    void clear_card();
};
phone_card_address_book::phone_card_address_book()
{
    cnt = -1;
    string names,tels,hometowns,qqs;
    SIM_card_contacts pp;
    ifstream infile;
    infile.open("test_2.txt",ios::in);
    if (!infile)
    {
        cerr << "读取文件失败" << endl;
        abort();
    }
    char s[100];
    infile.getline(s,100);
    infile.getline(s,100);
    while(infile >> names >> tels >> hometowns >> qqs)
    {
        pp.set(names,tels,hometowns,qqs);
        my_sim_card_contacts.push_back(pp);
        cnt ++;
    }
    infile.close();
}

void phone_card_address_book::Add()
{
    if (cnt >= 1000)
    {
        cerr << "超过容量上限,无法继续存入" << endl;
        abort();
    }
    SIM_card_contacts pp;
    cin >> pp;
    for (auto &aa : my_sim_card_contacts)
    {
        if (aa.get_tel() == pp.get_tel())
        {
            cout << "已存在相同号码的联系人,无法进行添加" << endl;
            return;
        }
    }
    my_sim_card_contacts.push_back(pp);
    cnt ++;
}

void phone_card_address_book::Delete()
{
    if (cnt < 1)
    {
        cerr << "不存在联系人,无法删除" << endl;
        abort();
    }
    vector<SIM_card_contacts>::iterator it;
    cout << "请输入检索联系人的方式" << endl;
    cout << "按电话号码检索请输入1,按qq请输入2" << endl;
    int op;
    cin >> op;
    if (op == 1)
    {
        cout << "请输入要删除联系人的电话号码" << endl;
        string delete_tel;
        cin >> delete_tel;
        bool flag = 0;
        for (it = my_sim_card_contacts.begin();it != my_sim_card_contacts.end(); it ++)
        {
            if ((*it).get_tel() == delete_tel)
            {
                my_sim_card_contacts.erase(it);
                flag = 1;
                cnt --;
                break;
            }
        }
        if (flag)
        {
            cout << "删除成功" << endl;
        }
        else
        {
            cout << "不存在该名联系人" << endl;
        }

    }
    else if (op == 2)
    {
        cout << "请输入要删除联系人的qq" << endl;
        string delete_qq;
        cin >> delete_qq;
        bool flag = 0;
        for (it = my_sim_card_contacts.begin();it != my_sim_card_contacts.end(); it ++)
        {
            if ((*it).get_qq() == delete_qq)
            {
                my_sim_card_contacts.erase(it);
                flag = 1;
                cnt --;
                break;
            }
        }
        if (flag)
        {
            cout << "删除成功" << endl;
        }
        else
        {
            cout << "不存在该名联系人" << endl;
        }
    }
    else
    {
        cerr << "输入错误,请重试" << endl;
        abort();
    }
}

void phone_card_address_book::Display()
{
    cout << "姓名" << "t" <<"电话号码"<< "t" << "籍贯" << "ttt" << "qq" << endl;
    for (auto &aa : my_sim_card_contacts)
    {
        cout << aa.get_name() << 't' << aa.get_tel() << 't' << aa.get_hometown() << 't' << aa.get_qq() << endl;
    }
}

void phone_card_address_book::Modify()
{
    int op = 0;
    cout << "请输入您想修改的值" << endl;
    cout << "按姓名检索请输入1,按电话号码检索请输入2" << endl;
    cout << "按籍贯检索请输入3,按qq检索请输入4" << endl;
    cin >> op;
    if (op == 1)
    {
        string pre_name;
        cout << "请输入要修改的名字" << endl;
        cin >> pre_name;
        for (auto &aa : my_sim_card_contacts)
        {
            if (aa.get_name() == pre_name)
            {
                aa.modify();
            }
        }
    }
    else if (op == 2)
    {
        string pre_tel;
        cout << "请输入要修改的电话号码" << endl;
        cin >> pre_tel;
        for (auto &aa : my_sim_card_contacts)
        {
            if (aa.get_tel() == pre_tel)
            {
                aa.modify();
            }
        }
    }
    else if (op == 3)
    {
        string pre_hometown;
        cout << "请输入要修改的籍贯" << endl;
        cin >> pre_hometown;
        for (auto &aa : my_sim_card_contacts)
        {
            if (aa.get_hometown() == pre_hometown)
            {
                aa.modify();
            }
        }
    }
    else if (op == 4)
    {
        string pre_qq;
        cout << "请输入要修改的qq" << endl;
        cin >> pre_qq;
        for (auto &aa : my_sim_card_contacts)
        {
            if (aa.get_qq() == pre_qq)
            {
                aa.modify();
            }
        }
    }
    else
    {
        cerr << "输入错误,请重试" << endl;
        abort();
    }
}

void phone_card_address_book::query()
{
    cout << "请输入您想要的查询方式" << endl;
    cout << "按姓名查询请输入1,按电话号码查询请输入2" << endl;
    cout << "按籍贯查询请输入3,按qq查询请输入4" << endl;
    int op;
    cin >> op;
    if (op == 1)
    {
        string q_name;
        cout << "请输入想要查询的姓名" << endl;
        cin >> q_name;
        for (auto &aa : my_sim_card_contacts)
        {
            if (aa.get_name() == q_name)
            {
                cout << "姓名为: " << aa.get_name() << "t" << "电话号码为: " << aa.get_tel() << "籍贯为: " << "t" << "qq为: " << endl;
            }
        }
    }
    else if (op == 2)
    {
        string q_tel;
        cout << "请输入想要查询的电话号码" << endl;
        cin >> q_tel;
        for (auto &aa : my_sim_card_contacts)
        {
            if (aa.get_tel() == q_tel)
            {
                cout << "姓名为: " << aa.get_name() << "t" << "电话号码为: " << aa.get_tel() << "籍贯为: " << "t" << "qq为: " << endl;
            }
        }
    }
    else if (op == 3)
    {
        string q_hometown;
        cout << "请输入想要查询的姓名" << endl;
        cin >> q_hometown;
        for (auto &aa : my_sim_card_contacts)
        {
            if (aa.get_name() == q_hometown)
            {
                cout << "姓名为: " << aa.get_name() << "t" << "电话号码为: " << aa.get_tel() << "籍贯为: " << "t" << "qq为: " << endl;
            }
        }
    }
    else if (op == 4)
    {
        string q_qq;
        cout << "请输入想要查询的姓名" << endl;
        cin >> q_qq;
        for (auto &aa : my_sim_card_contacts)
        {
            if (aa.get_name() == q_qq)
            {
                cout << "姓名为: " << aa.get_name() << "t" << "电话号码为: " << aa.get_tel() << "籍贯为: " << "t" << "qq为: " << endl;
            }
        }
    }
    else
    {
        cerr << "输入错误,请重试" << endl;
        abort();
    }
}

int phone_card_address_book::get_cnt()
{
    return cnt;
}

void phone_card_address_book::copy(string pname, string ptel)
{
    if (cnt > 1000)
    {
        cerr << "超过容量上限,无法继续存入" << endl;
        abort();
    }
    for (auto &aa : my_sim_card_contacts)
    {
        if(aa.get_name() == pname && aa.get_tel() == ptel)
        {
            cout<<"所复制联系人的信息中,有原本原来已经存在,跳过存在联系人的复制"<<endl;
            return ;
        }
    }
    SIM_card_contacts temp;
    temp.set(pname,ptel,"籍贯暂定","qq暂定");
    my_sim_card_contacts.push_back(temp);
    cnt ++;
}

void phone_card_address_book::clear_card()
{
    my_sim_card_contacts.clear();
    cnt = 0;
}

phone_card_address_book::~phone_card_address_book()
{
    ofstream outfile;
    outfile.open("test_2.txt",ios::out);
    if (!outfile)
    {
        cerr << "读取文件失败" << endl;
        abort();
    }
    outfile << "====================通讯录管理系统====================" << endl;
    outfile << "姓名" << "t" << "电话号码" << "t"<< "籍贯"<< "t" << "qq" << endl;
    for (auto &aa : my_sim_card_contacts)
    {
        outfile << aa.get_name() << " " << aa.get_tel() << " " << aa.get_hometown() << " " << aa.get_qq() << endl;
    }
    outfile.close();
}

class menus
{
public:
    void main_menu();
    void add_menu();
    void delete_menu();
    void query_menu();
    void display_menu();
    void modify_menu();
    void clear_screen();
};
void menus::main_menu()
{   cout << "====================通讯录管理系统====================" << endl;
    cout << "你可以选择以下几种操作: " << endl;
    cout << "1.新建联系人" << endl;
    cout << "2.删除一个联系人" << endl;
    cout << "3.修改联系人的信息"<< endl;
    cout << "4.查询联系人的信息" << endl;
    cout << "5.浏览所有人的信息" << endl;
    cout << "6.将联系人的信息从手机卡转移到手机" << endl;
    cout << "7.将联系人的信息从手机转移到手机卡" << endl;
    cout << "0.退出程序,保存文件" << endl;
    cout << "======================================================"<<endl;
    cout << "请输入你的选择: " << endl;
}

void menus::add_menu()
{
    cout << "======================================================" << endl;
    cout << "              请选择添加联系人到哪个通讯录           " << endl;
    cout << "------------------------------------------------------" << endl;
    cout << "               1.   手机通讯录                       " << endl;
    cout << "               2.   手机卡通讯录                     " << endl;
    cout << "======================================================" << endl;
    cout << "请输入你的选择:"<<endl;

}

void menus::delete_menu()
{
    cout << "======================================================" << endl;
    cout << "              请选择在哪个通讯录里删除联系人          " << endl;
    cout << "------------------------------------------------------" << endl;
    cout << "               1.   手机通讯录                       " << endl;
    cout << "               2.   手机卡通讯录                     " << endl;
    cout << "======================================================" << endl;
    cout << "请输入你的选择:"<<endl;
}

void menus::query_menu()
{
    cout << "======================================================" << endl;
    cout << "              请选择在哪个通讯录里查询联系人          " << endl;
    cout << "------------------------------------------------------" << endl;
    cout << "               1.   手机通讯录                       " << endl;
    cout << "               2.   手机卡通讯录                     " << endl;
    cout << "======================================================" << endl;
    cout << "请输入你的选择:"<<endl;
}

void menus::display_menu()
{
    cout << "======================================================" << endl;
    cout << "          请选择你要显示哪个通讯录的所有联系人          " << endl;
    cout << "------------------------------------------------------" << endl;
    cout << "               1.   手机通讯录                        " << endl;
    cout << "               2.   手机卡通讯录                      " << endl;
    cout << "======================================================" << endl;
    cout << "请输入你的选择:"<<endl;
}

void menus::modify_menu()
{
    cout << "======================================================" << endl;
    cout << "          请选择你要修改哪个通讯录的联系人          " << endl;
    cout << "------------------------------------------------------" << endl;
    cout << "               1.   手机通讯录                        " << endl;
    cout << "               2.   手机卡通讯录                      " << endl;
    cout << "======================================================" << endl;
    cout << "请输入你的选择:"<<endl;
}

void menus::clear_screen()
{
    system("cls");
}


class users
{
    mobile_phone_address_book my_phone;
    phone_card_address_book my_card;
    menus my_menu;
public:
    users();
    ~users();
    void Add();
    void Delete();
    void Display();
    void Modify();
    void Query();
    void Move_to_phone();
    void Move_to_card();
    void Copy_to_card();
    void Copy_to_phone();
};
users::users()
{
    cout << "======================================================" << endl;
    cout << "              欢迎进入通讯录管理系统           " << endl;
    cout << "------------------------------------------------------" << endl;
    cout << "你目前的手机联系人有: " << my_phone.get_cnt() + 1 << "人" << endl;
    cout << "你目前的手机卡联系人有: " << my_card.get_cnt() + 1 << "人" << endl;
    cout << "======================================================" << endl;
}

void users::Add()
{
    my_menu.clear_screen();
    my_menu.add_menu();
    address_book *p;
    int op;
    cin >> op;
    if (op == 1)
    {
        p = &my_phone;
        p->Add();
    }
    else if (op == 2)
    {
        p = &my_card;
        p->Add();
    }
    else
    {
        cerr << "输入错误,请重试" << endl;
        abort();
    }
}

void users::Delete()
{
    my_menu.clear_screen();
    my_menu.delete_menu();
    address_book *p;
    int op;
    cin >> op;
    if (op == 1)
    {
        p = &my_phone;
        p->Delete();
    }
    else if (op == 2)
    {
        p = &my_card;
        p->Delete();
    }
    else
    {
        cerr << "输入错误,请重试" << endl;
        abort();
    }
}

void users::Display()
{
    my_menu.clear_screen();
    my_menu.display_menu();
    address_book *p;
    int op;
    cin >> op;
    if (op == 1)
    {
        p = &my_phone;
        p->Display();
    }
    else if (op == 2)
    {
        p = &my_card;
        p->Display();
    }
    else
    {
        cerr << "输入错误,请重试" << endl;
        abort();
    }
}

void users::Modify()
{
    my_menu.clear_screen();
    my_menu.modify_menu();
    address_book *p;
    int op;
    cin >> op;
    if (op == 1)
    {
        p = &my_phone;
        p->Modify();
    }
    else if (op == 2)
    {
        p = &my_card;
        p->Modify();
    }
    else
    {
        cerr << "输入错误,请重试" << endl;
        abort();
    }
}

void users::Query()
{
    my_menu.clear_screen();
    my_menu.query_menu();
    address_book *p;
    int op;
    cin >> op;
    if (op == 1)
    {
        p = &my_phone;
        p->query();
    }
    else if (op == 2)
    {
        p = &my_card;
        p->query();
    }
    else
    {
        cerr << "输入错误,请重试" << endl;
        abort();
    }
}

void users::Move_to_phone()
{
    if(my_card.get_cnt() <= 0)
    {
        cout<<"手机卡通讯录当前没有联系人!"<<endl;
        return;
    }
    for (auto &aa : my_card.my_sim_card_contacts)
    {
        my_phone.copy(aa.get_name(),aa.get_tel());
    }
    my_card.clear_card();
    cout << "移动完成" << endl;
}

void users::Move_to_card()
{
    if(my_phone.get_cnt() <= 0)
    {
        cout<<"手机卡通讯录当前没有联系人!"<<endl;
        return;
    }
    for (auto &aa : my_phone.my_phone_contacts)
    {
        my_card.copy(aa.get_name(),aa.get_tel());
    }
    my_phone.clear_phone();
    cout << "移动完成" << endl;
}

void users::Copy_to_phone()
{
    if(my_card.get_cnt() <= 0)
    {
        cout<<"手机卡通讯录当前没有联系人!"<<endl;
        return;
    }
    for (auto &aa : my_card.my_sim_card_contacts)
    {
        my_phone.copy(aa.get_name(),aa.get_tel());
    }
    cout << "复制完成" << endl;
}

void users::Copy_to_card()
{
    if(my_phone.get_cnt() <= 0)
    {
        cout << "手机通讯录当前没有联系人" <<endl;
        return;
    }
    for (auto &aa : my_phone.my_phone_contacts)
    {
        my_card.copy(aa.get_name(),aa.get_tel());
    }
    cout << "复制完成" << endl;
}

users::~users()
{
    cout << "谢谢使用本系统" << endl;
}


int main()
{
    menus my_menu;
    users me;
    int choose = 1,c;
    while(choose!=0)
    {
        my_menu.main_menu();
        cin>>choose;
        switch(choose)
        {
            case 0:
                   break;
            case 1:
                   me.Add();
                   break;
            case 2:
                   me.Delete();
                   break;
            case 3:
                   me.Modify();
                   break;
            case 4:
                   me.Query();
                   break;
            case 5:
                   me.Display();
                   break;
            case 6:
                  cout << "请选择 1.复制 2移动" << endl;
                  cin >> c;
                  switch(c)
                  {
                    case 1:
                           me.Copy_to_phone();
                           break;
                    case 2:
                           me.Move_to_phone();
                           break;
                    default:
                           cout << "操作错误" << endl;
                           break;

                   }
                   break;
            case 7:
                  cout << "请选择 1.复制 2移动" << endl;
                  cin>>c;
                  switch(c)
                  {
                    case 1:
                           me.Copy_to_card();
                           break;
                    case 2:
                           me.Move_to_card();
                           break;
                    default:
                           cout << "操作错误" << endl;
                           break;
                  }
                  break;
            }
    }

    return 0;
}

最后

以上就是温婉指甲油为你收集整理的通讯录管理系统升级版的全部内容,希望文章能够帮你解决通讯录管理系统升级版所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部