c++课程设计具有简单功能的通讯录管理系统

通讯录管理系统

手机通讯录中的联系人的信息既可以存储在手机中,也可以存储在手机卡中,也可以同时存储在两个位置上(每个位置上的存储容量为1000,即手机卡中或手机上最多只能存储1000个联系人)。存储在手机卡的联系人的信息只包含用户名和电话号码两项信息。存储在手机上的联系人的信息除了上面提到的两项信息外,还包含籍贯,QQ号等信息。
根据通用的手机通讯录的使用方式,采用OOP(Object Oriented Programming,面向对象编程)方法编写一个手机通讯录管理。
要求:
1.创建文本文件,记录联系人的信息(需要创建两个文本文件,分别存储手机和手机卡上的存储的联系人的信息)。
2.以菜单方式工作(字符界面即可)
3.存储在手机卡上的联系人的信息包括:姓名和电话号码;存储在手机上的联系人的信息包括姓名,籍贯,电话号码,QQ号等信息
4.管理系统的功能包括:
a)新建联系人:添加新的联系人(添加时确定是添加到手机上还是手机卡中)
b)删除:删除一个联系人(输入电话号码,删除该联系人。说明,如果两个存储位置上都存在该联系人的话,需要在两个存储位置上都要进行删除操作)
c)修改:修改某个联系人的信息(输入电话号码,查询到联系人之后进行信息的修改。说明,如果两个存储位置上都存在该联系人的话,需要在两个存储位置上都要进行修改操作)
d)查询:根据名字查询联系人信息(查询结果不唯一)
e)浏览:显示所有联系人的信息
f)将联系人的信息从手机转存到手机卡上(同时要避免重复数据的存在。并且在转存是要检查容量是否受限。下同。)
g)将联系人的信息从手机卡上转存到手机上(同时要避免重复数据的存在)
5.要支持继承、多态、重载(运算符重载、函数重载)等面向对象的基本特点
6.提交程序源码和课程设计报告。

#include <iostream>
#include <fstream>
#include <string>
#include<stdlib.h>
#include<windows.h>
#include <string.h>
using namespace std;
/*
1.手机卡联系人类:表示一个联系人
        数据成员包括:
姓名
电话号码
成员函数包括
带参并带默认值的构造函数
一组set函数为数据成员赋值
一组modify函数,修改数据成员的值
重载>>,<<运算符,完成对象的输入和输出操作
*/
class Mobilecardcontact
{
public:
    string name;
    string number;
    /*
    带参并带默认值的构造函数
    */
    Mobilecardcontact(string a = "a", string b = "b")
    {
        name = a; number = b;
    }
    /*
     重载>>,<<运算符,完成对象的输入和输出操作
     */
    friend istream& operator>>(istream& cin, Mobilecardcontact& b);
    friend ostream& operator<<(ostream& cout, Mobilecardcontact& b);
    int set(string a, string b);
    int modify();//修改数据成员的值
};
istream& operator>>(istream& cin, Mobilecardcontact& b)
{
    cout << "请输入姓名:" << endl;
    cin >> b.name;
    cout << "请输入电话号码:" << endl;
    cin >> b.number;
    return cin;
}
ostream& operator<<(ostream& cout, Mobilecardcontact& b)
{
    cout << "姓名:" << b.name << endl;
    cout << "电话号码:" << b.number << endl;
    return cout;
}
int Mobilecardcontact::set(string a,string b)
{
    name = a; number = b; return 0;
}
int Mobilecardcontact::modify()
{
    cout << "请选择要修改的信息:" << endl;
    cout << "修改姓名请输入1" << endl;
    cout << "修改号码输入2" << endl;
    int n; cin >> n;
    if (n == 1)
    {
        string a; cout << "请输入要修改成的名字" << endl;
        cin >> a; name = a;
    }
    else if (n == 2)
    {
        string a; cout << "请输入要修改成的电话号码" << endl;
        cin >> a; number = a;
    }
    return 0;
}
/*
2.手机联系人(继承于手机卡联系人类):
新增数据成员:
籍贯
QQ号
成员函数包括
一组set函数为数据成员赋值
一组modify函数,修改数据成员的值
重载>>,<<运算符,完成数据成员的输入输出操作
*/
class Mobilecontact :public Mobilecardcontact
{

public:
    string nativeplace;//籍贯
    string qqnumber;//QQ号
    Mobilecontact(string a = "a", string b = "b", string c = "c", string d = "d") :Mobilecardcontact(a, b)
    {
        nativeplace = c; qqnumber = d;
    }
    friend istream& operator>>(istream& cin, Mobilecontact& b);
    friend ostream& operator<<(ostream& cout, Mobilecontact& b);
    int set(string a, string b);
    int modify();//修改数据成员的值
};
int Mobilecontact::set(string a, string b)
{
    nativeplace = a; qqnumber = b; return 0;
}
int Mobilecontact::modify()
{
    cout << "请选择要修改的信息:" << endl;
    cout << "修改姓名请输入1" << endl;
    cout << "修改号码请输入2" << endl;
    cout << "修改籍贯请输入3" << endl;
    cout << "修改QQ号码请输入4" << endl;
    int n; cin >> n;
    if (n == 1)
    {
        string a; cout << "请输入要修改成的名字" << endl;
        cin >> a; name = a;
    }
    else if (n == 2)
    {
        int a; cout << "请输入要修改成的电话号码" << endl;
        cin >> a; number = a;
    }
    else if (n == 3)
    {
        string a; cout << "请输入要修改成的籍贯" << endl;
        cin >> a; nativeplace = a;
    }
    else if (n == 4)
    {
        int a; cout << "请输入要修改成的QQ号码" << endl;
        cin >> a; qqnumber = a;
    }
    return 0;
}
istream& operator>>(istream& cin, Mobilecontact& b)
{
    cout << "请输入姓名:" << endl; cin >> b.name;
    cout << "请输入电话号码:" << endl; cin >> b.number;
    cout << "请输入籍贯:" << endl; cin >> b.nativeplace;
    cout << "请输入QQ号码:" << endl; cin >> b.qqnumber;
    return cin;
}
ostream& operator<<(ostream& cout, Mobilecontact& b)
{
    cout << "姓名:" << b.name << endl;
    cout << "电话号码:" << b.number << endl;
    cout << "籍贯:" << b.nativeplace << endl;
    cout << "QQ号码:" << b.qqnumber << endl;
    return cout;
}
/*
3.定义一个通讯簿抽象类,用来封装以下函数(为支持多态,可以将以下函数封装为纯虚函数)
            增加函数:增加一个联系人
            删除操作:删除一个联系人
            Display:显示所有联系人的信息
            修改某一联系人的信息:
            查询并显示某一联系人的信息:
*/
class addressbook
{
public:
    addressbook() { }
    virtual int addcontacter() = 0;
    virtual int inquire() = 0;
    virtual int deletecontacter() = 0;
    virtual int modification() = 0;
    virtual int showallcontacter() = 0;
    virtual int unloading() = 0;
    ~addressbook() {  }
};
/*
5.手机卡通讯簿类(这是一个数据库类,继承于通讯簿抽象类):用于记录手机中存储的所有联系人的信息
        数据成员包括:
            手机联系人的数量
            手机联系人对象数组
        成员函数包括
            构造函数:读取文本文件中的数据,并根据文件内容创建联系人对象数组
            析构函数:将对象数组中的内容写入到文本文件中。
            增加函数:增加一个联系人
            删除操作:删除一个联系人
            Display:显示所有联系人的信息
            修改某一联系人的信息:
            查询并显示某一联系人的信息:
*/
class Mobilecardaddressbook :public addressbook
{
public:
    Mobilecardaddressbook()
    {
        cout << "                     ********************************" << endl;
        cout << "                     *      欢迎来到手机卡通讯簿    *" << endl;
        cout << "                     ********************************" << endl;

    }
    int addcontacter();
    int inquire();
    int deletecontacter();
    int modification();
    int showallcontacter();
    int unloading();
    ~Mobilecardaddressbook()
    {
        cout << "                     ********************************" << endl;
        cout << "                     *      成功离开手机通讯簿      *" << endl;
    }
};
int Mobilecardaddressbook::addcontacter()
{
    int m;
    string a[1000][2];
    fstream infile("Mobilecard contact.txt", ios::in);//打开源目录下已建好的手机卡通讯录
    if (!infile)
    {
        cout << "打开手机卡内存文件失败!" << endl;
    }
    for (int i = 0; i <= 1000; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            infile >> a[i][j];
        }
        m = i;
        if (a[i][0] == "")
        {
            break;
        }
    }
    cout << "现在已经有:" << m << "个联系人" << endl;
    if (m < 1000)
    {
        //  cout << "请输入你想要添加到手机卡的联系人的姓名:" << endl;
        //  cout << "请输入你想要添加到手机卡的联系人的电话号码:" << endl;
        Mobilecardcontact A;
        cin >> A;
        cout << "您刚刚输入的信息为:" << endl;
        cout << A;
        fstream infile("Mobilecard contact.txt", ios::app | ios::out);
        if (!infile)
        {
            cout << "打开手机卡内存文件失败!" << endl;
        }
        infile << "姓名:" << A.name << endl;
        infile << "电话号码:" << A.number << endl;
        infile.close();
    }
    else if (m >= 1000)
    {
        cout << "无法添加" << endl;
    }
    return 0;
}
int Mobilecardaddressbook::inquire()
{
    string a[1000][2];
    cout << "请输入你想要查询联系人的姓名:" << endl;
    string b; cin >> b;
    string d;  d = "姓名:" + b;
    fstream infile("Mobilecard contact.txt", ios::in);
    if (!infile)
    {
        cout << "打开手机卡内存文件失败!" << endl;
    }
    for (int i = 0; i <= 1000; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            infile >> a[i][j];
        }
        if (d == a[i][0])
        {
            cout << "您查找的联系人信息为:" << endl;
            cout << d << endl;
            cout << a[i][1] << endl;
        }
    }
    infile.close();
    return 0;
}
int Mobilecardaddressbook::modification()
{
    string a[1000][2];
    int m;
    cout << "请输入你想要修改的联系人的电话号码:" << endl;
    string b; cin >> b;
    string d; d = "电话号码:" + b;
    fstream infile("Mobilecard contact.txt", ios::in);
    if (!infile)
    {
        cout << "打开手机卡内存文件失败!" << endl;
    }
    for (int i = 0; i <= 1000; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            infile >> a[i][j];
        }
        m = i;
        if (a[i][0] == "")
        {
            break;
        }
    }
    infile.close();
    for (int i = 0; i <= m; i++)
    {
        if (d == a[i][1])
        {
            cout << "请输入您要修改成的姓名:" << endl;
            string s, b;
            cin >> s;
            a[i][0] = "姓名:" + s;
            cout << "请输入您要修改成的电话号码:" << endl;
            cin >> b;
            a[i][1] = "电话号码:" + b;
            cout << "请输入您要修改成的籍贯:" << endl;
            cout << "修改成功!" << endl;
        }
    }
    fstream infile2("Mobilecard contact.txt", ios::out);
    if (!infile2)
    {
        cout << "打开手机卡内存文件失败!" << endl;
    }
    for (int i = 0; i <= m; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            if (a[i][0] == "1" || a[i][1] == "1")
            {
                break;
            }
            else
            {
                infile2 << a[i][j] << endl;
            }
        }
    }
    infile2.close();
    return 0;
}
int Mobilecardaddressbook::deletecontacter()
{
    string a[1000][2];
    int m;
    cout << "请输入你想要删除的联系人的电话号码:" << endl;
    string b; cin >> b;
    string d; d = "电话号码:" + b;
    fstream infile("Mobilecard contact.txt", ios::in);
    if (!infile)
    {
        cout << "打开手机卡内存文件失败!" << endl;
    }
    for (int i = 0; i <= 1000; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            infile >> a[i][j];
        }
        m = i;
        if (a[i][0] == "")
        {
            break;
        }
    }
    infile.close();
    for (int i = 0; i <= m; i++)
    {
        if (d == a[i][1])
        {
            a[i][0] = "1";
            a[i][1] = "1";
            cout << "联系人删除成功" << endl;
        }
    }
    fstream infile2("Mobilecard contact.txt", ios::out);
    if (!infile2)
    {
        cout << "打开手机卡内存文件失败!" << endl;
    }
    for (int i = 0; i <= m; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            if (a[i][0] == "1" || a[i][1] == "1")
            {
            }
            else
            {
                infile2 << a[i][j] << endl;
            }
        }
    }
    infile2.close();
    return 0;
}
int Mobilecardaddressbook::showallcontacter()
{
    int m;
    string a[1000][2];
    fstream infile("Mobilecard contact.txt", ios::in);
    if (!infile)
    {
        cout << "打开手机卡内存文件失败!" << endl;
    }
    for (int i = 0; i < 1000; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            infile >> a[i][j];
        }
        m = i;
        if (a[i][0] == "")
        {
            break;
        }
    }
    infile.close();
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            cout << a[i][j] << endl;
        }
    }
    return 0;
}
int Mobilecardaddressbook::unloading()
{
    int m1;
    string a[1000][2];
    fstream infile2("Mobilecard contact.txt", ios::in);
    if (!infile2)
    {
        cout << "打开手机卡内存文件失败!" << endl;
    }
    for (int i = 0; i < 1000; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            infile2 >> a[i][j];
        }
        m1 = i;
        if (a[i][0] == "")
        {
            break;
        }
    }
    infile2.close();
    int m2;
    string b[1000][4];
    fstream infile("Mobile contact.txt", ios::in);
    if (!infile)
    {
        cout << "打开手机内存文件失败!" << endl;
    }
    for (int i = 0; i < 1000; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            infile >> b[i][j];
        }
        m2 = i;
        if (b[i][0] == "")
        {
            break;
        }
    }
    for (int j = 0; j < m2; j++)
    {
        for (int i = 0; i < m1; i++)
        {
            if (b[j][1] == a[i][1])
            {
                a[i][0] = "1";
                a[i][1] = "1";
            }
        }
    }
    int sum;
    sum = m1 + m2 + 2;
    if (sum <= 1000)
    {
        int i1 = 0;
        int j1 = 0;
        cout << "手机卡联系人已转存到手机联系人中" << endl;
        cout << "(注:为了节省内存空间,姓名电话相同的项将不会进行转存!)" << endl;
        for (int i = m2; i < sum; i++)
        {
            for (int j = 0; j < 4; j++)
            {

                if (j == 0 || j == 1)
                {
                    b[i][j] = a[i1][j1];
                    j1++;
                }
                else if (j == 2 || j == 3)
                {
                    b[i][j] = "无此信息";
                    j1++;
                }
            }
            i1++;
            j1 = 0;
        }
        fstream infile2("Mobile contact.txt", ios::out);
        if (!infile2)
        {
            cout << "打开手机内存文件失败!" << endl;
        }
        for (int i = 0; i < sum; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (b[i][0] == "1" || b[i][1] == "1")
                {
                    break;
                }
                else if (b[i][0] != "" || b[i][1] != "")
                {
                    infile2 << b[i][j] << endl;
                }
            }
        }
        infile2.close();
    }
    if (sum > 1000)
    {
        cout << "无法转存" << endl;
    }
    return 0;
}
/*
4.手机通讯簿类(这是一个数据库类,继承于通讯簿抽象类):用于记录手机中存储的所有联系人的信息
        数据成员包括:
            手机联系人的数量
            手机联系人对象数组
        成员函数包括
            构造函数:读取文本文件中的数据,并根据文件内容创建联系人对象数组
            析构函数:将对象数组中的内容写入到文本文件中。
            增加函数:增加一个联系人
            删除操作:删除一个联系人
            Display:显示所有联系人的信息
            修改某一联系人的信息:
            查询并显示某一联系人的信息:
*/
class Mobileaddressbook :public addressbook
{
public:
    Mobileaddressbook()
    {
        cout << "                     ********************************" << endl;
        cout << "                     *       欢迎来到手机通讯簿     *" << endl;
        cout << "                     ********************************" << endl;

    }
    int addcontacter();
    int inquire();
    int deletecontacter();
    int modification();
    int showallcontacter();
    int unloading();
    ~Mobileaddressbook()
    {
        cout << "                     ********************************" << endl;
        cout << "                     *      成功离开手机通讯簿      *" << endl;
    }
};
int Mobileaddressbook::addcontacter()
{
    int m;
    string a[1000][4];
    fstream infile("Mobile contact.txt", ios::in);
    if (!infile)
    {
        cout << "打开手机内存文件失败!" << endl;
    }
    for (int i = 0; i <= 1000; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            infile >> a[i][j];
        }
        m = i;
        if (a[i][0] == "")
        {
            break;
        }
    }
    cout << "现在手机中已经有:" << m << "个联系人" << endl;
    if (m < 1000)
    {
        // cout << "请输入你想要添加到手机的联系人的姓名:" << endl;
        // cout << "请输入你想要添加到手机的联系人的电话号码:" << endl;
        Mobilecontact A;
        cin >> A;
        cout << "您刚刚输入的信息为:" << endl;
        cout << A;
        fstream infile("Mobile contact.txt", ios::app | ios::out);
        if (!infile)
        {
            cout << "打开手机内存文件失败!" << endl;
        }
        infile << "姓名:" << A.name << endl;
        infile << "电话号码:" << A.number << endl;
        infile << "籍贯:" << A.nativeplace << endl;
        infile << "QQ号码:" << A.qqnumber << endl;
        infile.close();
        return 0;
    }
    else if (m >= 1000)
    {
        cout << "无法继续给手机添加新的联系人" << endl;
    }
}
int Mobileaddressbook::inquire()
{
    string a[1000][4];
    cout << "请输入你想要查询联系人的姓名:" << endl;
    string b; cin >> b;
    string d;  d = "姓名:" + b;
    fstream infile("Mobile contact.txt", ios::in);
    if (!infile)
    {
        cout << "打开手机内存文件失败!" << endl;
    }
    for (int i = 0; i <= 1000; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            infile >> a[i][j];
        }
        if (d == a[i][0])
        {
            cout << "您查找的联系人信息为:" << endl;
            cout << d << endl;
            cout << a[i][1] << endl;
            cout << a[i][2] << endl;
            cout << a[i][3] << endl;
        }
    }
    infile.close();
    return 0;
}
int Mobileaddressbook::deletecontacter()
{
    string a[1000][4];
    int m;
    cout << "请输入你想要删的联系人的电话号码:" << endl;
    string b; cin >> b;
    string d; d = "电话号码:" + b;
    fstream infile("Mobile contact.txt", ios::in);
    if (!infile)
    {
        cout << "打开手机内存文件失败!" << endl;
    }
    for (int i = 0; i <= 1000; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            infile >> a[i][j];
        }
        m = i;
        if (a[i][0] == "")
        {
            break;
        }
    }
    infile.close();
    for (int i = 0; i < m; i++)
    {
        if (d == a[i][1])
        {
            a[i][0] = "1";
            a[i][1] = "1";
            a[i][2] = "1";
            a[i][3] = "1";
            cout << "联系人删除成功" << endl;
        }
    }
    fstream infile2("Mobile contact.txt", ios::out);
    if (!infile2)
    {
        cout << "打开手机内存文件失败!" << endl;
    }
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if (a[i][0] == "1")
            {
                break;
            }
            else
            {
                infile2 << a[i][j] << endl;
            }
        }

    }
    infile2.close();
    return 0;
}
int Mobileaddressbook::modification()
{
    string a[1000][4];
    int m;
    cout << "请输入你想要修改的联系人的电话号码:" << endl;
    string b; cin >> b;
    string d; d = "电话号码:" + b;
    fstream infile("Mobile contact.txt", ios::in);
    if (!infile)
    {
        cout << "打开手机内存文件失败!" << endl;
    }
    for (int i = 0; i <= 1000; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            infile >> a[i][j];
        }
        m = i;
        if (a[i][0] == "")
        {
            break;
        }
    }
    infile.close();
    for (int i = 0; i < m; i++)
    {
        if (d == a[i][1])
        {
            cout << "请输入您要修改成的姓名:" << endl;
            string s, b, c, d;
            cin >> s;
            a[i][0] = "姓名:" + s;
            cout << "请输入您要修改成的电话号码:" << endl;
            cin >> b;
            a[i][1] = "电话号码:" + b;
            cout << "请输入您要修改成的籍贯:" << endl;
            cin >> c;
            a[i][2] = "籍贯:" + c;
            cout << "请输入您要修改成的qq号码:" << endl;
            cin >> d;
            a[i][3] = "QQ号码:" + d;
            cout << "修改成功!" << endl;
        }
    }
    fstream infile2("Mobile contact.txt", ios::out);
    if (!infile2)
    {
        cout << "打开手机内存文件失败!" << endl;
    }
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if (a[i][0] == "1")
            {
                break;
            }
            else
            {
                infile2 << a[i][j] << endl;
            }
        }

    }
    infile2.close();
    return 0;
}

int Mobileaddressbook::showallcontacter()
{
    int m;
    string a[1000][4];
    fstream infile("Mobile contact.txt", ios::in);
    if (!infile)
    {
        cout << "打开手机卡内存文件失败!" << endl;
    }
    for (int i = 0; i < 1000; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            infile >> a[i][j];
        }
    }
    infile.close();
    for (int i = 0; i < 1000; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if (a[i][j] != "")
            {
                cout << a[i][j] << endl;
            }
        }
    }
    return 0;
}
int Mobileaddressbook::unloading()
{
    int m1;
    string a[1000][2];
    fstream infile("Mobilecard contact.txt", ios::in);
    if (!infile)
    {
        cout << "打开手机卡内存文件失败!" << endl;
    }
    for (int i = 0; i < 1000; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            infile >> a[i][j];
        }
        m1 = i;
        if (a[i][0] == "")
        {
            break;
        }
    }
    infile.close();
    int m2;
    string b[1000][4];
    fstream infile2("Mobile contact.txt", ios::in);
    if (!infile2)
    {
        cout << "打开手机内存文件失败!" << endl;
    }
    for (int i = 0; i < 1000; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            infile2 >> b[i][j];
        }
        m2 = i;
        if (b[i][0] == "")
        {
            break;
        }
    }
    infile2.close();
    for (int i = 0; i < m1; i++)
    {
        for (int j = 0; j < m2; j++)
        {
            if (a[i][1] == b[j][1])
            {
                b[j][0] = "1";
                b[j][1] = "1";
            }
        }
    }
    int sum;
    sum = m1 + m2 + 2;
    if (sum <= 1000)
    {
        int i1 = 0;
        int j1 = 0;
        cout << "手机联系人已转存到手机卡联系人中" << endl;
        cout << "(注:为了节省内存空间,姓名电话相同的项将不会进行转存!)" << endl;
        for (int i = m1; i < sum; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                a[i][j] = b[i1][j1];
                j1++;
            }
            i1++;
            j1 = 0;
        }
        fstream infile2("Mobilecard contact.txt", ios::out);
        if (!infile2)
        {
            cout << "打开手机卡内存文件失败!" << endl;
        }
        for (int i = 0; i < sum; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                if (a[i][0] == "1" || a[i][1] == "1")
                {
                    break;
                }
                else if (a[i][0] != "1" || a[i][1] != "1")
                {
                    infile2 << a[i][j] << endl;
                }
            }
        }
        infile2.close();
    }
    if (sum > 1000)
    {
        cout << "无法转存" << endl;
    }
    return 0;
}
/*
6.用户类(这是一个操作类,完成通讯簿的操作):用户拥有两个通讯簿(一个是手机中存储的联系人,一个是手机卡中存储的联系人),并且可以对通讯录进行管理
        数据成员包括:
            两个通讯簿对象
        成员函数包括(成员函数体现用户的行为):
            添加联系人:利用基类指针,调用相应的通讯簿对象(手机通讯簿或手机卡通信簿)的增加函数完成联系人的添加。实现动态联编,体现出多态特点。(下同)
            删除联系人:调用相应的通讯簿对象的删除操作删除一个联系人
            Display:显示相应的通讯簿中联系人的信息
            修改某一联系人的信息:调用通讯簿对象的函数完成操作
            查询并显示某一联系人的信息:调用通讯簿对象的函数完成操作
            将手机卡中的存储的联系人的信息移动到手机中
            将手机中存储的联系人的信息移动到手机卡中
            将手机卡中的存储的联系人的信息复制到手机中
            将手机中存储的联系人的信息复制到手机卡中
*/
class user
{
public:
    int n;
    user(int a)
    {
        /*
         cout << "                     ********************************" << endl;
         cout << "                     * 欢迎来到通讯录管理系统操作区 *" << endl;
         cout << "                     ********************************" << endl;
         */
        n = a;
        if (n == 1)
        {
            addcontacteru();
        }
        else if (n == 2)
        {
            inquair();
        }
        else if (n == 3)
        {
            deletecontact();
        }
        else if (n == 4)
        {
            modification();
        }
        else if (n == 5)
        {
            showallcontacter();
        }
        else if (n == 6)
        {
            unloading();
        }
    }
    ~user()
    {
        /*  cout << "----------------------------------" << endl;
          cout << "***离开通讯录管理系统操作区成功***" << endl;
          cout << "----------------------------------" << endl;
          */
    }
    int addcontacteru();
    int inquair();
    int deletecontact();
    int modification();
    int showallcontacter();
    int unloading();

};
int user::addcontacteru()
{
    while (n <= 10)
    {
        cout << "                     ********************************" << endl;
        cout << "                     *          增加联系人          *" << endl;
        cout << "                     ********************************" << endl;
        cout << "                     *   在手机中增加新的联系人:1   *" << endl;
        cout << "                     *  在手机卡中增加新的联系人:2  *" << endl;
        cout << "                     *         返回上一菜单:0      *" << endl;
        cout << "                     ********************************" << endl;
        int n; cin >> n;
        if (n == 1)
        {
            addressbook* a;
            Mobileaddressbook b;
            a = &b;
            a->addcontacter();
        }
        else if (n == 2)
        {
            addressbook* a;
            Mobilecardaddressbook c;
            a = &c;
            a->addcontacter();
        }
        else if (n == 0)
        {
            system("cls");//清屏
            break;
        }
    }
    return 0;
}
int user::modification()
{
    while (n <= 10)
    {
        cout << "                     ********************************" << endl;
        cout << "                     *          修改联系人          *" << endl;
        cout << "                     ********************************" << endl;
        cout << "                     *     修改手机中的联系人:1    *" << endl;
        cout << "                     *    修改手机卡中的联系人: 2   *" << endl;
        cout << "                     *         退出修改界面:0      *" << endl;
        cout << "                     ********************************" << endl;
        int n;
        cin >> n;
        if (n == 1)
        {
            addressbook* a;
            Mobileaddressbook b;
            a = &b;
            a->modification();
        }
        else if (n == 2)
        {
            addressbook* a;
            Mobilecardaddressbook c;
            a = &c;
            a->modification();
        }
        else if (n == 0)
        {
            system("cls");//清屏
            break;
        }
    }
    return 0;
}
int user::inquair()
{
    while (n <= 10)
    {
        cout << "                     ********************************" << endl;
        cout << "                     *          查询联系人          *" << endl;
        cout << "                     ********************************" << endl;
        cout << "                     *     查询手机中的联系人:1    *" << endl;
        cout << "                     *    查询手机卡中的联系人: 2   *" << endl;
        cout << "                     *         退出查询界面:0      *" << endl;
        cout << "                     ********************************" << endl;
        int n;
        cin >> n;
        if (n == 1)
        {
            addressbook* a;
            Mobileaddressbook b;
            a = &b;
            a->inquire();
        }
        else if (n == 2)
        {
            addressbook* a;
            Mobilecardaddressbook c;
            a = &c;
            a->inquire();
        }
        else if (n == 0)
        {
            system("cls");//清屏
            break;
        }
    }
    return 0;
}
int user::deletecontact()//用姓名作为删除依据可能会出现重名的现象,所以这里采用以电话为删除依据
{
    while (n <= 10)
    {
        cout << "                     ********************************" << endl;
        cout << "                     *          删除联系人          *" << endl;
        cout << "                     ********************************" << endl;
        cout << "                     *     删除手机中的联系人:1    *" << endl;
        cout << "                     *    删除手机卡中的联系人: 2   *" << endl;
        cout << "                     *    一键删除所有的联系人: 3   *" << endl;
        cout << "                     *         退出删除界面:0      *" << endl;
        cout << "                     ********************************" << endl;
        int n;
        cin >> n;
        if (n == 1)
        {
            addressbook* a;
            Mobileaddressbook b;
            a = &b;
            a->deletecontacter();
        }
        else if (n == 2)
        {
            addressbook* a;
            Mobilecardaddressbook c;
            a = &c;
            a->deletecontacter();
        }
        else if (n == 3)
        {
            fstream infile("Mobile contact.txt", ios::out);
            if (!infile)
            {
                cout << "打开手机内存文件失败!" << endl;
            }
            else {
                infile << "";
            }
            fstream infile2("Mobilecard contact.txt", ios::out);
            if (!infile)
            {
                cout << "打开手机内存文件失败!" << endl;
            }
            else {
                infile << "";
            }
            cout << "全部删除成功!" << endl;
            infile.close();
            infile2.close();
        }
        else if (n == 0)
        {
            system("cls");//清屏
            break;
        }
    }
    return 0;
}
int user::showallcontacter()
{
    while (n <= 10)
    {
        cout << "                     ********************************" << endl;
        cout << "                     *          显示联系人          *" << endl;
        cout << "                     ********************************" << endl;
        cout << "                     *     显示手机中的联系人:1    *" << endl;
        cout << "                     *    显示手机卡中的联系人: 2   *" << endl;
        cout << "                     *         退出显示界面:0      *" << endl;
        cout << "                     ********************************" << endl;
        int n; cin >> n;
        if (n == 1)
        {
            addressbook* a;
            Mobileaddressbook b;
            a = &b;
            a->showallcontacter();
        }
        if (n == 2)
        {
            addressbook* a;
            Mobilecardaddressbook c;
            a = &c;
            a->showallcontacter();
        }
        if (n == 0)
        {
            system("cls");//清屏
            break;
        }
    }
    return 0;
}
int user::unloading()
{
    while (n <= 10)
    {
        cout << "                     ********************************" << endl;
        cout << "                     *          转存联系人          *" << endl;
        cout << "                     ********************************" << endl;
        cout << "                     *     转存手机中的联系人:1    *" << endl;
        cout << "                     *    转存手机卡中的联系人: 2   *" << endl;
        cout << "                     *         退出转存界面:0      *" << endl;
        cout << "                     ********************************" << endl;
        int n; cin >> n;
        if (n == 1)
        {
            addressbook* a;
            Mobileaddressbook b;
            a = &b;
            a->unloading();
        }
        else if (n == 2)
        {
            addressbook* a;
            Mobilecardaddressbook c;
            a = &c;
            a->unloading();
        }
        else if (n == 0)
        {
            system("cls");//清屏
            break;
        }
    }
    return 0;
}
/*
7.界面菜单类:用来给出操作提示
        数据成员:可以不定义数据成员
        成员函数:
        Display函数:显示操作菜单的提示。
        说明:可以根据需要定义多个函数,显示不同的菜单(操作提示)。
*/
class menu
{
public:
    menu() {
        cout << "                     ********************************" << endl;
        cout << "                     *  欢迎使用小岳通讯录管理系统  *" << endl;
        cout << "                     ********************************" << endl;
    }
    ~menu() {
        /*
        cout << "                     ********************************" << endl;
        cout << "                     *  成功离开通讯录管理系统菜单  *" << endl;
        cout << "                     ********************************" << endl;
        */
    }
    int display();
};
int menu::display()
{
    int n;
    cout << "                     *    请输入数字选择相应功能    *" << endl;
    cout << "                     ********************************" << endl;
    cout << "                     *       新建一个联系人:1      *" << endl;
    cout << "                     *       查询一个联系人:2      *" << endl;
    cout << "                     *       删除一个联系人:3      *" << endl;
    cout << "                     *       修改一个联系人:4      *" << endl;
    cout << "                     *       显示所有联系人:5      *" << endl;
    cout << "                     *         转存联系人:6        *" << endl;
    cout << "                     *          退出系统: 0         *" << endl;
    cout << "                     ********************************" << endl;
    cin >> n;
    return n;
}
int main()
{
    int a = 1;
    while (a < 10)
    {
        menu A;
        a = A.display();
        if (a == 0)break;
        user B(a);
    }
}
  • 13
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值