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

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

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

#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);
    }
}
目录
相关文章
|
7月前
|
存储 监控 算法
员工屏幕监控系统之 C++ 图像差分算法
在现代企业管理中,员工屏幕监控系统至关重要。本文探讨了其中常用的图像差分算法,该算法通过比较相邻两帧图像的像素差异,检测屏幕内容变化,如应用程序切换等。文中提供了C++实现代码,并介绍了其在实时监控、异常行为检测和数据压缩等方面的应用,展示了其实现简单、效率高的特点。
169 15
|
11月前
|
存储 C++ UED
【实战指南】4步实现C++插件化编程,轻松实现功能定制与扩展
本文介绍了如何通过四步实现C++插件化编程,实现功能定制与扩展。主要内容包括引言、概述、需求分析、设计方案、详细设计、验证和总结。通过动态加载功能模块,实现软件的高度灵活性和可扩展性,支持快速定制和市场变化响应。具体步骤涉及配置文件构建、模块编译、动态库入口实现和主程序加载。验证部分展示了模块加载成功的日志和配置信息。总结中强调了插件化编程的优势及其在多个方面的应用。
1079 176
|
8月前
|
存储 算法 搜索推荐
【C++面向对象——群体类和群体数据的组织】实现含排序功能的数组类(头歌实践教学平台习题)【合集】
1. **相关排序和查找算法的原理**:介绍直接插入排序、直接选择排序、冒泡排序和顺序查找的基本原理及其实现代码。 2. **C++ 类与成员函数的定义**:讲解如何定义`Array`类,包括类的声明和实现,以及成员函数的定义与调用。 3. **数组作为类的成员变量的处理**:探讨内存管理和正确访问数组元素的方法,确保在类中正确使用动态分配的数组。 4. **函数参数传递与返回值处理**:解释排序和查找函数的参数传递方式及返回值处理,确保函数功能正确实现。 通过掌握这些知识,可以顺利地将排序和查找算法封装到`Array`类中,并进行测试验证。编程要求是在右侧编辑器补充代码以实现三种排序算法
128 5
|
9月前
|
算法 网络协议 数据挖掘
C++是一种功能强大的编程语言,
C++是一种功能强大的编程语言,
161 14
|
C++
【C++案例】一个项目掌握C++基础-通讯录管理系统
这篇文章通过一个通讯录管理系统的C++项目案例,详细介绍了如何使用C++实现添加、显示、删除、查找、修改和清空联系人等功能。
207 3
|
存储 数据可视化 C++
【C++】C++-学生考试题库管理系统(源码)
本系统设计了一个选题管理流程,包括读取题目信息、随机抽取题目、保存及查询选题结果等功能。使用 `readProjects` 从文件读取题目信息,`drawProject` 随机抽取未选中的题目,`saveSelection` 保存选题结果至文件,`querySelection` 查询并显示所有选题结果。主函数提供菜单界面,支持学生信息输入、抽题及结果查询。关注【测试开发自动化】公众号,回复“题库”获取源码。
138 1
|
Rust 安全 C++
系统编程的未来之战:Rust能否撼动C++的王座?
【8月更文挑战第31天】Rust与C++:现代系统编程的新选择。C++长期主导系统编程,但内存安全问题频发。Rust以安全性为核心,通过所有权和生命周期概念避免内存泄漏和野指针等问题。Rust在编译时确保内存安全,简化并发编程,其生态系统虽不及C++成熟,但发展迅速,为现代系统编程提供了新选择。未来有望看到更多Rust驱动的系统级应用。
250 1
|
图形学 C++ C#
Unity插件开发全攻略:从零起步教你用C++扩展游戏功能,解锁Unity新玩法的详细步骤与实战技巧大公开
【8月更文挑战第31天】Unity 是一款功能强大的游戏开发引擎,支持多平台发布并拥有丰富的插件生态系统。本文介绍 Unity 插件开发基础,帮助读者从零开始编写自定义插件以扩展其功能。插件通常用 C++ 编写,通过 Mono C# 运行时调用,需在不同平台上编译。文中详细讲解了开发环境搭建、简单插件编写及在 Unity 中调用的方法,包括创建 C# 封装脚本和处理跨平台问题,助力开发者提升游戏开发效率。
1146 0
|
C++
使用 QML 类型系统注册 C++ 类型
使用 QML 类型系统注册 C++ 类型
426 0
|
7月前
|
编译器 C++ 开发者
【C++篇】深度解析类与对象(下)
在上一篇博客中,我们学习了C++的基础类与对象概念,包括类的定义、对象的使用和构造函数的作用。在这一篇,我们将深入探讨C++类的一些重要特性,如构造函数的高级用法、类型转换、static成员、友元、内部类、匿名对象,以及对象拷贝优化等。这些内容可以帮助你更好地理解和应用面向对象编程的核心理念,提升代码的健壮性、灵活性和可维护性。