无聊的c++期末实验验收(简单的通讯录管理系统)

/*简易电话薄管理系统
本程序纯属应付期末验收。
程序一共两个类:
Contact_person 描述电话薄中的联系人信息
System         系统程序,包含新建和查找这两个功能
其中查找到联系人后,可进行删除和修改
没有写文件操作,这样每次都必须重新新建联系人
读者可自行添加文件操作,已提供count记录电话薄中联系人的个数
以及flag标记,方便文件的读入及重写
程序几乎没有容错能力,不能处理非法输入
不能处理联系人姓名相同的情况*/
#include <cstdio>
#include <string>
#include <iostream>
#include <map>

using namespace std;
map <string,int> system_map;
class Contact_person{
    private:
        int ID;//该联系人的数字编号
        bool flag;//标记该联系人是否已经被删除
        string name,tel,remark;//remark为备注
    public:
        void assign(int id,string n,string t,string r){
            ID = id;
            name  = n;
            tel = t;
            remark = r;
        }
        void print(){
            cout << "Name  :" << name << endl;
            cout << "Tel   :" << tel << endl;
            cout << "Remark:" << remark << endl;
        }
        void delate(){
            flag = 0;
        }
};

Contact_person p[1000];
class System{
    private:
        int count;//记录目前电话薄中有多少联系人
        void show_sys(){
            cout << "***********************************" << endl;
            cout << "1 . 新建联系人" << endl;
            cout << "2 . 查找联系人" << endl;
            cout << "3 . 退出" << endl ;
            cout << "  请输入指令:" << endl;
            cout << "***********************************" << endl;
        }
        void show_search(){
            cout << "***********************" << endl;
            cout << "1 . 修改该联系人" << endl;
            cout << "2 . 删除该联系人" << endl;
            cout << "3 . 退出" << endl;
            cout << "请输入指令" << endl;
            cout << "***********************" << endl;
        }
        void build(){
            string name,tel,remark;
            cout << "请输入联系人姓名" << endl;
            cin >> name;
            cout << "请输入电话" << endl;
            cin >> tel;
            cout << "请输入备注"<< endl;
            cin >> remark;
            p[count].assign(count,name,tel,remark);
            cout << "\n新建成功!\n" << endl;
            p[count].print();
            system_map[name] = count;
            count++;
            return;
        }
        void search(string s){
            int tag;
            while(1){
                int id;
                if(system_map.count(s) != 0){
                    id = system_map[s];
                    cout << "\n查找成功!\n" << endl;
                    p[id].print();
                }
                else{
                    cout << "\n抱歉,您要查找的联系人不存在,请重新选择指令\n" << endl;
                    return;
                }
                show_search();
                cin >> tag;
                if(tag == 1){
                    string name,tel,remark;
                    cout << "请输入联系人姓名" << endl;
                    cin >> name;
                    cout << "请输入电话" << endl;
                    cin >> tel;
                    cout << "请输入备注"<< endl;
                    cin >> remark;
                    p[id].assign(id,name,tel,remark);
                    cout << "\n修改成功!\n" << endl;
                    p[id].print();
                    return;
                }
                else if(tag == 2){
                    system_map.erase(s);
                    p[id].delate();
                    cout << "\n删除成功!" << endl;
                    return;
                }
                else if(tag == 3){
                    return;
                }
                else{
                    cout << "输入错误,请重新输入" << endl;
                }
            }
        }
        void command(){
            int tag;
            while(1){
                show_sys();
                cin >> tag;
                if(tag == 1){
                    build();
                }
                else if(tag == 2){
                    string text;
                    cout << "请输入姓名:" << endl;
                    cin >> text;
                    search(text);
                }
                else if(tag == 3){
                    return;
                }
                else
                    cout << "输入错误,请重新输入" << endl;
            }
        }
    public:
        System(int c){
            count = c;
            command();
        }
};

int main(){
    System s(0);
    return 0;
}


 

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值