。。。。。课 2022-05-12 19:55 采纳率: 0%
浏览 75
已结题

关于#c#的问题,如何解决?

一.
课题研究现状
手机通讯录在我们生活中应用广泛,通讯录作为通讯录
地址的书本,当今的通讯录可以涵盖多项内容,实现了
人与人之间的交流需求。可利用结构体、函数等知识,
实现了清空,排序等功能。
二.技术支持
(1)结构体
(2)定义函数
(3)指针
((4)realloc函数
三、计划实现的功能框架
1.添加联系人
2.删除联系人
3.显示联系人
4.查找联系人(根据首字母查找)
5.更改联系人信息
6.清空通讯录
7.收藏联系人

  • 写回答

3条回答 默认 最新

  • 吕布辕门 新星创作者: 后端开发技术领域 2022-05-12 20:12
    关注

    你看一下哈,可以参考。有注释,不清楚的可以问

    #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;//QQMobilecontact(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);
        }
    }
    
    
    
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月16日
  • 赞助了问题酬金5元 5月12日
  • 创建了问题 5月12日