栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

通讯录管理系统-C++课程设计(试错版)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通讯录管理系统-C++课程设计(试错版)

目录

项目要求:

首先:建立手机联系人头文件

 手机卡联系人源文件.cpp文件:

 建立手机联系人头文件-Phone_Contacts.h:

 建立 手机联系人源文件-Phone_Contacts.cpp文件:

address_book抽象类:

派生类card_address_book,card_address_book:public address_book

派生类 phone_adddress_book

源文件

用户类user头文件

源文件user

菜单类显示各种操作界面头文件:

菜单类显示各种操作界面源文件:

 // 通讯录管理系统主函数菜单实现区:


 

项目要求:

通讯录管理系统

手机通讯录中的联系人的信息既可以存储在手机中,也可以存储在手机卡中,也可以同时存储在两个位置上(每个位置上的存储容量为1000,即手机卡中或手机上最多只能存储1000个联系人)。存储在手机卡的联系人的信息只包含用户名和电话号码两项信息。存储在手机上的联系人的信息除了上面提到的两项信息外,还包含籍贯,QQ号等信息。

根据通用的手机通讯录的使用方式,采用OOP(Object Oriented Programming,面向对象编程)方法编写一个手机通讯录管理。

要求:

  1. 创建文本文件,记录联系人的信息(需要创建两个文本文件,分别存储手机和手机卡上的存储的联系人的信息)。
  2. 以菜单方式工作(字符界面即可)
  3. 存储在手机卡上的联系人的信息包括:姓名和电话号码;存储在手机上的联系人的信息包括姓名,籍贯,电话号码,QQ号等信息
  4. 管理系统的功能包括:
    1. 新建联系人:添加新的联系人(添加时确定是添加到手机上还是手机卡中)
    2. 删除:删除一个联系人(输入电话号码,删除该联系人。说明,如果两个存储位置上都存在该联系人的话,需要在两个存储位置上都要进行删除操作)
    3. 修改:修改某个联系人的信息(输入电话号码,查询到联系人之后进行信息的修改。说明,如果两个存储位置上都存在该联系人的话,需要在两个存储位置上都要进行修改操作)
    4. 查询:根据名字查询联系人信息(查询结果不唯一)
    5. 浏览:显示所有联系人的信息
    6. 将联系人的信息从手机转存到手机卡上(同时要避免重复数据的存在。并且在转存是要检查容量是否受限。下同。)
    7. 将联系人的信息从手机卡上转存到手机上(同时要避免重复数据的存在)
  5. 要支持继承、多态、重载(运算符重载、函数重载)等面向对象的基本特点。
首先:建立手机联系人头文件

//Card_Contacts.h

#pragma once

//定义手机卡联系人类Card_Cntacts,作为手机联系人类的基类.

#ifndef CARD_CONTACTS_H
#define CARD_CONTACTS_H
#include
#include
#include
using namespace std;

class Card_Contacts
{
protected:
	string name;//姓名
	string tel;//电话号码
public:
	Card_Contacts(string pname = "no name", string ptel = "no tel");//带参并带默认值的构造函数
	void set(string pname = "no name", string ptel = "no tel");//一组set函数为数据成员赋值
	void modify();//一组modify函数,修改数据成员的值
	string getname()const;//定义getname()函数, get 姓名.
	string gettel()const;//定义gettel()函数, get 号码.
	friend ostream& operator<<(ostream& output, Card_Contacts& obj_a);//重载<<运算符,完成对象的输出
	friend istream& operator>>(istream& input, Card_Contacts& obj_b);//重载>>运算符,完成对象的输入
};
#endif // !CARD_CONTACTS_H

 手机卡联系人源文件.cpp文件:

//Card_Contacts.cpp

#include"Card_Contacts.h"
Card_Contacts::Card_Contacts(string pname, string ptel)
{
	name = pname;
	tel = ptel;
}
inline  void Card_Contacts::set(string pname , string ptel)
{
	name = pname;
	tel = ptel;
}
void  Card_Contacts::modify()   //modify函数,修改数据成员的值
{
	string pname;
	string ptel;
	int number;
	cout << "请输入·你的选择:1-修改姓名;2-修改手机号码;3-修改姓名和手机号码;" << endl;
	cin >> number;
	switch (number)
	{
	case 1:
		cout << "请重新输入姓名:";
		cin >> pname;
		name = pname;
		cout << endl;
		break;
	case 2:
		cout << "请重新输入手机号码:";
		cin >> ptel;
		tel = ptel;
		cout << endl;
		break;
	case 3:
		cout << "请重新输入·姓名和手机号码:";
		cin >> pname >> ptel;
		pname = name;
		tel = ptel;
		cout << endl;
	default:
		cout << "输入错误!请重操作!" << endl;
	}
}
string  Card_Contacts::getname()const
{
	return name;
}
string  Card_Contacts::gettel()const
{
	return tel;
}
ostream& operator<<(ostream& output,const Card_Contacts &obj_a)//加了const,get和set函数必须永const修饰,否则会出错
{
	output << "姓名:";
	output.width(15);
	output.setf(ios::left);
	output << obj_a.getname();
	output << "电话号码:" << obj_a.gettel() << endl;
	return output;
}
istream& operator>>(istream& input, Card_Contacts &obj_b)
{
	string pname;
	string ptel;
	cout << "请输入该联系人名字:";
	input >> pname;
	cout << "请输入该联系人的电话号码:";
	input >> ptel;
	obj_b.set(pname,ptel);
	return input;
}
 建立手机联系人头文件-Phone_Contacts.h:

//Phone_Contacts.h

#pragma once

//建立手机联系人类-Phone_Contacts,公有继承手机卡类-Card_Contacts,

#ifndef PHONE_CONTACTS_H
#define PHONE_CONTACTS_H
#include"Card_Contacts.h"

class Phone_Contacts
{
protected:
	string address;//籍贯
	string qq;//QQ号
public:
	Phone_Contacts(string pname = "no name", string ptel = "no tel",string paddress="no address",string pqq="no qq");
	void set(string pname = "no name", string ptel = "no tel", string paddress = "no address", string pqq = "no qq");//一组set函数为数据成员赋值
	void modify();//一组modify函数,修改数据成员的值
	string getaddress()const;
	string getqq()const;
	friend ostream& operator<<(ostream &output,const Phone_Contacts &obj_c);//重载<<运算符,完成数据成员的输出.
	friend istream& operator>>(istream& input, Phone_Contacts &obj_d);//重载>>运算符,完成数据成员的输入.
};
#endif // !PHONE_CONTACTS_H
 建立 手机联系人源文件-Phone_Contacts.cpp文件:

//Phone_Contacts.cpp

#include"Phone_Contacts.h"

//派生类必须有构造函数-初始化列表来初始化基类数据成员

Phone_Contacts::Phone_Contacts(string pname,string ptel,string paddress,string pqq) :Card_Contacts(pname, ptel)
{
	address = paddress;
	qq = pqq;
}
inline void Phone_Contacts::set(string pname, string ptel, string paddress, string pqq)
{
	Card_Contacts::set(pname, ptel);
	address = paddress;
	qq = pqq;
}
void Phone_Contacts::modify()
{

	string pname;
	string ptel;
	string paddress;
	string pqq;
	int number;
	cout << "请输入·你的选择:1-修改姓名;2-修改手机号码;3-修改籍贯;4-修改QQ号;5-全改." << endl;
	cin >> number;
	switch (number)
	{
	case 1:
		cout << "请重新输入姓名:";
		cin >> pname;
		name = pname;
		cout << endl;
		break;
	case 2:
		cout << "请重新输入手机号码:";
		cin >> ptel;
		tel = ptel;
		cout << endl;
		break;
	case 3:
		cout << "请重新输入籍贯:";
		cin >> paddress;
		address = paddress;
		break;
	case 4:
		cout << "请重新输入QQ号:";
		cin >> pqq;
		qq = pqq;
		break;
	case 5:
		cout << "请重新输入·姓名:";
		cin >> pname ;
		pname = name;
		cout << "请重新输入·手机号码:";
		cin >> ptel;
		tel = ptel;
		cout << "请重新输入·籍贯:";
		cin >> paddress;
		address = paddress;
		cout << "请重新输入·QQ号:";
		cin >> pqq;
		qq = pqq;
		cout << endl;
		break;
	default:
		cout << "输入错误!请重操作!" << endl;
	}
}
inline string Phone_Contacts::getaddress()const
{
	return address;
}
inline string Phone_Contacts::getqq()const
{
	return qq;
}
ostream& operator<<(ostream& output, const Phone_Contacts& obj_c)
{
	output << "姓名:";
	output.width(11);
	output.setf(ios::left);
	output << obj_c.getname();
	output << "手机号码:";
	output.width(12);
	output << obj_c.gettel();
	output << "籍贯:";
	output.width(12);
	output << obj_c.getaddress();
	output << "QQ号:";
	output << obj_c.getqq();
	return output;
}
istream& operator>>(istream& input, Phone_Contacts& obj_d)
{
	string pname;
	string ptel;
	string paddress;
	string pqq;
	cout << "请输入该联系人名字:";
	input >> pname;
	cout << "请输入该联系人的电话号码:";
	input >> ptel;
	cout << "请输入该联系人的籍贯:";
	input >> paddress;
	cout << "请输入该联系人的QQ号:";
	cin >> pqq;
	obj_d.set(pname,ptel,paddress,pqq);
	return input;
}
address_book抽象类:
#pragma once

//定义一个通讯簿抽象类


#ifndef ADDRESS_BOOK_H
#define ADDRESS_BOOOK_H

#include
#include
#include
#include
#include
using namespace std;
class address_book
{
public:
	address_book() { }
	 //增加函数:增加一个联系人
	virtual void add()const = 0;

	//删除操作:删除一个联系人(输入电话号码,删除该联系人.)
	virtual void remove_tel(string ptel)const=0;

	//Display:显示所有联系人的信息
	virtual void display()const = 0;

	//修改某一联系人的信息(输入电话号码,查询到联系人之后进行信息的修改。)
	virtual void change_tel(string ptel)const = 0;

	//查询并显示某一联系人的信息(根据名字查询联系人信息)
	virtual void query_name(string pname)const = 0;

	~address_book() { }
};
#endif // !ADDRESS_BOOK_H
派生类card_address_book,card_address_book:public address_book
#pragma once

#ifndef CARD_ADDRESS_BOOK_H
#define CARD_ADDRESS_BOOK_H

#include
#include
#include"Address_Book.h"
#include"Phone_Contacts.h"

class card_address_book:public address_book
{
//protected:
//    int num; //手机联系人的数量
//    card_address_book *cb[1000];//手机联系人对象数组
public:
    //构造函数:读取文本文件中的数据,并根据文件内容创建联系人对象数组
    card_address_book();

    //析构函数:将对象数组中的内容写入到文本文件中。
    ~card_address_book();

    //增加函数:增加一个联系人
    void add()const;

    //删除操作:删除一个联系人
    void remove_tel(string ptel)const;

    //Display:显示所有联系人的信息
    void display()const;

    //修改某一联系人的信息:
    void modify(string ptel)const;

    //查询并显示某一联系人的信息:
    void query(string pname)const;

    //string getname(int i);

    //string gettel(int i);

    //清空通讯录
    //void clean_card_book();
};
#endif // !CARD_ADDRESS_BOOK_H
派生类 phone_adddress_book
#pragma once


#ifndef PHONE_ADDRESS_BOOK_H
#define PHONE_ADDRESS_BOOK_H

#include"Address_Book.h"
#include
#include
#include
#include
#include
#include

class phone_adddress_book:public address_book
{

//protected:
//    int num;//手机联系人的数量
//    phone_adddress_book *phBook[1000];//手机联系人对象数组
public:
    //构造函数:读取文本文件中的数据,并根据文件内容创建联系人对象数组
    phone_adddress_book();

    //析构函数:将对象数组中的内容写入到文本文件中。
    ~phone_adddress_book();

    //增加函数:增加一个联系人
    void add()const;

    //删除操作:删除一个联系人
    void remove_tel(string ptel)const;

    //Display:显示所有联系人的信息
    void display()const;

    //修改某一联系人的信息
    void change_tel(string ptel)const;

    //查询并显示某一联系人的信息
    void query_name(string pname)const;

    //返回下标为i的联系人姓名
    string getname(int i);

    //返回下标为i的联系人的手机号码
    string gettel(int i);

    //清空  Phone_Adddress_Book通讯录
    void clean_phone_book()const;

};
#endif // !PHONE_ADDRESS_BOOK_H
源文件
#include"Card_Address_Book.h"
#include
#include
#include
#include
#include

//const char* mycardbookfile = "手机卡通讯录.txt";//系统默认在这个文件中读写
card_address_book::card_address_book()
{
	cout << "***********************¥¥¥¥¥¥¥¥¥¥¥¥*****************" << endl;
	cout << "********************     欢迎来到手机卡通讯簿    **************" << endl;
	cout << "***********************¥¥¥¥¥¥¥¥¥¥¥¥****************" << endl;
}
card_address_book::~card_address_book()
{
	cout << "*********************************************************" << endl;
	cout << "*****************     成功离开手机通讯簿     **************" << endl;
	cout << "*********************************************************" << endl;
}

//增加函数:增加一个联系人
void card_address_book::add()const
{
	int num;
	string a[1000][2];
	fstream infile("手机卡通讯录.txt", ios::in);
	if (!infile)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	for (int i = 0; i <= 1000; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			infile >> a[i][j];
		}
		num = i;
		if (a[i][0] == "")
		{
			break;
		}
	}
	cout << "现在已经有:" << num << "个联系人" << endl;
	if (num < 1000)
	{
		Card_Contacts A;
		cin>>A;
		cout << "你刚才输入的信息为:" << endl;
		cout << A;
		fstream infile("手机卡通讯录.txt", ios::app | ios::out);
		if (!infile)
		{
			cout << "File could not open!" << endl;
			abort();
		}
		infile << "姓名:" << A.getname() << endl;
		infile << "电话号码:" << A.gettel() << endl;
		infile.close();
	}
	else if (num >= 1000)
	{
		cout << "手机卡容量已满,无法添加!请清理空间!" << endl;
	}
}

//删除操作:删除一个联系人
void card_address_book::remove_tel(string ptel)const
{
	string a[1000][2], ttel, tel_s;
	int num;
	cout << "请输入你要删除的联系人的电话号码:";
	cin >> ttel;
	tel_s = "电话号码:" + ttel;
	fstream infile("手机卡通讯录.txt", ios::in);
	if (!infile)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	for (int i = 0; i < 1000; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			infile >> a[i][j];
		}
		num = i;
		if (a[i][0] == "")
		{
			break;
		}
	}
	infile.close();
	fstream infile2("手机卡通讯录.txt", ios::in);
	if (!infile2)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	for (int i = 0; i <= num; 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();
}

//修改某一联系人的信息:
void card_address_book::modify(string ptel)const
{
	string a[1000][2]; string p_tel; string tel_s;
	int num;
	cout << "输入你要修改的联系人电话号码:";
	cin >> p_tel;
	tel_s = "电话号码" + p_tel;
	fstream infile("手机卡通讯录.txt", ios::in);
	if (!infile)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	for (int i = 0; i <= 1000; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			infile >> a[i][j];
		}
		num = i;
		if (a[i][0] == "")
		{
			break;
		}
	}
	infile.close();
	for (int i = 0; i <= num; i++)
	{
		if (tel_s == a[i][1])
		{
			string name, tel;
			cout << "请输入你要修改的姓名:";
			cin >> name; cout << endl;
			a[i][0] = "姓名:" + name;
			cout << "请输入你要修改的电话号码:";
			cin >> tel;
			a[i][1] = "电话号码:" + tel;
			//cout << "请输入你要修改的籍贯:";
			cout << "修改成功!" << endl;
		}
	}
	fstream infile2("手机卡通讯录.txt", ios::in);
	if (!infile2)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	for (int i = 0; i <= num; 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();//关闭文件
}

//查询并显示某一联系人的信息:
void card_address_book::query(string pname)const
{
	string a[1000][2];
	string p_name;
	cout << "请输入要查询的联系人姓名:";
	cin >> p_name;
	string name_s;
	name_s = "姓名:" + p_name;
	fstream infile("手机卡通讯录.txt", ios::in);
	if (!infile)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	for (int i = 0; i <= 1000; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			infile >> a[i][j];
		}
		if (name_s == a[i][0])
		{
			cout << "您查找的联系人信息为:" << endl;
			cout << name_s << endl;
			cout << a[i][0] << endl;
		}
	}
	infile.close();
}

//Display:显示所有联系人的信息
void card_address_book::display()const
{
	int num;
	 string  a[1000][2];
	fstream infile("手机卡通讯录.txt", ios::in);
	if (!infile)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	for (int i = 0; i < 1000; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			infile >> a[i][j];
		}
		num = i;
		if (a[i][0] == "")
		{
			break;
		}
	}
	infile.close();
	for (int i = 0; i < num; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			cout << a[i][j] << endl;
		}
	}
}

//void card_address_book::clean_card_book(){}
#include"Phone_Address_Book.h"
#include"Phone_Contacts.h"
//const char* phonebookfile = "手机通讯录.txt";//系统默认在这个文件中读写

//读取文本文件中的数据,并根据文件内容创建联系人对象数组
phone_adddress_book::phone_adddress_book()
{
	cout << "********************************************" << endl;
	cout << "*****         欢迎来到手机通讯簿        ****" << endl;
	cout << "********************************************" << endl;
}

phone_adddress_book::~phone_adddress_book()
{
	cout << "**********************************************" << endl;
	cout << "***********    成功离开手机通讯簿   *********" << endl;
	cout << "**********************************************" << endl;
}

void phone_adddress_book::add()const
{
	int num;
	string a[1000][4];
	fstream infile("手机通讯录.txt", ios::in);
	if (!infile)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	for (int i = 0; i <= 1000; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			infile >> a[i][j];
		}
		num = i;
		if (a[i][0] == "")
		{
			break;
		}
	}
	cout << "现在已经有:" << num << "个联系人" << endl;
	if (num < 1000)
	{
		Phone_Contacts A;
		cin >> A;
		cout << "你刚才输入的信息为:" << endl;
		cout << A;
		fstream infile("手机通讯录.txt", ios::app | ios::out);
		if (!infile)
		{
			cout << "File could not open!" << endl;
			abort();
		}
		infile << "姓名:" << A.getname() << endl;
		infile << "电话号码:" << A.gettel() << endl;
		infile << "籍贯:" << A.getaddress() << endl;
		infile << "QQ号码:" << A.getqq() << endl;
		infile.close();
	}
	else if (num >= 1000)
	{
		cout << "手机卡容量已满,无法添加!请清理空间!" << endl;
	}
}

void phone_adddress_book::remove_tel(string ptel)const
{
	string a[1000][4], ttel, tel_s;
	int num;
	cout << "请输入你要删除的联系人的电话号码:";
	cin >> ttel;
	tel_s = "电话号码:" + ttel;
	fstream infile("手机通讯录.txt", ios::in);
	if (!infile)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	for (int i = 0; i < 1000; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			infile >> a[i][j];
		}
		num = i;
		if (a[i][0] == "")
		{
			break;
		}
	}
	infile.close();
	for (int i = 0; i > p_name;
	string name_s;
	name_s = "姓名:" + p_name;
	fstream infile("手机通讯录.txt", ios::in);
	if (!infile)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	for (int i = 0; i <= 1000; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			infile >> a[i][j];
		}
		if (name_s == a[i][0])
		{
			cout << "您查找的联系人信息为:" << endl;
			cout << name_s << endl;
			cout << a[i][1] << endl;
			cout << a[i][2] << endl;
			cout << a[i][3] << endl;
		}
	}
	infile.close();
}

void phone_adddress_book::change_tel(string ptel)const
{

	string a[1000][4]; string p_tel; string tel_s;
	int num;
	cout << "输入你要修改的联系人电话号码:";
	cin >> p_tel;
	tel_s = "电话号码" + p_tel;
	fstream infile("手机卡通讯录.txt", ios::in);
	if (!infile)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	for (int i = 0; i <= 1000; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			infile >> a[i][j];
		}
		num = i;
		if (a[i][0] == "")
		{
			break;
		}
	}
	infile.close();
	for (int i = 0; i < num; i++)
	{
		if (tel_s == a[i][1])
		{
			string name, tel, address, qq;
			cout << "请输入你要修改的姓名:";
			cin >> name; cout << endl;
			a[i][0] = "姓名:" + name;
			cout << "请输入你要修改的电话号码:";
			cin >> tel;
			a[i][1] = "电话号码:" + tel;
			cout << "请输入你要修改的籍贯:";
			cin >> address;
			a[i][2] = "籍贯·:" + address;
			cout << "请输入你要修改的QQ号:";
			cin >> qq;
			a[i][3] = "QQ号:" + qq;
			cout << "修改成功!" << endl;
		}
	}
	fstream infile2("手机通讯录.txt", ios::in);
	if (!infile2)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	for (int i = 0; i <= num; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			if (a[i][0] == "1")
			{
				break;
			}
			else
			{
				infile2 << a[i][j] << endl;
			}
		}
	}
	infile2.close();//关闭文件
}

void phone_adddress_book::display()const
{
	//int num;
	string a[1000][4];
	fstream infile("手机通讯录.txt", ios::in);
	if (!infile)
	{
		cout << "File could not open!" << endl;
		abort();
	}
	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;
			}
		}
	}
}
//void phone_adddress_book::clean_phone_book()const
//{
//}
用户类user头文件
#pragma once

#ifndef USER_H
#define USER_H
#include"menu.h"
#include"Phone_Address_Book.h"
#include"Card_Address_Book.h"

class user
{
private:
	phone_adddress_book myphone;
	card_address_book mycard;
	menu umenu;
public:
	user();
	void add();//联系人的添加

	void remove_tel(string ptel);//删除联系添加联系人

	void change(string ptel);//修改某一联系人的信息:调用通讯簿对象的函数完成操作

	void query(string pname);//查询并显示某一联系人的信息:调用通讯簿对象的函数完成操作

	void display();//Display:显示相应的通讯簿中联系人的信息

	void move_cardto_phone();//将手机卡中的存储的联系人的信息移动到手机中

	void move_phoneto_card();//将手机中存储的联系人的信息移动到手机卡中

	void  copy_cardto_phone();//将手机卡中的存储的联系人的信息复制到手机中
	
	void copy_phoneto_card();//将手机中存储的联系人的信息复制到手机卡中

	~user();
};
#endif // !USER_H
源文件user
#include"user.h"

user::user()
{
	int number;//可选择的数字
	cout << "******************************************************************" << endl;
	cout << "***********************   欢迎来到用户操作区  ********************" << endl;
	cout << "******************************************************************" << endl;
	cout << "                                                                  " << endl;
	cout << "                   ******请选择并输入你选择的数字******           " << endl;
	cout << "********   ————————1-添加联系人——————————*******" << endl;
	cout << "********   ————————2-删除联系人——————————*******" << endl;
	cout << "********   ————————3-修改联系人——————————*******" << endl;
	cout << "********   ————————4-查询联系人——————————*******" << endl;
	cout << "********   ————————5-添加联系人——————————*******" << endl;
	cout << "********   ————————6-显示所有联系人————————*******" << endl;
	cout << "                                                                  " << endl;
	cout << "                                                                  " << endl;
	cout << "******************************************************************" << endl;
	cout << "******************************************************************" << endl;
	cin >> number;
	while (true)
	{
		switch (number)
		{
		case 1:
			add();
			break;
		case 2:
			remove_tel(0);
			break;
		case 3:
			change(0);
			break;
		case 4:
			query(0);
			break;
		case 5:
			display();
			break;
		default:
				cout << "输入错误!请按要求输入,谢谢!" << endl;
		}
	}

}
void user::add()
{
	cout << "********************************************************" << endl;
	cout << "*************———欢迎来到添加联系人区————*********" << endl;
	cout << "********************************************************" << endl;
	cout << "*******                                          *******" << endl;
	cout << "**********————    0-返回上一级菜单      ————****" << endl;
	cout << "**********————    1-在手机中添加联系人  ————****" << endl;
	cout << "**********————   2-在手机卡中添加联系人 ————****" << endl;
	cout << "*******                                          *******" << endl;
	cout << "***********——   请选择输入数字:0.or 1.or 2.——******" << endl;
	cout << "********************************************************" << endl;
	int n;
	cin >> n;
	address_book* temp;
	//card_address_book cb;
	//phone_adddress_book pb;
	cout << "=============================================================================" << endl;
	switch (n)
	{
	case 1:
		temp = &myphone;   //利用基类指针,调用手机的通讯簿对象,实现动态联编,体现出多态特点
		temp->add();
		break;
	case 2:
		temp = &mycard;   // //利用基类指针,调用手机卡的通讯簿对象,实现动态联编,体现出多态特点
		temp->add();
		break;
	case 0:
		system("cls");//清屏
		break;
	default:
		cout << "输入操作错误!,请重新操作!" << endl;
		return;
	}
	cout << "=============================================================================" << endl;
}
void user::remove_tel(string ptel) //电话号码删除
{
	cout << "********************************************************" << endl;
	cout << "*************———欢迎来到删除联系人区————*********" << endl;
	cout << "********************************************************" << endl;
	cout << "*******                                          *******" << endl;
	cout << "**********————    0-退出删除界面        ————****" << endl;
	cout << "**********————    1-在手机中删除联系人  ————****" << endl;
	cout << "**********————    2-在手机卡中删除联系人  ———****" << endl;
	cout << "**********————    3-删除所有联系人        ———****" << endl;
	cout << "*******                                          *******" << endl;
	cout << "*******——   请选择输入数字:0.or1.or 2.or 3.——******" << endl;
	cout << "********************************************************" << endl;
	int n;
	cin >> n;
	address_book* temp;
	switch (n)
	{
	case 1:      // 1-在手机中删除联系人 
		temp = &myphone;
		temp->remove_tel(ptel);
		break;
	case 2:     //2 - 在手机卡中删除联系人
		temp = &mycard;
		temp->remove_tel(ptel);
		break;
	case 3:
	{
		fstream infile1("手机通讯录.txt", ios::out);
		if (!infile1)
		{
			cout << "File could not open!" << endl;
		}
		else
		{
			infile1 << "";
		}
		fstream infile2("手机卡通讯录.txt", ios::out);
		if (!infile2)
		{
			cout << "File could not open!" << endl;
		}
		else
		{
			infile2 << "";
		}
		cout << "全部删除成功!" << endl;
		infile1.close();
		infile2.close();
		break;
	}
	case 0:
		system("cls");//清屏
	default:
		cout << "操作错误!" << endl;
		break;
	}
}
void user::change(string ptel)    //电话号码修改
{
	cout << "********************************************************" << endl;
	cout << "*************———欢迎来到修改联系人区————*********" << endl;
	cout << "********************************************************" << endl;
	cout << "*******                                          *******" << endl;
	cout << "**********————    0-退出修改界面        ————****" << endl;
	cout << "**********————    1-在手机中修改联系人  ————****" << endl;
	cout << "**********————    2-在手机卡中修改联系人  ———****" << endl;
	cout << "**********————    3-两个都修改联系人        ———****" << endl;
	cout << "*******                                          *******" << endl;
	cout << "*******——   请选择输入数字:0.or1.or 2.or 3.——******" << endl;
	cout << "********************************************************" << endl;
	int n;
	cin >> n;
	address_book* temp;
	switch (n)
	{
	case 1:
		temp = &myphone;
		temp->change_tel(ptel);
		break;
	case 2:
		temp = &mycard;
		temp->change_tel(ptel);
		break;
	case 3:
		temp = &myphone;
		temp->change_tel(ptel);
		temp = &mycard;
		temp->change_tel(ptel);
		break;
	case 0:
		system("cls");
	default:
		cout << "操作错误!" << endl;
		break;
	}

}
void user::query(string pname)
{

	cout << "********************************************************" << endl;
	cout << "*************———欢迎来到查询联系人区————*********" << endl;
	cout << "********************************************************" << endl;
	cout << "*******                                          *******" << endl;
	cout << "**********————    0-退出查询界面        ————****" << endl;
	cout << "**********————    1-在手机中查询联系人  ————****" << endl;
	cout << "**********————    2-在手机卡中查询联系人  ———****" << endl;
	cout << "**********————    3-两个都查询联系人        ———****" << endl;
	cout << "*******                                          *******" << endl;
	cout << "*******——   请选择输入数字:0.or1.or 2.or 3.——******" << endl;
	cout << "********************************************************" << endl;
	int n;
	cin >> n;
	address_book* temp;
	switch (n)
	{
	case 1:
		temp = &myphone;
		temp->query_name(pname);
		break;
	case 2:
		temp = &mycard;
		temp->query_name(pname);
		break;
	case 3:
		temp = &myphone;
		temp->query_name(pname);
		temp = &mycard;
		temp->query_name(pname);
		break;
	case 0:
		system("cls");
	default:
		cout << "操作错误!" << endl;
		break;
	}
}
void user::display()
{

	cout << "********************************************************" << endl;
	cout << "*************———欢迎来到显示联系人区————*********" << endl;
	cout << "********************************************************" << endl;
	cout << "*******                                          *******" << endl;
	cout << "**********————    0-退出显示界面        ————****" << endl;
	cout << "**********————    1-显示手机中的联系人  ————****" << endl;
	cout << "**********————    2-显示手机卡中的联系人  ———****" << endl;
	cout << "**********————    3-显示两个联系人        ———****" << endl;
	cout << "*******                                          *******" << endl;
	cout << "*******——   请选择输入数字:0.or1.or 2.or 3.——******" << endl;
	cout << "********************************************************" << endl;
	int n;
	cin >> n;
	address_book* temp;
	switch (n)
	{
	case 1:
		temp = &myphone;
		temp->display();
		break;
	case 2:
		temp = &mycard;
		temp->display();
		break;
	case 3:
		temp = &myphone;
		temp->display();
		temp = &mycard;
		temp->display();
		break;
	case 0:
		system("cls");
	default:
		cout << "操作错误!" << endl;
		break;
	}
}
void user::move_cardto_phone()
{

}
void user::move_phoneto_card()
{}
void user::copy_cardto_phone()
{}
void user::copy_phoneto_card()
{}
user::~user()
{
	cout << "感谢使用通讯录管理系统!您的联系人已经存入相关文件中。" << endl;
}
菜单类显示各种操作界面头文件:
#pragma once
//定义菜单类显示各种操作界面

#ifndef MENU_H
#define MENU_H

#include
using namespace std;
class menu {
public:
	menu();
	~menu();
	int displaymenu();
};
#endif
菜单类显示各种操作界面源文件:
#include"user.h"

user::user()
{
	int number;//可选择的数字
	cout << "******************************************************************" << endl;
	cout << "***********************   欢迎来到用户操作区  ********************" << endl;
	cout << "******************************************************************" << endl;
	cout << "                                                                  " << endl;
	cout << "                   ******请选择并输入你选择的数字******           " << endl;
	cout << "********   ————————1-添加联系人——————————*******" << endl;
	cout << "********   ————————2-删除联系人——————————*******" << endl;
	cout << "********   ————————3-修改联系人——————————*******" << endl;
	cout << "********   ————————4-查询联系人——————————*******" << endl;
	cout << "********   ————————5-添加联系人——————————*******" << endl;
	cout << "********   ————————6-显示所有联系人————————*******" << endl;
	cout << "                                                                  " << endl;
	cout << "                                                                  " << endl;
	cout << "******************************************************************" << endl;
	cout << "******************************************************************" << endl;
	cin >> number;
	while (true)
	{
		switch (number)
		{
		case 1:
			add();
			break;
		case 2:
			remove_tel(0);
			break;
		case 3:
			change(0);
			break;
		case 4:
			query(0);
			break;
		case 5:
			display();
			break;
		default:
				cout << "输入错误!请按要求输入,谢谢!" << endl;
		}
	}

}
void user::add()
{
	cout << "********************************************************" << endl;
	cout << "*************———欢迎来到添加联系人区————*********" << endl;
	cout << "********************************************************" << endl;
	cout << "*******                                          *******" << endl;
	cout << "**********————    0-返回上一级菜单      ————****" << endl;
	cout << "**********————    1-在手机中添加联系人  ————****" << endl;
	cout << "**********————   2-在手机卡中添加联系人 ————****" << endl;
	cout << "*******                                          *******" << endl;
	cout << "***********——   请选择输入数字:0.or 1.or 2.——******" << endl;
	cout << "********************************************************" << endl;
	int n;
	cin >> n;
	address_book* temp;
	//card_address_book cb;
	//phone_adddress_book pb;
	cout << "=============================================================================" << endl;
	switch (n)
	{
	case 1:
		temp = &myphone;   //利用基类指针,调用手机的通讯簿对象,实现动态联编,体现出多态特点
		temp->add();
		break;
	case 2:
		temp = &mycard;   // //利用基类指针,调用手机卡的通讯簿对象,实现动态联编,体现出多态特点
		temp->add();
		break;
	case 0:
		system("cls");//清屏
		break;
	default:
		cout << "输入操作错误!,请重新操作!" << endl;
		return;
	}
	cout << "=============================================================================" << endl;
}
void user::remove_tel(string ptel) //电话号码删除
{
	cout << "********************************************************" << endl;
	cout << "*************———欢迎来到删除联系人区————*********" << endl;
	cout << "********************************************************" << endl;
	cout << "*******                                          *******" << endl;
	cout << "**********————    0-退出删除界面        ————****" << endl;
	cout << "**********————    1-在手机中删除联系人  ————****" << endl;
	cout << "**********————    2-在手机卡中删除联系人  ———****" << endl;
	cout << "**********————    3-删除所有联系人        ———****" << endl;
	cout << "*******                                          *******" << endl;
	cout << "*******——   请选择输入数字:0.or1.or 2.or 3.——******" << endl;
	cout << "********************************************************" << endl;
	int n;
	cin >> n;
	address_book* temp;
	switch (n)
	{
	case 1:      // 1-在手机中删除联系人 
		temp = &myphone;
		temp->remove_tel(ptel);
		break;
	case 2:     //2 - 在手机卡中删除联系人
		temp = &mycard;
		temp->remove_tel(ptel);
		break;
	case 3:
	{
		fstream infile1("手机通讯录.txt", ios::out);
		if (!infile1)
		{
			cout << "File could not open!" << endl;
		}
		else
		{
			infile1 << "";
		}
		fstream infile2("手机卡通讯录.txt", ios::out);
		if (!infile2)
		{
			cout << "File could not open!" << endl;
		}
		else
		{
			infile2 << "";
		}
		cout << "全部删除成功!" << endl;
		infile1.close();
		infile2.close();
		break;
	}
	case 0:
		system("cls");//清屏
	default:
		cout << "操作错误!" << endl;
		break;
	}
}
void user::change(string ptel)    //电话号码修改
{
	cout << "********************************************************" << endl;
	cout << "*************———欢迎来到修改联系人区————*********" << endl;
	cout << "********************************************************" << endl;
	cout << "*******                                          *******" << endl;
	cout << "**********————    0-退出修改界面        ————****" << endl;
	cout << "**********————    1-在手机中修改联系人  ————****" << endl;
	cout << "**********————    2-在手机卡中修改联系人  ———****" << endl;
	cout << "**********————    3-两个都修改联系人        ———****" << endl;
	cout << "*******                                          *******" << endl;
	cout << "*******——   请选择输入数字:0.or1.or 2.or 3.——******" << endl;
	cout << "********************************************************" << endl;
	int n;
	cin >> n;
	address_book* temp;
	switch (n)
	{
	case 1:
		temp = &myphone;
		temp->change_tel(ptel);
		break;
	case 2:
		temp = &mycard;
		temp->change_tel(ptel);
		break;
	case 3:
		temp = &myphone;
		temp->change_tel(ptel);
		temp = &mycard;
		temp->change_tel(ptel);
		break;
	case 0:
		system("cls");
	default:
		cout << "操作错误!" << endl;
		break;
	}

}
void user::query(string pname)
{

	cout << "********************************************************" << endl;
	cout << "*************———欢迎来到查询联系人区————*********" << endl;
	cout << "********************************************************" << endl;
	cout << "*******                                          *******" << endl;
	cout << "**********————    0-退出查询界面        ————****" << endl;
	cout << "**********————    1-在手机中查询联系人  ————****" << endl;
	cout << "**********————    2-在手机卡中查询联系人  ———****" << endl;
	cout << "**********————    3-两个都查询联系人        ———****" << endl;
	cout << "*******                                          *******" << endl;
	cout << "*******——   请选择输入数字:0.or1.or 2.or 3.——******" << endl;
	cout << "********************************************************" << endl;
	int n;
	cin >> n;
	address_book* temp;
	switch (n)
	{
	case 1:
		temp = &myphone;
		temp->query_name(pname);
		break;
	case 2:
		temp = &mycard;
		temp->query_name(pname);
		break;
	case 3:
		temp = &myphone;
		temp->query_name(pname);
		temp = &mycard;
		temp->query_name(pname);
		break;
	case 0:
		system("cls");
	default:
		cout << "操作错误!" << endl;
		break;
	}
}
void user::display()
{

	cout << "********************************************************" << endl;
	cout << "*************———欢迎来到显示联系人区————*********" << endl;
	cout << "********************************************************" << endl;
	cout << "*******                                          *******" << endl;
	cout << "**********————    0-退出显示界面        ————****" << endl;
	cout << "**********————    1-显示手机中的联系人  ————****" << endl;
	cout << "**********————    2-显示手机卡中的联系人  ———****" << endl;
	cout << "**********————    3-显示两个联系人        ———****" << endl;
	cout << "*******                                          *******" << endl;
	cout << "*******——   请选择输入数字:0.or1.or 2.or 3.——******" << endl;
	cout << "********************************************************" << endl;
	int n;
	cin >> n;
	address_book* temp;
	switch (n)
	{
	case 1:
		temp = &myphone;
		temp->display();
		break;
	case 2:
		temp = &mycard;
		temp->display();
		break;
	case 3:
		temp = &myphone;
		temp->display();
		temp = &mycard;
		temp->display();
		break;
	case 0:
		system("cls");
	default:
		cout << "操作错误!" << endl;
		break;
	}
}
void user::move_cardto_phone()
{

}
void user::move_phoneto_card()
{}
void user::copy_cardto_phone()
{}
void user::copy_phoneto_card()
{}
user::~user()
{
	cout << "感谢使用通讯录管理系统!您的联系人已经存入相关文件中。" << endl;
}

 

 

 // 通讯录管理系统主函数菜单实现区:
#include
#include"menu.h"
#include"user.h"
#include"Address_Book.h"
#include"Card_Address_Book.h"
#include"Card_Contacts.h"
#include"Phone_Address_Book.h"
#include"Phone_Contacts.h"

// 通讯录管理系统主函数菜单实现区:

int main()
{
	menu mymenu;
	user me;
	mymenu.displaymenu();
	system("pause");

	return 0;
}

还没有成功,出现的错误还没有解决!基本的框架就是如此了。

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/982757.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号