目录

一,设计要求3

(一)功能设计要求3

1.建立文件3

2.文件存储3

3.读取文件3

4.增加学生记录3

5.删除记录4

6.修改记录4

7.查询记录4

8.显示记录4

9.关于记录的排序4

10.测试程序5

(二)总体设计5

1.结构层次

实体结构层次5

(1)第一层:contact_per.h个人信息层

(2)第二层:database.h数据库层5

(3)第三层:oper.h用户操作层5

两个平行交互层(与前三层进行关联)5

(1)menu.h目录层5

(2)主源代码.cpp接口层6

2.结构具​​体实现细节6

第一层:contact_per.h个人信息层6

手机单个用户类6

手机卡单个用户类6

第二层:database.h数据库层6

手机数据库类6

手机卡数据库类6

第三层:oper.h用户操作层7

二,界面设计与各功能模块实现9

(一)界面设计9

(二)功能模块实现10

四,使用说明及编程体会10

(一)使用说明10

(二)编程体会10

完整源代码11

实体结构层次11

两个平行交互层(与前三层进行关联)36

参考文献41

一,设计要求

(一)功能设计要求

1.建立文件

(1)程序采用相对路径保存文件,以提高程序健壮性。

(2)手机和手机卡联系人分别存储于工程文件夹下与源代码同文件夹的PHONE_CONTACT和SD_contact下。

(3)通过构造函数构建函数打开文件时,通过特别的判定机制,如果文件丢失会跳过本地记录同步过程,不会发生卡死现象,在程序结束时会创建新文件,第二次打开会正常运行。

(4)写文件时若有同名文件存在则会进行覆盖,保证数据的同步性。

2.文件存储

返回主菜单或者退出程序时会自动覆写到文件,不需要手工操作保存,更加人性化。

3.读取文件

程序启动时会读取两个本地文件中的本地记录,同步到多重映射中后,由用户决定是否浏览,之后正式进入主菜单。

4.增加学生记录

(1)分为保存到手机和手机卡两个选项,在保存文件前,新增内容和读取到的原来的内容都保存在多重映射多重映射中,在返回主菜单或者退出程序时会自动更新到文件。

(2)设置了最大存储容量,手机默认是200,手机卡为2000,可以允许的最大安全容量为27531841条记录,超过后由于栈区内存限制不能保证安全性。在主菜单选项8中可以修改。

5.删除记录

(1)可以按照姓名列出所有的联系人进行任意形式的删除操作。

(2)进行删除之前会先确定联系人所在位置,定位操作采用的是二分查找算法,通过lower_bound和upper_bound确定同名记录的范围.O(log2n)级复杂度,比传统的顺序查找方式具有更高的效率的算法支撑。

(2)程序中有关删除的模式共有八种分别是:

1)手机通讯录(删除同名字全部记录)。

2)手机卡通讯录。(删除同名字全部记录)。

3)手机通讯录。(删除同名字某条记录)。

4)手机卡通讯录。(删除同名的某条记录)。

5)两个通讯录都进行名字清空(抹消该名字的全部记录)

6)清空手机卡通讯录。

7)清空手机通讯录

8)清除所有记录

6.修改记录

(1)系统会按照姓名列出所有的联系人

(2)对名字进行定位并进行该名字下的某条记录任意形式的修改操作。

(3)程序中有关修改的模式共有两种分别是:

修改手机中某条记录的任意一项信息

修改手机卡中某条记录的任意一项信息

7.查询记录

(1)输入名字后列出手机和手机卡中所有该名字的记录。

(2)内置定位算法是二分查找算法,具有更高的查询速度。

8.显示记录

(1)分为“全部展示”,仅展示“手机通讯录”,仅展示“手机卡通讯录”三种模式

(2)在显示出主菜单后可以按5随时显示当前数据库中信息。

(3)若没有记录可以显示,则给出提示信息。

9.关于记录的排序

由于多重映射的本质是红黑树,会按照键值自动有序,所以在内存中记录默认是从A->ž成字典序排列的,不需要手动排序。但是对于非ASCII码字符,会自动追加在记录的最后面。为了字典序二分算法的顺利运行,并没有设计能手动更改排序规则的操作。

测试程序

本程序在上交前通过了各项边缘测试,健壮性良好。

在27531841条记录下均表现出了良好的算法性能,极大地体现了多重映射的树形结构比起普通顺序容器的优势

(二)总体设计

1.结构层次概括

本设计共计1522行代码。

底层数据结构是STL中多重映射实现的红黑树,比传统的顺序容器具有更高的各类算法性能

组织设计模式参考了网络的OSI模型思想,进行了从底层到高层的封装

本设计由5个文件构成:五个头文件(.H)和​​一个主源代码文件(的.cpp)

共有三个实体结构层次由低到高分别为

实体结构层次

(1)第一层:contact_per.h个人信息层。

这部分包括:

Phone_contact_per和Mobile_phone_contacts_per两个类

储存手机和卡​​中单个人的信息及其操作

(2)第二层:database.h数据库层

这部分包括:

DatabasePhone和DatabaseSD两个数据库类。

将第一层通过多重映射多重映射进行封装。

储存两个联系人数据库以及对其进行的各类操作。

(3)第三层:oper.h用户操作层

这部分包括:用户类

封装了第二层并进行用户层面上的各类操作。

两个平行交互层(与前三层进行关联)

(1)menu.h目录层

这部分包括:

前三层各类操作的目录以及提示信息,程序在运行时将在平行交互层和实体结构层次不断交互。将目录单独封装显得代码更加条理,便于阅读且容易修改,不容易出错。

(2)主源代码.cpp接口层

这部分包括:

整个程序的入口,实现各种功能选择性跳转的实现部分,进入使用开关结构,退出时则提供了返回到主菜单,返回上一级,退出并保存三种选项。

2.结构具​​体实现细节

第一层:contact_per.h个人信息层

手机单个用户类

class Phone_contact_per
{
protected:string phone_number;//姓名,电话号码
public:string name;Phone_contact_per(string pname="NULL_name",string ptel="NULL_phone");   //带参并带默认值的构造函数void set(string pname="NULL_name",string ptel="NULL_phone");   //一组set函数为数据成员赋值void modify();  //一组modify函数,修改数据成员的值friend istream &operator>>(istream &in,Phone_contact_per &per);  //重载>>,<<运算符,完成对象的输入和输出操作*/friend ostream &operator<<(ostream &out,Phone_contact_per &per);friend class User;//第三层操作权限friend class DatabasePhone;//第二层操作权限
}phone_contact_per;

手机卡单个用户类

class Mobile_phone_contacts_per:public Phone_contact_per
{
protected:string home_address,qq_number;//新增数据成员:籍贯,QQ号
public:Mobile_phone_contacts_per(string pname="NULL_name",string ptel="NULL_phone",string phome="NULL_home",string pqq="NULL_qq");void set(string pname="NULL_name",string ptel="NULL_phone",string phome="NULL_home",string pqq="NULL_qq");    //一组set函数为数据成员赋值void modify();  //一组modify函数,修改数据成员的值friend istream &operator>>(istream &in,Mobile_phone_contacts_per &per);  //重载>>,<<运算符,完成对象的输入和输出操作*/friend ostream &operator<<(ostream &out,Mobile_phone_contacts_per &per);friend class User;friend class DatabaseSD;
};

第二层:database.h数据库层

手机数据库类

class DatabasePhone
{
private:unsigned long long int Phone_num;//表示当前手机已经存储了的电话信息个数multimap<string,Phone_contact_per> phone_contact;//手机数据库
public:DatabasePhone(){Phone_num=0;}inline bool check();//检查手机是否存满void per_out(multimap<string,Phone_contact_per>::iterator &p);//输出单个人的信息void add();void lookUp(string);unsigned long long int look_per_howmuch(string);//返回SD卡中某人信息的个数void del(multimap<string,Phone_contact_per>::iterator &p);void modify();friend class User;
};

手机卡数据库类

class DatabaseSD
{
private:unsigned long long int SD_num;multimap<string,Mobile_phone_contacts_per> mobile_phone_contact;//SD卡数据库
public:DatabaseSD(){SD_num=0;}//表示当前SD卡已经存储了的电话信息个数inline bool check();//检查SD卡是否存满void per_out(multimap<string,Mobile_phone_contacts_per>::iterator &p);//输出单个人的信息void add();void del(multimap<string,Mobile_phone_contacts_per>::iterator &p);void lookUp(string);unsigned long long int look_per_howmuch(string);//返回SD卡中某人信息的个数friend class User;
};

第三层:oper.h用户操作层

class User
{
private:DatabasePhone phone;//手机数据库DatabaseSD SDcard;//手机卡数据库
public:User();//程序启动文件读取~User();//程序关闭文件存储Menu menu;//与菜单进行交互void add();//添加记录void look();//查询记录void del();//删除记录void modify();//修改记录void display();//浏览记录void display_local();//浏览本地记录void store();//返回主菜单时存储//复制的六种模式void copyToPhone_per();//复制同名记录到手机void copyToPhone();//全部复制到手机void copyToSD_per();//复制同名记录到卡void copyToSD();//全部复制到卡void copyToSD_one();//复制某条记录到手机void copyToPhone_one();//复制某条记录到卡//移动的六种模式(大体同复制模式,按照名字划分)void moveToPhone_per();void moveToPhone();void moveToSD_per();void moveToSD();void moveToSD_one();void moveToPhone_one();void modifymax();//修改默认最大容量
};

二,界面设计与各功能模块实现

(一)界面设计

界面设计全部包含在交互层中的菜单类当中,具体包括以下界面:

class Menu{
public:  void description();  //程序启动界面void mainmenu();     //主菜单void addmenu();      //添加人员菜单void remove1menu();  //删除人员菜单void changemenu();   //修改人员菜单void displaymenu();  //浏览人员菜单void lookmenu();     //查询人员菜单void displaymenu1(); //查询人员选项菜单void displaymenu2(); //查询人员选项菜单void Phone_contact_per_modify();         //修改手机信息菜单void Mobile_phone_contacts_per_modify(); //修改手机卡信息菜单void modify();      //修改信息主菜单void copy();        //复制信息主菜单void move();        //移动信息主菜单void user_return(); //返回操作菜单void sd_read_success();//以下都是读写提示void sd_read_fail();void sd_write_success();void sd_write_fail();void phone_read_success();void phone_read_fail();void phone_write_success();void phone_write_fail();void menumodifymax();//修改最大容量菜单
}menu;  

篇幅问题,仅仅列出主菜单,实际效果建议自己运行试试

(二)功能模块实现

实体操作层,高层(用户层)执行宏观操作,底层(数据库层)执行实际操作。

交互层负责各类提示和程序流程跳转

代码文件放在附录,需要具体实现可以自行查阅

四,使用说明及编程体会

(一)使用说明

按照交互层的提示操作程序即可

(二)编程体会

此次课程设计极大程度的统合了自己学过的各种知识,积累了大量的经验。对于多重映射的使用更加熟悉,为日后写大型程序奠定了扎实的基础。独立完成本设计后获得了成就感,真真切切的感受到了写程序的兴趣。

感谢老师对我平时的指导给了我完成本设计的灵感和知识能力。

三天1522行代码,虽然累,但是最终做出成果来的时候真的很高兴,期待我的下一个项目。(写项目可比打算法竞赛舒服多了)

完整源代码

实体结构层次

(1)第一层:contact_per.h个人信息层。

/*
这部分包括:
Phone_contact_per和Mobile_phone_contacts_per两个类
表示单个人的信息及其操作
*/
#ifndef contact_per_h
#define contact_per_h
#include<iostream>
#include<string>
#include<map>
#include<cstdio>
#include<climits>
#include<algorithm>
#include"menu.h"
using namespace std;
char choose='\0';
class Phone_contact_per
{
protected:string phone_number;//姓名,电话号码
public:string name;Phone_contact_per(string pname="NULL_name",string ptel="NULL_phone");   //带参并带默认值的构造函数void set(string pname="NULL_name",string ptel="NULL_phone");   //一组set函数为数据成员赋值void modify();  //一组modify函数,修改数据成员的值friend istream &operator>>(istream &in,Phone_contact_per &per);  //重载>>,<<运算符,完成对象的输入和输出操作*/friend ostream &operator<<(ostream &out,Phone_contact_per &per);friend class User;//第三层操作权限friend class DatabasePhone;//第二层操作权限
}phone_contact_per;
//类外实现部分
Phone_contact_per::Phone_contact_per(string pname,string ptel)
{name=pname;phone_number=ptel;
}
void Phone_contact_per::set(string pname,string ptel)
{name=pname;phone_number=ptel;
}
void Phone_contact_per::modify()
{menu.Phone_contact_per_modify();cin>>choose;switch (choose){case '1':{cout<<"您选择了修改姓名\n,请输入要改成的姓名"<<endl;string t_name;cin>>t_name;name=t_name;cout<<"修改成功"<<endl;break;}case '2':{cout<<"您选择了修改电话号码,请输入要改成的电话号码"<<endl;string t_num;cin>>t_num;phone_number=t_num;cout<<"修改成功"<<endl;break;}case '3':{cout<<"您选择了全修改,请输入新的姓名和电话号码"<<endl;string t_name,t_num;cin>>t_name;cin>>t_num;name=t_name;phone_number=t_num;cout<<"修改成功"<<endl;break;}case '4':return;default:cout<<"选择错误,不做任何修改\n"<<endl;}
}
istream &operator>>(istream &in,Phone_contact_per &per)
{in>>per.name>>per.phone_number;return in;
}
ostream &operator<<(ostream &out,Phone_contact_per &per)
{out<<"----》名字        "<<per.name<<endl<<"      电话号码:   "<<per.phone_number<<endl;return out;
}
//----------------------------------------
class Mobile_phone_contacts_per:public Phone_contact_per
{
protected:string home_address,qq_number;//新增数据成员:籍贯,QQ号
public:Mobile_phone_contacts_per(string pname="NULL_name",string ptel="NULL_phone",string phome="NULL_home",string pqq="NULL_qq");void set(string pname="NULL_name",string ptel="NULL_phone",string phome="NULL_home",string pqq="NULL_qq");    //一组set函数为数据成员赋值void modify();  //一组modify函数,修改数据成员的值friend istream &operator>>(istream &in,Mobile_phone_contacts_per &per);  //重载>>,<<运算符,完成对象的输入和输出操作*/friend ostream &operator<<(ostream &out,Mobile_phone_contacts_per &per);friend class User;friend class DatabaseSD;
};
Mobile_phone_contacts_per::Mobile_phone_contacts_per(string pname,string ptel,string phome,string pqq):Phone_contact_per(pname,ptel)
{home_address=phome;qq_number=pqq;
}
void Mobile_phone_contacts_per::set(string pname,string ptel,string phome,string pqq)
{name=pname;phone_number=ptel;home_address=phome;qq_number=pqq;
}
void Mobile_phone_contacts_per::modify()
{menu.Mobile_phone_contacts_per_modify();cin>>choose;switch (choose){case '1':{cout<<"您选择了修改姓名\n,请输入要改成的姓名"<<endl;string t_name;cin>>t_name;name=t_name;cout<<"修改成功"<<endl;break;}case '2':{cout<<"您选择了修改电话号码,请输入要改成的电话号码"<<endl;string t_num;cin>>t_num;phone_number=t_num;cout<<"修改成功"<<endl;break;}case '3':{cout<<"您选择了修改家庭住址,请输入要改成的家庭住址"<<endl;string t_address;cin>>t_address;home_address=t_address;cout<<"修改成功"<<endl;break;}case '4':{cout<<"您选择了修改QQ,请输入要改成的QQ"<<endl;string t_qq;cin>>t_qq;qq_number=t_qq;cout<<"修改成功"<<endl;break;}case '5':{cout<<"全修改、输入姓名电话、家庭住址、QQ"<<endl;string t_name,t_tel,t_addr,t_qq;cin>>t_name>>t_tel>>t_addr>>t_qq;name=t_name;phone_number=t_tel;home_address=t_addr;qq_number=t_qq;cout<<"修改成功"<<endl;break;}case '6':return;default:cout<<"选择错误,不做任何修改\n"<<endl;}
}
istream &operator>>(istream &in,Mobile_phone_contacts_per &per)
{in>>per.name>>per.phone_number>>per.home_address>>per.qq_number;return in;
}
ostream &operator<<(ostream &out,Mobile_phone_contacts_per &per)
{cout<<"----》名字\t\t"<<per.name<<endl<<"      电话号码\t"<<per.phone_number<<endl<<"      住址\t\t"<<per.home_address<<endl<<"      QQ号\t\t"<<per.qq_number<<endl;return out;
}
#endif 

(2)第二层:database.h    数据库层

#ifndef datebase_h
#define datebase_h
/*这部分包括两个数据库类
*/
long long unsigned int max_phone_capacity=200;//初始化手机最大容量
long long unsigned int max_SDcard_capacity=2000;//初始化SD卡最大容量
class DatabasePhone
{
private:unsigned long long int Phone_num;//表示当前手机已经存储了的电话信息个数multimap<string,Phone_contact_per> phone_contact;//手机数据库
public:DatabasePhone(){Phone_num=0;}inline bool check();//检查手机是否存满void per_out(multimap<string,Phone_contact_per>::iterator &p);//输出单个人的信息void add();void lookUp(string);unsigned long long int look_per_howmuch(string);//返回SD卡中某人信息的个数void del(multimap<string,Phone_contact_per>::iterator &p);void modify();friend class User;
};
inline bool DatabasePhone::check()
{if(Phone_num>max_phone_capacity) {cout<<"手机容量已满,最大上限为"<<max_phone_capacity<<endl;return false;}else return true;
}
void DatabasePhone::add()
{Phone_contact_per temp;cout<<"请输入姓名与手机号"<<endl;cin>>temp;phone_contact.insert(pair<string,Phone_contact_per>(temp.name,temp));//添加新记录的过程Phone_num++;
}
void DatabasePhone::del(multimap<string,Phone_contact_per>::iterator &p)
{phone_contact.erase(p);cout<<"删除成功"<<endl;
}
void DatabasePhone::lookUp(string lookname)
{multimap<string,Phone_contact_per>::iterator look_itor_head,look_itor_foot;//查询手机联系人look_itor_head=phone_contact.equal_range(lookname).first;look_itor_foot=phone_contact.equal_range(lookname).second;if(look_itor_head==look_itor_foot){cout<<"手机中无此联系人"<<endl;return;}else menu.displaymenu1();for(multimap<string,Phone_contact_per>::iterator i=look_itor_head;i!=look_itor_foot;cout<<i->second<<endl,i++);
}
unsigned long long int DatabasePhone::look_per_howmuch(string lookname)
{multimap<string,Phone_contact_per>::iterator look_itor_head,look_itor_foot;//查询手机联系人look_itor_head=phone_contact.lower_bound(lookname);look_itor_foot=phone_contact.upper_bound(lookname);return distance(look_itor_head,look_itor_foot);
}
void DatabasePhone::per_out(multimap<string,Phone_contact_per>::iterator &p){cout<<"----》名字                            "<<p->second.name<<endl<<"      电话号码                        "<<p->second.phone_number<<endl;}
//***************************************************
class DatabaseSD
{
private:unsigned long long int SD_num;multimap<string,Mobile_phone_contacts_per> mobile_phone_contact;//SD卡数据库
public:DatabaseSD(){SD_num=0;}//表示当前SD卡已经存储了的电话信息个数inline bool check();//检查SD卡是否存满void per_out(multimap<string,Mobile_phone_contacts_per>::iterator &p);//输出单个人的信息void add();void del(multimap<string,Mobile_phone_contacts_per>::iterator &p);void lookUp(string);unsigned long long int look_per_howmuch(string);//返回SD卡中某人信息的个数friend class User;
};
inline bool DatabaseSD::check()
{if(SD_num>max_SDcard_capacity) {cout<<"手机卡容量已满,最大上限为"<<max_SDcard_capacity<<endl;return false;}else return true;
}
void DatabaseSD::add()
{Mobile_phone_contacts_per temp;cout<<"请输入姓名、手机号、家庭住址、QQ号"<<endl;cin>>temp;mobile_phone_contact.insert(pair<string,Mobile_phone_contacts_per>(temp.name,temp));//添加新记录的过程SD_num++;
}
void DatabaseSD::del(multimap<string,Mobile_phone_contacts_per>::iterator &p)
{mobile_phone_contact.erase(p);cout<<"删除成功"<<endl;
}
void DatabaseSD::lookUp(string lookname)
{multimap<string,Mobile_phone_contacts_per>::iterator look_itor_head,look_itor_foot;//查询手机联系人look_itor_head=mobile_phone_contact.lower_bound(lookname);look_itor_foot=mobile_phone_contact.upper_bound(lookname);if(look_itor_head==look_itor_foot){cout<<"SD卡中无此联系人"<<endl;return;}else menu.displaymenu2();for(multimap<string,Mobile_phone_contacts_per>::iterator i=look_itor_head;i!=look_itor_foot;cout<<i->second<<endl,i++);
}
unsigned long long int DatabaseSD::look_per_howmuch(string lookname)
{multimap<string,Mobile_phone_contacts_per>::iterator look_itor_head,look_itor_foot;//查询手机卡联系人look_itor_head=mobile_phone_contact.lower_bound(lookname);look_itor_foot=mobile_phone_contact.upper_bound(lookname);return distance(look_itor_head,look_itor_foot);
}
void DatabaseSD::per_out(multimap<string,Mobile_phone_contacts_per>::iterator &p){cout<<"----》名字                            "<<p->second.name<<endl<<"      电话号码                        "<<p->second.phone_number<<endl<<"      住址                            "<<p->second.home_address<<endl<<"      QQ号                            "<<p->second.qq_number<<endl;}
#endif 

(3)第三层:oper.h用户操作层

/*这部分包括用户类及其操作
*/
#include"contact_per.h"
#include"menu.h"
#include"database.h"
#include<fstream>
using namespace std;
class User
{
private:DatabasePhone phone;//手机数据库DatabaseSD SDcard;//手机卡数据库
public:User();//程序启动文件读取~User();//程序关闭文件存储Menu menu;//与菜单进行交互void add();//添加记录void look();//查询记录void del();//删除记录void modify();//修改记录void display();//浏览记录void display_local();//浏览本地记录void store();//返回主菜单时存储//复制的六种模式void copyToPhone_per();//复制同名记录到手机void copyToPhone();//全部复制到手机void copyToSD_per();//复制同名记录到卡void copyToSD();//全部复制到卡void copyToSD_one();//复制某条记录到手机void copyToPhone_one();//复制某条记录到卡//移动的六种模式(大体同复制模式,按照名字划分)void moveToPhone_per();void moveToPhone();void moveToSD_per();void moveToSD();void moveToSD_one();void moveToPhone_one();void modifymax();//修改默认最大容量
};
User::User()
{fstream phone_read("phone_contact",ios::in);if(phone_read)menu.phone_read_success();else {menu.phone_read_fail();return;}Phone_contact_per temp_phone;phone_read>>temp_phone.name>>temp_phone.phone_number;while(!phone_read.eof()){phone_read>>temp_phone.name>>temp_phone.phone_number;phone.phone_contact.insert(pair<string,Phone_contact_per>(temp_phone.name,temp_phone));phone.Phone_num++;}fstream SD_read("SD_contact",ios::in);if(SD_read) menu.sd_read_success();else {menu.sd_read_fail();return;}Mobile_phone_contacts_per temp;SD_read>>temp.name>>temp.phone_number>>temp.home_address>>temp.qq_number;while(!SD_read.eof()){SD_read>>temp.name>>temp.phone_number>>temp.home_address>>temp.qq_number;SDcard.mobile_phone_contact.insert(pair<string,Mobile_phone_contacts_per>(temp.name,temp));SDcard.SD_num++;}SD_read.close();display_local();}
User::~User()
{ofstream phone_write("phone_contact");multimap<string,Phone_contact_per>::iterator itor_phone_head=phone.phone_contact.begin(),itor_foot_phone=phone.phone_contact.end();for(;itor_phone_head!=itor_foot_phone;itor_phone_head++){if(itor_phone_head->second.name=="NULL_name") continue;phone_write<<itor_phone_head->second.name<<' '<<itor_phone_head->second.phone_number<<endl;}if(phone_write) menu.phone_write_success();else menu.phone_write_fail();phone_write.close();ofstream SD_write("SD_contact");multimap<string,Mobile_phone_contacts_per>::iterator itor_head_sd=SDcard.mobile_phone_contact.begin(),itor_foot_sd=SDcard.mobile_phone_contact.end();for(;itor_head_sd!=itor_foot_sd;itor_head_sd++){if(itor_head_sd->second.name=="NULL_name") continue;SD_write<<itor_head_sd->second.name<<' '<<itor_head_sd->second.phone_number<<' '<<itor_head_sd->second.home_address<<' '<<itor_head_sd->second.qq_number<<endl;}if(SD_write) menu.sd_write_success();else menu.sd_write_fail();SD_write.close();}
void User::add()
{while (1){menu.addmenu();//1是手机通讯录,2是手机卡通讯录char tem;cin>>tem;if(tem=='1'){phone.add();if(phone.check()){cout<<"添加完成"<<endl;break;}else continue;}else if(tem=='2'){SDcard.add();if(SDcard.check()){cout<<"添加完成"<<endl;break;}else continue;}else{while(1){cout<<"选项输入错误,是否重新添加?Y/N(不区分大小写)"<<endl;cin>>tem;if(tem=='Y'||tem=='y') break;else if(tem=='N'||tem=='n') return;cout<<"请回答正确选项!";}}}
}
void User::look()
{cout<<"请输入人名,系统将会自动查询信息"<<endl;string ask_name;cin>>ask_name;phone.lookUp(ask_name);SDcard.lookUp(ask_name);
}
void User::del()
{menu.remove1menu();cin>>choose;multimap<string,Phone_contact_per>::iterator Phone_itor=phone.phone_contact.begin();menu.displaymenu1();if(!distance(phone.phone_contact.begin(),phone.phone_contact.end()))cout<<"    手机中无记录"<<endl;for(;Phone_itor!=phone.phone_contact.end();phone.per_out(Phone_itor),Phone_itor++);multimap<string,Mobile_phone_contacts_per>::iterator SDitor=SDcard.mobile_phone_contact.begin();menu.displaymenu2();for(;SDitor!=SDcard.mobile_phone_contact.end();SDcard.per_out(SDitor),SDitor++);if(!distance(SDcard.mobile_phone_contact.begin(),SDcard.mobile_phone_contact.end()))cout<<"    手机卡中无记录"<<endl;cout<<"    显示完毕"<<endl;switch (choose){case '1':{string movename;cout<<"输入要删除的姓名,手机中与该姓名有关的所有记录将被删除"<<endl;cin>>movename;phone.phone_contact.erase(movename);phone.Phone_num-=phone.look_per_howmuch(movename);cout<<"手机中关于"<<movename<<"的记录已经全部删除"<<endl;break;}case '2':{string movename;cout<<"输入要删除的姓名,手机卡与该姓名有关的所有记录将被删除"<<endl;cin>>movename;SDcard.mobile_phone_contact.erase(movename);SDcard.SD_num-=SDcard.look_per_howmuch(movename);cout<<"手机卡中关于"<<movename<<"的记录已经全部删除"<<endl;break;}case '3':{string movename;int num=0;cout<<"输入想要进行操作的名字"<<endl;cin>>movename;cout<<"系统将显示当前目录下所有名字叫"<<movename<<"的人,选择要删除的人是第几个"<<endl;multimap<string,Phone_contact_per>::iterator Phone_itor=phone.phone_contact.equal_range(movename).first,p=Phone_itor,endit=phone.phone_contact.equal_range(movename).second;if(!distance(Phone_itor,endit)){cout<<"无记录"<<endl;return;}menu.displaymenu1();for(;Phone_itor!=endit;phone.per_out(Phone_itor),Phone_itor++);cout<<"显示完毕"<<endl;cin>>num;for(int i=1;i<num;i++,p++);phone.del(p);cout<<"删除完成"<<endl;break;}case '4':{string movename;int num=0;cout<<"输入想要进行操作的名字"<<endl;cin>>movename;cout<<"系统将显示当前目录下所有名字叫"<<movename<<"的人,选择要删除的人是第几个"<<endl;multimap<string,Mobile_phone_contacts_per>::iterator SD_itor=SDcard.mobile_phone_contact.equal_range(movename).first,p=SD_itor,endit=SDcard.mobile_phone_contact.equal_range(movename).second;if(!distance(SD_itor,endit)){cout<<"无记录"<<endl;return;}menu.displaymenu1();for(;SD_itor!=endit;SDcard.per_out(SD_itor),SD_itor++);cout<<"显示完毕"<<endl;cin>>num;for(int i=1;i<num;i++,p++);SDcard.del(p);cout<<"删除完成"<<endl;break;}case '5':{string movename;cout<<"输入要删除的姓名,与该姓名有关的所有记录将全部被删除"<<endl;cin>>movename;phone.phone_contact.erase(movename);phone.Phone_num-=phone.look_per_howmuch(movename);SDcard.mobile_phone_contact.erase(movename);SDcard.SD_num-=SDcard.look_per_howmuch(movename);cout<<"关于"<<movename<<"的记录已经全部删除"<<endl;break;}case '6':phone.phone_contact.clear();break;case '7':SDcard.mobile_phone_contact.clear();break;case '8':phone.phone_contact.clear();SDcard.mobile_phone_contact.clear();break;default:cout<<"选择错误,不作任何删除"<<endl;}}
void User::modify()
{multimap<string,Phone_contact_per>::iterator Phone_itor=phone.phone_contact.begin();menu.displaymenu1();if(!distance(phone.phone_contact.begin(),phone.phone_contact.end()))cout<<"    手机中无记录"<<endl;for(;Phone_itor!=phone.phone_contact.end();phone.per_out(Phone_itor),Phone_itor++);multimap<string,Mobile_phone_contacts_per>::iterator SDitor=SDcard.mobile_phone_contact.begin();menu.displaymenu2();for(;SDitor!=SDcard.mobile_phone_contact.end();SDcard.per_out(SDitor),SDitor++);if(!distance(SDcard.mobile_phone_contact.begin(),SDcard.mobile_phone_contact.end()))cout<<"    手机卡中无记录"<<endl;cout<<"    显示完毕"<<endl;cout<<"输入想要修改的人名"<<endl;string name;int num=0;cin>>name;phone.lookUp(name);SDcard.lookUp(name);menu.changemenu();cin>>choose;if(choose=='1'){cout<<"想修改第几条记录"<<endl;cin>>num;multimap<string,Phone_contact_per>::iterator p=phone.phone_contact.equal_range(name).first;for(int i=1;i<num;i++,p++);p->second.modify();}else if(choose=='2'){cout<<"想修改第几条记录"<<endl;cin>>num;multimap<string,Mobile_phone_contacts_per>::iterator p=SDcard.mobile_phone_contact.equal_range(name).first;for(int i=1;i<num;i++,p++);p->second.modify();}else return;
}
void User::store()
{fstream phone_write("phone_contact",ios::out,ios::trunc);multimap<string,Phone_contact_per>::iterator itor_phone_head=phone.phone_contact.begin(),itor_foot_phone=phone.phone_contact.end();for(;itor_phone_head!=itor_foot_phone;itor_phone_head++)phone_write<<itor_phone_head->second.name<<' '<<itor_phone_head->second.phone_number<<endl;phone_write.close();fstream SD_write("SD_contact",ios::out,ios::trunc);multimap<string,Mobile_phone_contacts_per>::iterator itor_head_sd=SDcard.mobile_phone_contact.begin(),itor_foot_sd=SDcard.mobile_phone_contact.end();for(;itor_head_sd!=itor_foot_sd;itor_head_sd++)SD_write<<itor_head_sd->second.name<<' '<<itor_head_sd->second.phone_number<<' '<<itor_head_sd->second.home_address<<' '<<itor_head_sd->second.qq_number<<endl;SD_write.close();}
void User::copyToPhone_per()
{string copyname;cin>>copyname;multimap<string,Mobile_phone_contacts_per>::iterator itor_head=SDcard.mobile_phone_contact.begin(),itor_foot=SDcard.mobile_phone_contact.end();Phone_contact_per temp;if(!phone.look_per_howmuch(itor_head->first)) {if(phone.Phone_num>max_phone_capacity) {cout<<"很遗憾,手机容量已满,上限为:"<<max_phone_capacity<<endl<<"已经复制的不做改动"<<endl;return;}temp.name=itor_head->first;temp.phone_number=itor_head->second.phone_number;while(itor_head!=itor_foot){phone.phone_contact.insert(pair<string,Phone_contact_per>(temp.name,temp));phone.Phone_num++;}}cout<<"恭喜你,复制成功!"<<endl;
}
void User::copyToPhone()
{multimap<string,Mobile_phone_contacts_per>::iterator itor_head=SDcard.mobile_phone_contact.begin(),itor_foot=SDcard.mobile_phone_contact.end();Phone_contact_per temp;if(!phone.look_per_howmuch(itor_head->first)) {if(phone.Phone_num>max_phone_capacity) {cout<<"很遗憾,手机容量已满,上限为:"<<max_phone_capacity<<endl<<"已经复制的不做改动。"<<endl;return;}temp.name=itor_head->first;temp.phone_number=itor_head->second.phone_number;phone.phone_contact.insert(pair<string,Phone_contact_per>(temp.name,temp));phone.Phone_num++;}cout<<"恭喜你,全部复制成功!"<<endl;
}
void User::copyToSD_per()
{string copyname;cout<<"输入要进行复制操作的姓名"<<endl;cin>>copyname;multimap<string,Phone_contact_per>::iterator itor_head=phone.phone_contact.equal_range(copyname).first,itor_foot=phone.phone_contact.equal_range(copyname).second;Mobile_phone_contacts_per temp;if(!SDcard.look_per_howmuch(itor_head->first)) {if(SDcard.SD_num>max_SDcard_capacity) {cout<<"很遗憾,手机卡容量已满,上限为:"<<max_SDcard_capacity<<endl;return;}temp.name=itor_head->first;temp.phone_number=itor_head->second.phone_number;temp.home_address="由手机转到卡的信息没有记录";temp.qq_number="由手机转到卡的QQ号没有记录";while(itor_head!=itor_foot){SDcard.mobile_phone_contact.insert(pair<string,Mobile_phone_contacts_per>(temp.name,temp));SDcard.SD_num++;phone.phone_contact.erase(itor_head);phone.Phone_num--;itor_head=phone.phone_contact.equal_range(copyname).first,itor_foot=phone.phone_contact.equal_range(copyname).second;}}cout<<"恭喜你,复制成功!"<<endl;
}
void User::copyToSD()
{multimap<string,Phone_contact_per>::iterator itor_head=phone.phone_contact.begin(),itor_foot=phone.phone_contact.end();Mobile_phone_contacts_per temp;if(!SDcard.look_per_howmuch(itor_head->first)) {if(SDcard.SD_num>max_SDcard_capacity) {cout<<"很遗憾,手机卡容量已满,上限为:"<<max_SDcard_capacity<<endl;return;}temp.name=itor_head->first;temp.phone_number=itor_head->second.phone_number;temp.home_address="由手机转到卡的信息没有记录";temp.qq_number="由手机转到卡的QQ号没有记录";SDcard.mobile_phone_contact.insert(pair<string,Mobile_phone_contacts_per>(temp.name,temp));SDcard.SD_num++;}cout<<"恭喜你,全部复制成功!"<<endl;}
void User::copyToSD_one()
{string copyname;int num=0;cin>>copyname;cout<<"系统将显示所有名字叫"<<copyname<<"的人,选择要复制的人是第几个"<<endl;multimap<string,Phone_contact_per>::iterator Phone_itor=phone.phone_contact.equal_range(copyname).first,p=Phone_itor,endit=phone.phone_contact.equal_range(copyname).second;if(!distance(Phone_itor,endit)){cout<<"无记录"<<endl;return;}menu.displaymenu1();for(;Phone_itor!=endit;phone.per_out(Phone_itor),Phone_itor++);cout<<"显示完毕"<<endl;cout<<"你想复制第几个?"<<endl;cin>>num;for(int i=1;i<num;i++,p++);Mobile_phone_contacts_per temp;temp.name=p->second.name;temp.phone_number=p->second.phone_number;temp.home_address="由手机转到卡的信息没有记录";temp.qq_number="由手机转到卡的信息没有记录";SDcard.mobile_phone_contact.insert(pair<string,Mobile_phone_contacts_per>(temp.name,temp));SDcard.SD_num++;cout<<"复制完成"<<endl;
}
void User::copyToPhone_one()
{string copyname;int num=0;cout<<"输入名字"<<endl;cin>>copyname;cout<<"系统将显示所有名字叫"<<copyname<<"的人,选择要复制的人是第几个"<<endl;multimap<string,Mobile_phone_contacts_per>::iterator sdc_itor=SDcard.mobile_phone_contact.equal_range(copyname).first,p=sdc_itor,endit=SDcard.mobile_phone_contact.equal_range(copyname).second;if(!distance(sdc_itor,endit)){cout<<"无记录"<<endl;return;}menu.displaymenu1();for(;sdc_itor!=endit;SDcard.per_out(sdc_itor),sdc_itor++);cout<<"显示完毕"<<endl;cout<<"你想复制第几个?"<<endl;cin>>num;for(int i=1;i<num;i++,p++);Phone_contact_per temp;temp.name=p->second.name;temp.phone_number=p->second.phone_number;phone.phone_contact.insert(pair<string,Phone_contact_per>(temp.name,temp));phone.Phone_num++;cout<<"复制完成"<<endl;
}
void User::moveToPhone()
{multimap<string,Mobile_phone_contacts_per>::iterator itor_head=SDcard.mobile_phone_contact.begin(),itor_foot=SDcard.mobile_phone_contact.end();Phone_contact_per temp;if(!phone.look_per_howmuch(itor_head->first)) {if(phone.Phone_num>max_phone_capacity) {cout<<"很遗憾,手机容量已满,上限为:"<<max_phone_capacity<<endl<<"已经移动的不做改动,手机卡存储的消息不进行删除"<<endl;return;}temp.name=itor_head->first;temp.phone_number=itor_head->second.phone_number;phone.phone_contact.insert(pair<string,Phone_contact_per>(temp.name,temp));phone.Phone_num++;}cout<<"恭喜你,全部移动成功!"<<endl;SDcard.mobile_phone_contact.clear();SDcard.SD_num=0;
}
void User::moveToPhone_per()
{string movename;cin>>movename;multimap<string,Mobile_phone_contacts_per>::iterator itor_head=SDcard.mobile_phone_contact.begin(),itor_foot=SDcard.mobile_phone_contact.end();Phone_contact_per temp;if(!phone.look_per_howmuch(itor_head->first)) {if(phone.Phone_num>max_phone_capacity) {cout<<"很遗憾,手机容量已满,上限为:"<<max_phone_capacity<<endl<<"已经移动的不做改动,手机卡存储的消息不进行删除"<<endl;return;}temp.name=itor_head->first;temp.phone_number=itor_head->second.phone_number;while(itor_head!=itor_foot){phone.phone_contact.insert(pair<string,Phone_contact_per>(temp.name,temp));phone.Phone_num++;SDcard.mobile_phone_contact.erase(itor_head);phone.Phone_num--;itor_head=SDcard.mobile_phone_contact.equal_range(movename).first,itor_foot=SDcard.mobile_phone_contact.equal_range(movename).second;}}cout<<"恭喜你,移动成功!"<<endl;}
void User::moveToSD_per()
{string movename;cout<<"输入要进行移动操作的姓名"<<endl;cin>>movename;multimap<string,Phone_contact_per>::iterator itor_head=phone.phone_contact.equal_range(movename).first,itor_foot=phone.phone_contact.equal_range(movename).second;Mobile_phone_contacts_per temp;if(!SDcard.look_per_howmuch(itor_head->first)) {if(SDcard.SD_num>max_SDcard_capacity) {cout<<"很遗憾,手机卡容量已满,上限为:"<<max_SDcard_capacity<<endl<<"手机存储的消息不进行删除"<<endl;return;}temp.name=itor_head->first;temp.phone_number=itor_head->second.phone_number;temp.home_address="由手机转到卡的信息没有记录";temp.qq_number="由手机转到卡的QQ号没有记录";while(itor_head!=itor_foot){SDcard.mobile_phone_contact.insert(pair<string,Mobile_phone_contacts_per>(temp.name,temp));SDcard.SD_num++;phone.phone_contact.erase(itor_head);phone.Phone_num--;itor_head=phone.phone_contact.equal_range(movename).first,itor_foot=phone.phone_contact.equal_range(movename).second;}}cout<<"恭喜你,移动成功!"<<endl;
}
void User::moveToSD_one()
{string movename;int num=0;cout<<"输入名字"<<endl;cin>>movename;cout<<"系统将显示所有名字叫"<<movename<<"的人,选择要移动的人是第几个"<<endl;multimap<string,Phone_contact_per>::iterator Phone_itor=phone.phone_contact.equal_range(movename).first,p=Phone_itor,endit=phone.phone_contact.equal_range(movename).second;if(!distance(Phone_itor,endit)){cout<<"无记录"<<endl;return;}menu.displaymenu1();for(;Phone_itor!=endit;phone.per_out(Phone_itor),Phone_itor++);cout<<"显示完毕"<<endl;cout<<"你想移动第几个?"<<endl;cin>>num;for(int i=1;i<num;i++,p++);Mobile_phone_contacts_per temp;temp.name=p->second.name;temp.phone_number=p->second.phone_number;temp.home_address="由手机转到卡的信息没有记录";temp.qq_number="由手机转到卡的信息没有记录";SDcard.mobile_phone_contact.insert(pair<string,Mobile_phone_contacts_per>(temp.name,temp));SDcard.SD_num++;phone.phone_contact.erase(p);phone.Phone_num--;cout<<"移动完成"<<endl;
}
void User::moveToPhone_one()
{string movename;int num=0;cout<<"输入名字"<<endl;cin>>movename;cout<<"系统将显示所有名字叫"<<movename<<"的人,选择要移动的人是第几个"<<endl;multimap<string,Mobile_phone_contacts_per>::iterator sdc_itor=SDcard.mobile_phone_contact.equal_range(movename).first,p=sdc_itor,endit=SDcard.mobile_phone_contact.equal_range(movename).second;if(!distance(sdc_itor,endit)){cout<<"无记录"<<endl;return;}menu.displaymenu1();for(;sdc_itor!=endit;SDcard.per_out(sdc_itor),sdc_itor++);cout<<"显示完毕"<<endl;cout<<"你想移动第几个?"<<endl;cin>>num;for(int i=1;i<num;i++,p++);Phone_contact_per temp;temp.name=p->second.name;temp.phone_number=p->second.phone_number;phone.phone_contact.insert(pair<string,Phone_contact_per>(temp.name,temp));phone.Phone_num++;SDcard.mobile_phone_contact.erase(p);SDcard.SD_num--;cout<<"移动完成"<<endl;
}
void User::moveToSD()
{multimap<string,Phone_contact_per>::iterator itor_head=phone.phone_contact.begin(),itor_foot=phone.phone_contact.end();Mobile_phone_contacts_per temp;if(!SDcard.look_per_howmuch(itor_head->first)) {if(SDcard.SD_num>max_SDcard_capacity) {cout<<"很遗憾,手机卡容量已满,上限为:"<<max_SDcard_capacity<<endl<<"已经移动的不做改动,手机存储的消息不进行删除"<<endl;return;}temp.name=itor_head->first;temp.phone_number=itor_head->second.phone_number;temp.home_address="由手机转到卡的信息没有记录";temp.qq_number="由手机转到卡的QQ号没有记录";SDcard.mobile_phone_contact.insert(pair<string,Mobile_phone_contacts_per>(temp.name,temp));SDcard.SD_num++;}cout<<"恭喜你,全部移动成功!"<<endl;phone.phone_contact.clear();phone.Phone_num=0;
}
void User::display()
{while (1){menu.displaymenu();//1是展示手机通讯录,2是展示手机卡通讯录char tem;cin>>tem;if(tem=='1'){multimap<string,Phone_contact_per>::iterator Phone_itor=phone.phone_contact.begin();menu.displaymenu1();if(!distance(phone.phone_contact.begin(),phone.phone_contact.end()))cout<<"    手机中无记录"<<endl;for(;Phone_itor!=phone.phone_contact.end();phone.per_out(Phone_itor),Phone_itor++);multimap<string,Mobile_phone_contacts_per>::iterator SDitor=SDcard.mobile_phone_contact.begin();menu.displaymenu2();for(;SDitor!=SDcard.mobile_phone_contact.end();SDcard.per_out(SDitor),SDitor++);if(!distance(SDcard.mobile_phone_contact.begin(),SDcard.mobile_phone_contact.end()))cout<<"    手机卡中无记录"<<endl;cout<<"    显示完毕"<<endl;return;}else if(tem=='2'){multimap<string,Phone_contact_per>::iterator Phone_itor=phone.phone_contact.begin();if(!distance(phone.phone_contact.begin(),phone.phone_contact.end())){cout<<"无记录"<<endl;return;}menu.displaymenu1();for(;Phone_itor!=phone.phone_contact.end();phone.per_out(Phone_itor),Phone_itor++);cout<<"显示完毕"<<endl;return;}else if(tem=='3'){multimap<string,Mobile_phone_contacts_per>::iterator SDitor=SDcard.mobile_phone_contact.begin();if(!distance(SDcard.mobile_phone_contact.begin(),SDcard.mobile_phone_contact.end())){cout<<"无记录"<<endl;return;}menu.displaymenu2();for(;SDitor!=SDcard.mobile_phone_contact.end();SDcard.per_out(SDitor),SDitor++);cout<<"显示完毕"<<endl;return;}else {while(1){cout<<"选项输入错误,是否重新添加?Y/N(不区分大小写)"<<endl;cin>>tem;if(tem=='Y'||tem=='y') break;else if(tem=='N'||tem=='n') return;cout<<"请回答正确选项!";}}}
}
void User::display_local(){cout<<"是否显示成功读入的联系人信息?\n输入Y/y显示,任意键跳过"<<endl;char s;cin>>s;if(s=='Y'||s=='y'){multimap<string,Phone_contact_per>::iterator Phone_itor=phone.phone_contact.begin();menu.displaymenu1();if(!distance(phone.phone_contact.begin(),phone.phone_contact.end()))cout<<"    手机中的本地记录没有信息"<<endl;for(;Phone_itor!=phone.phone_contact.end();phone.per_out(Phone_itor),Phone_itor++);multimap<string,Mobile_phone_contacts_per>::iterator SDitor=SDcard.mobile_phone_contact.begin();menu.displaymenu2();for(;SDitor!=SDcard.mobile_phone_contact.end();SDcard.per_out(SDitor),SDitor++);if(!distance(SDcard.mobile_phone_contact.begin(),SDcard.mobile_phone_contact.end()))cout<<"    手机中的本地卡记录没有信息"<<endl;cout<<"    显示完毕"<<endl;}else{system("cls");return;}cout<<"任意输入结束显示"<<endl;cin>>s;system("cls");return;}
void User::modifymax()
{char temp;menu.menumodifymax();cin>>temp;if(temp=='1'){cout<<"重新输入最大手机容量"<<endl;cin>>max_phone_capacity;cout<<"修改成功"<<endl;}else if(temp=='2'){cout<<"重新输入最大手机卡容量"<<endl;cin>>max_SDcard_capacity;cout<<"修改成功"<<endl;}else if(temp=='3'){cout<<"重新输入最大手机和手机卡容量"<<endl;cin>>max_phone_capacity>>max_SDcard_capacity;cout<<"修改成功"<<endl;}else cout<<"不执行任何操作"<<endl;}

两个平行交互层(与前三层进行关联)

(1)menu.h目录层(因为word格式限制,实际目录显示以实物为准)

#ifndef menu_h
#define menu_h
/*这部分是菜单类
*/
#include"contact_per.h"
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<windows.h>
using namespace std;
char return_choice;
char answer;
class Menu{
public:  void description();  //程序启动界面void mainmenu();     //主菜单void addmenu();      //添加人员菜单void remove1menu();  //删除人员菜单void changemenu();   //修改人员菜单void displaymenu();  //浏览人员菜单void lookmenu();     //查询人员菜单void displaymenu1(); //查询人员选项菜单void displaymenu2(); //查询人员选项菜单void Phone_contact_per_modify();         //修改手机信息菜单void Mobile_phone_contacts_per_modify(); //修改手机卡信息菜单void modify();      //修改信息主菜单void copy();        //复制信息主菜单void move();        //移动信息主菜单void user_return(); //返回操作菜单void sd_read_success();//以下都是读写提示void sd_read_fail();void sd_write_success();void sd_write_fail();void phone_read_success();void phone_read_fail();void phone_write_success();void phone_write_fail();void menumodifymax();//修改最大容量菜单
}menu;
void Menu::description()
{system("color F1");cout<<"\a****************************************************************"<<endl  <<"*                通讯录管理系统  v12.5                         *"<<endl  <<"*                                         作者于衡             *"<<endl<<"****************************************************************"<<endl<<"◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇"<<endl<<"◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇"<<endl<<"◇◇◇···◇◇◇···◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇"<<endl<<"◇◇◇◇··◇◇◇··◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇"<<endl<<"◇◇◇◇···◇···◇◇◇◇◇◇◇◇◇·◇◇◇◇·◇◇◇◇◇◇"<<endl<<"◇◇◇◇◇·····◇◇◇◇◇◇◇◇◇◇·◇◇◇◇·◇◇◇◇◇◇"<<endl<<"◇◇◇◇◇◇····◇◇◇◇◇◇◇◇◇◇·◇◇◇◇·◇◇◇◇◇◇"<<endl<<"◇◇◇◇◇◇···◇◇◇◇◇◇◇◇◇◇◇·◇◇◇◇·◇◇◇◇◇◇"<<endl<<"◇◇◇◇◇◇◇··◇◇◇◇◇◇◇◇◇◇◇·◇◇◇··◇◇◇◇◇◇"<<endl<<"◇◇◇◇◇◇◇··◇◇◇◇◇◇◇◇◇◇◇··◇···◇◇◇◇◇◇"<<endl<<"◇◇◇◇◇◇◇··◇◇◇◇◇◇◇◇◇◇◇······◇◇◇◇◇◇"<<endl<<"◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇"<<endl<<"◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇"<<endl<<"◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇"<<endl<<"◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇"<<endl;Sleep(1000);system("cls");
}
void Menu::mainmenu()
{  system("cls");cout<<"*****************************************************************"<<endl  <<"*                       通讯录管理系统  v12.5                   *"<<endl  <<"*                           主菜单                              *"<<endl   <<"*****************************************************************"<<endl   <<"*                    请输入数字选择相应的操作                   *"<<endl   <<"*---------------------------------------------------------------*"<<endl   <<"*                                                               *"<<endl   <<"*           0.       退出系统并保存文件.                        *"<<endl   <<"*           1.       添加联系人.                                *"<<endl   <<"*           2.       删除一个或者多个联系人.                    *"<<endl   <<"*           3.       修改联系人的信息.                          *"<<endl   <<"*           4.       查询联系人信息.                            *"<<endl   <<"*           5.       浏览所有联系人的信息.                      *"<<endl   <<"*           6.       对联系人信息进行复制.                      *"<<endl   <<"*           7.       对联系人信息进行移动.                      *"<<endl<<"*           8.       修改默认存储容量.(初始为手机200,卡2000)   *"<<endl<<"*       注意:                                                  *"<<endl  <<"*         $通讯录文件会在回到主菜单的时候自动保存               *"<<endl  <<"*         $请不要乱输入空格                                     *"<<endl   <<"*****************************************************************"<<endl;  cout<<"请输入你的选择:"<<endl<<"--->";
}
void Menu::addmenu()
{  cout<<"*****************************************************************"<<endl  <<"*             请选择增加联系人到哪个通讯录:                    *"<<endl  <<"*                    1.手机通讯录.                              *"<<endl  <<"*                    2.手机卡通讯录.                            *"<<endl  <<"*****************************************************************"<<endl;  cout<<"请输入你的选择:"<<endl<<"--->";
}
void Menu::remove1menu()
{  cout<<"*****************************************************************"<<endl   <<"*---------------------------------------------------------------*"<<endl   <<"*           请选择在哪个通讯录删除联系人:                      *"<<endl   <<"*             1.手机通讯录   (删除名字下的全部记录).            *"<<endl   <<"*             2.手机卡通讯录.(删除名字下的全部记录).            *"<<endl   <<"*             3.手机通讯录.  (删除名字下的某条记录).            *"<<endl   <<"*             4.手机卡通讯录.(删除名字下的某条记录).            *"<<endl<<"*             5.两个通讯录都进行名字清空(抹消该名字的全部记录)*"<<endl<<"*             6.清空手机卡通讯录.                               *"<<endl<<"*             7.清空手机通讯录                                  *"<<endl<<"*             8.清除所有记录                                    *"<<endl<<"*****************************************************************"<<endl;  cout<<"请输入你的选择:"<<endl<<"--->"<<endl;
}
void Menu::copy()
{  cout<<"*****************************************************************"<<endl  <<"*           请选择复制模式?                                    *"<<endl  <<"*             1.将一个人从手机复制到卡.                         *"<<endl  <<"*             2.将一个人从卡复制到手机.                         *"<<endl  <<"*             3.将同个人名的所有记录从手机复制到卡.             *"<<endl  <<"*             4.将同个人名的某条记录从卡复制到手机.             *"<<endl <<"*             5.将手机中的全部信息复制到卡.                     *"<<endl  <<"*             6.将卡中所有信息复制到手机.                       *"<<endl  <<"*           选项外按键返回.                                     *"<<endl  <<"*****************************************************************"<<endl;  cout<<"请输入你的选择:"<<endl<<"--->";
}
void Menu::move()
{  cout<<"*****************************************************************"<<endl  <<"*           请选择移动模式?                                    *"<<endl  <<"*             1.将一个人从手机移动到卡.                         *"<<endl  <<"*             2.将一个人从卡移动到手机.                         *"<<endl  <<"*             3.将同个人名的所有记录从手机移动到卡.             *"<<endl  <<"*             4.将同个人名的某条记录从卡移动到手机.             *"<<endl <<"*             5.将手机中的全部信息移动到卡.                     *"<<endl  <<"*             6.将卡中所有信息移动到手机.                       *"<<endl  <<"*           选项外按键返回.                                     *"<<endl  <<"*****************************************************************"<<endl;  cout<<"请输入你的选择:"<<endl<<"--->";
}
void Menu::changemenu()
{  cout<<"*****************************************************************"<<endl  <<"*         请选择在哪个通讯录中修改联系人:                      *"<<endl  <<"*             1.手机通讯录.                                     *"<<endl  <<"*             2.手机卡通讯录.                                   *"<<endl  <<"*           选项外按键返回.                                     *"<<endl  <<"*****************************************************************"<<endl;  cout<<"请输入你的选择:"<<endl<<"--->";
}
void Menu::lookmenu()
{  cout<<"*****************************************************************"<<endl  <<"*         请选择在哪个通讯录中查询:                            *"<<endl  <<"*             1.手机通讯录.                                     *"<<endl  <<"*             2.手机卡通讯录.                                   *"<<endl<<"*           选项外按键返回.                                     *"<<endl<<"*****************************************************************"<<endl;  cout<<"请输入你的选择:"<<endl<<"--->";
}
void Menu::displaymenu()
{  cout<<"******************************************************************"<<endl  <<"*         请选择展示哪个通讯录                                  *"<<endl  <<"*             1.全部展示.                                       *"<<endl  <<"*             2.手机通讯录.                                     *"<<endl<<"*             3.手机卡通讯录.                                   *"<<endl<<"*           选项外按键返回.                                     *"<<endl<<"*****************************************************************"<<endl;  cout<<"请输入你的选择:"<<endl<<"--->";
}
void Menu::displaymenu1()
{  cout<<"*****************************************************************"<<endl <<"*                         手机通讯录                            *"<<endl <<"*****************************************************************"<<endl;
}
void Menu::displaymenu2()
{  cout<<"*****************************************************************"<<endl <<"*                         手机卡通讯录                          *"<<endl <<"*****************************************************************"<<endl;
}
void Menu::modify(){cout<<"*****************************************************************"<<endl<<"*                你想要修改什么信息?                           *"<<endl<<"*                       1.姓名.                                 *"<<endl<<"*                       2.电话号码.                             *"<<endl<<"*                       3.返回.                                 *"<<endl<<"*****************************************************************"<<endl;cout<<"请输入你的选择:"<<endl<<"--->";   }
void Menu::menumodifymax(){cout<<"*****************************************************************"<<endl<<"*                你想修改手机还是卡的最大容量? (慎重改动)    *"<<endl<<"*                       1.手机                                  *"<<endl<<"*                       2.卡                                    *"<<endl<<"*                       3.全部                                  *"<<endl<<"*****************************************************************"<<endl;cout<<"请输入你的选择:"<<endl<<"--->"; }
void Menu::Phone_contact_per_modify(){cout<<"*****************************************************************"<<endl<<"*                     你想修改哪部分信息?                      *"<<endl<<"*                       1.姓名.                                 *"<<endl<<"*                       2.电话号码.                             *"<<endl<<"*                       3.全部.                                 *"<<endl<<"*                       4.返回.                                 *"<<endl<<"*****************************************************************"<<endl;cout<<"请输入你的选择:"<<endl<<"--->";   }
void Menu::Mobile_phone_contacts_per_modify(){cout<<"*****************************************************************"<<endl<<"*                    你想修改哪部分信息?                       *"<<endl<<"*                     1.姓名.                                   *"<<endl<<"*                     2.电话号码.                               *"<<endl<<"*                     3.地址.                                   *"<<endl<<"*                     4.QQ号                                    *"<<endl<<"*                     5.全部.                                   *"<<endl<<"*                     6.返回.                                   *"<<endl<<"*****************************************************************"<<endl;cout<<"请输入你的选择:"<<endl<<"--->";  }
void Menu::user_return(){cout<<"*****************************************************************"<<endl  <<"*          操作已经完成,请选择接下来的操作                     *"<<endl  <<"*                    1.返回主菜单                               *"<<endl  <<"*                    2.返回上一级                               *"<<endl  <<"*                    3.退出系统并保存所有数据                   *"<<endl  <<"*****************************************************************"<<endl;  }
void Menu::sd_read_success(){cout<<"*****************************************************************"<<endl  <<"*                     本地手机卡通讯录同步成功                  *"<<endl  <<"*****************************************************************"<<endl; }
void Menu::sd_read_fail(){cout<<"*****************************************************************"<<endl  <<"*                Warning:本地手机卡通讯录同步失败              *"<<endl  <<"*****************************************************************"<<endl; }
void Menu::sd_write_success(){cout<<"*****************************************************************"<<endl  <<"*                     本地手机卡通讯录保存成功                  *"<<endl  <<"*****************************************************************"<<endl; }
void Menu::sd_write_fail(){cout<<"*****************************************************************"<<endl  <<"*                Warning:本地手机卡通讯录保存失败              *"<<endl  <<"*****************************************************************"<<endl; }
void Menu::phone_read_success(){cout<<"*****************************************************************"<<endl  <<"*                     本地手机通讯录同步成功                    *"<<endl  <<"*****************************************************************"<<endl; }
void Menu::phone_read_fail(){cout<<"*****************************************************************"<<endl  <<"*                Warning:本地手机通讯录同步失败                *"<<endl  <<"*****************************************************************"<<endl; }
void Menu::phone_write_success(){cout<<"*****************************************************************"<<endl  <<"*                     本地手机通讯录保存成功                    *"<<endl  <<"*****************************************************************"<<endl; }
void Menu::phone_write_fail(){cout<<"*****************************************************************"<<endl  <<"*                Warning:本地手机通讯录保存失败                *"<<endl  <<"*****************************************************************"<<endl; }#endif 

(2)主源代码.cpp接口层

#include"contact_per.h"
#include"menu.h"
#include"oper.h"
#include"database.h"
int main()
{menu.description();User yuheng;char choosee;mainmenu://返回主菜单yuheng.menu.mainmenu();mainmenu1:while(true){cin>>choosee;while(true)//返回上一级{lastmenu:switch (choosee){case '0':return 0;case '1':yuheng.add();menu.user_return();cin>>return_choice;switch(return_choice){case'1':yuheng.store();goto mainmenu;//返回主菜单case'2':goto lastmenu;//返回上一级菜单case'3':return 0;//退出程序default:{cout<<"输入错误,返回主菜单"<<endl;goto mainmenu;}}break;case '2':yuheng.del();menu.user_return();cin>>return_choice;switch(return_choice){case'1':yuheng.store();goto mainmenu;//返回主菜单case'2':goto lastmenu;//返回上一级菜单case'3':return 0;//退出程序default:{cout<<"输入错误,返回主菜单"<<endl;goto mainmenu;}}break;case '3':yuheng.modify();menu.user_return();cin>>return_choice;switch(return_choice){case'1':yuheng.store();goto mainmenu;//返回主菜单case'2':goto lastmenu;//返回上一级菜单case'3':return 0;//退出程序default:{cout<<"输入错误,返回主菜单"<<endl;goto mainmenu;}}break;case '4':yuheng.look();menu.user_return();cin>>return_choice;switch(return_choice){case'1':yuheng.store();goto mainmenu;//返回主菜单case'2':goto lastmenu;//返回上一级菜单case'3':return 0;//退出程序default:{cout<<"输入错误,返回主菜单"<<endl;goto mainmenu;}}break;case '5':yuheng.display();menu.user_return();cin>>return_choice;switch(return_choice){case'1':yuheng.store();goto mainmenu;//返回主菜单case'2':goto lastmenu;//返回上一级菜单case'3':return 0;//退出程序default:{cout<<"输入错误,返回主菜单"<<endl;goto mainmenu;}}break;case '6':menu.copy();cin>>answer;switch(answer){case'1':yuheng.copyToSD_one();break;case'2':yuheng.copyToPhone_one();break;case'3':yuheng.copyToSD_one();break;case'4':yuheng.copyToPhone_one();break;case'5':yuheng.copyToSD();break;case'6':yuheng.copyToPhone();break;default:{cout<<"输入错误,返回主菜单"<<endl;goto mainmenu;}}menu.user_return();cin>>return_choice;switch(return_choice){case'1':yuheng.store();goto mainmenu;//返回主菜单case'2':goto lastmenu;//返回上一级菜单case'3':return 0;//退出程序default:{cout<<"输入错误,返回主菜单"<<endl;goto mainmenu;}}break;case '7':menu.move();cin>>answer;switch(answer){case'1':yuheng.moveToSD_one();break;case'2':yuheng.moveToPhone_one();break;case'3':yuheng.moveToSD_per();break;case'4':yuheng.moveToPhone_per();break;case'5':yuheng.moveToSD();break;case'6':yuheng.moveToPhone();break;default:{cout<<"输入错误,返回主菜单"<<endl;goto mainmenu;}}menu.user_return();cin>>return_choice;switch(return_choice){case'1':yuheng.store();goto mainmenu;//返回主菜单case'2':goto lastmenu;//返回上一级菜单case'3':return 0;//退出程序default:{cout<<"输入错误,返回主菜单"<<endl;goto mainmenu;}}break;case '8':{yuheng.modifymax();menu.user_return();cin>>return_choice;switch(return_choice){case'1':yuheng.store();goto mainmenu;//返回主菜单case'2':goto lastmenu;//返回上一级菜单case'3':return 0;//退出程序default:{cout<<"输入错误,返回主菜单"<<endl;goto mainmenu;}}break;}default:{cout<<"输入错误,请重新输入"<<endl;goto mainmenu1;}}}}return 0;
}

参考文献

“C ++ STL标准模板库”

“计算机网络”

C++课程设计 STL通讯录管理系统相关推荐

  1. 通讯录管理系统C语言课程设计大作业,c语言课程设计报告---通讯录管理系统.doc...

    c语言课程设计报告---通讯录管理系统.doc Yangtze University College of Arts and Science 学生实习手册 (课程设计报告) 学 部 理 工 学 部 专 ...

  2. java课设通讯录制作,JAVA课程设计--个人通讯录管理系统

    JAVA课程设计--个人通讯录管理系统 JAVAJAVA 课程设计课程设计 课题个人通讯录管理系统课题个人通讯录管理系统 课程名称 java 课程设计 院 系 计算机科学与技术学院 班 级 09 计本 ...

  3. C++课程设计之通讯录管理系统

    Hello!亲爱的小伙伴们大家好啊,今天给大家带来的是C++课程设计之通讯录管理系统. 我们进行课程设计的主要目的是为了对C++的基础进行复习,为后续深入学习其他知识打好基础. 话不多说,咱们上代码: ...

  4. C++课程设计报告--通讯录管理系统

    这是大一C++课程结业的课程设计,当时写了5天的代码,但也是很爽的过程.因为不好排版主要是个人比较懒,所以比较乱. 题目分析 建立两个文本文件,记录存储在手机上联系人的基本信息和存储在手机卡上的联系人 ...

  5. 课程设计:通讯录管理系统

    课程设计能很好的检验个人程序基础知识掌握程度.某种程度上来说,这一个课程设计也算入门级的小项目了,今天简单总结一下自己在面对课设时的思路. 一.设计要求 本次课程设计的主题是通讯录管理系统.其目的是通 ...

  6. 数据库课程设计之通讯录管理系统之目录

    通讯录管理系统 目录 需求分析 . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1结构化系统分析 . . . . . . . . . . . . ...

  7. C/C++课程设计:通讯录管理系统(含课程设计报告书,支持答辩)

    目录 引言 一.总览 二.核心代码 结构体定义 快排 文件读写处理 三.运行截图 程序初始化.交互界面 添加功能 显示功能 查找功能 修改功能 删除功能 四.课程设计报告书 温馨提示 引言 本课程设计 ...

  8. java通讯录课程设计_Java通讯录管理系统(课程设计)

    Java通讯录管理系统 作者: 李思萌 日期: 2012-11-17 1.创建数据库DB_Address 脚本: create database DB|_|Address 2.数据表脚本tb_Addr ...

  9. 【课程设计】通讯录管理系统(源码 + 详解)

最新文章

  1. LeetCode Add Digits(计算数位的和)
  2. gRPC in ASP.NET Core 3.x - gRPC 简介(2)
  3. VDI序曲二 RemotoAPP部署
  4. getresourceasstream方法_【设计模式】第三篇:一篇搞定工厂模式【简单工厂、工厂方法模式、抽象工厂模式】...
  5. Java调用WeChat's API总结
  6. c# redis 如何设置过期时间_Spring cache整合Redis,并给它一个过期时间!
  7. Capture One Pro 22 for Mac(RAW图像处理软件)v15.1.2.1
  8. 为什么使用多态?实现多态的有哪些方式?
  9. LwIP协议栈源码详解—TCP定时器
  10. 计算机常见故障英语,常见电脑黑屏(有英文字母)的解决办法
  11. 高斯光束的简单matlab仿真
  12. Silvaco TCAD介绍
  13. win10计算机休眠快捷键,win10电脑休眠快捷键是什么_window10电脑睡眠快捷键怎么按-win7之家...
  14. 操作系统的目标与作用
  15. mkv格式用什么播放器打开?视频转换器怎样操作
  16. Linux中将多块新硬盘合并成一个,挂载到/data目录下
  17. 最新常用数据库排名及分类介绍
  18. 前端获取当前服务器时间,不使用客户端电脑时间
  19. revit里的BIM模型转fbx真的可以带纹理材质吗?
  20. opencv实现视频实时去雾算法

热门文章

  1. drf快速入门01---REST规范介绍序列化器的基础使用
  2. CSS去掉链接下划线的方法
  3. [Git Rebase] Git Rebase 合并提交(命令操作 SourceTree 操作)
  4. springboot解决循环依赖问题
  5. 网络爬虫框架——Scrapy框架解析
  6. Python super细节整理
  7. 手机掉水里的终极解决方案!
  8. Silverlight传值
  9. LED屏显示驱动简述与类型
  10. 某型无人机群的监视覆盖任务航路规划