⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phone.txt

📁 简单的电话簿
💻 TXT
字号:
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
class book
{
protected:
	string name;
	string address;
	long int number;
	int qq;
public:
	book(){}
	void add_person();
	virtual void print(){}
	virtual void select(){}
	virtual void save_new(){}
};
void book::add_person()
{
	cout<<"根据提示输入新联系人的信息"<<endl;
	cout<<"姓名:";
	cin>>name;
	cout<<"电话:";
	cin>>number;
	cout<<"QQ:";
	cin>>qq;
	cout<<"地址:";
	cin>>address;
}
class Friend:public book
{
private:
	string workplace;
public:
	void save_new()
	{
		ofstream outDate("friend.txt",ios::app);
		if(!outDate)
		{
			cout<<"对不起,打开文件失败!!!"<<endl;
			system("pause");
			return;}
		outDate<<name<<"\t"<<number<<"\t"<<qq<<"\t"
			<<address<<"\t"<<workplace<<endl;
		outDate.close();
	}
	void add_person()
	{
		book::add_person();
		cout<<"工作地方:";
		cin>>workplace;
		save_new();
		cout<<"新联系人的信息已经保存好了!"<<endl;
	}
	void print()
	{
		ifstream inDate("friend.txt",ios::in);
		if(!inDate)
		{
			cout<<"对不起,文件找不到!"<<endl;
			system("pause");
			return;
		}
		bool flag=true;
		string record;
		while(getline(inDate,record))
		{
			cout<<record<<endl;
			flag=false;
		}
		if(flag)
			cout<<"你的朋友信息为空,快添加吧!"<<endl;

	}
	void select()
	{
		ifstream inDate("friend.txt",ios::in);
		if(!inDate)
		{
			cout<<"对不起,文件找不到!"<<endl;
			system("pause");
			return;}
		string sign;
		cout<<"输入你想查找的联系人的姓名:";
		cin>>sign;
		bool flag=true;
		string str;
		while(inDate>>name)
		{
			getline(inDate,str);
			if(name==sign)
			{
				cout<<"你要找的联系人信息:"<<sign<<endl;
				cout<<"\t"<<"电话"<<"\t\t"<<"QQ"<<"\t\t"<<"地址"<<"\t\t"<<"工作地方"<<endl;
				cout<<str<<endl;
				flag=false;
				break;
			}
		}
		if(flag)
			cout<<"没有你要查找的人!!!"<<endl;
	}
};
class family:public book
{
private:
	string appellation;
public:
	void save_new()
	{
		ofstream outDate("family.txt",ios::app);
		if(!outDate)
		{
			cout<<"对不起,打开文件失败!!!"<<endl;
			system("pause");
			return;}
		outDate<<name<<"\t"<<appellation<<"\t"<<number<<"\t"
			<<qq<<"\t"<<address<<endl;
		outDate.close();
	}
	void add_person()
	{
		book::add_person();
		cout<<"称呼:";
		cin>>appellation;
		save_new();
		cout<<"新联系人的信息已经保存好了!"<<endl;
		system("pause");
	}
	void print()
	{
		ifstream inDate("family.txt",ios::in);
		if(!inDate)
		{
			cout<<"对不起,文件找不到!"<<endl;
			system("pause");
			return;
		}
		bool flag=true;
		string record;
		while(getline(inDate,record))
		{
			cout<<"\t"<<record<<endl;
			flag=false;
		}
		if(flag)
			cout<<"你的亲人信息为空,快添加吧!"<<endl;

	}
	void select()
	{
		ifstream inDate("family.txt",ios::in);
		if(!inDate)
		{
			cout<<"对不起,文件找不到!"<<endl;
			system("pause");
			return;}
		string sign;
		cout<<"输入你想查找的联系人的姓名:";
		cin>>sign;
		bool flag=true;
		string str;
		while(inDate>>name)
		{
			getline(inDate,str);
			if(name==sign)
			{
				cout<<"你要找的联系人信息:"<<endl;
				cout<<"\t"<<"称呼"<<"\t\t"<<"电话"<<"\t\t"<<"QQ"<<"\t\t"<<"地址"<<endl;
				cout<<str<<endl;
				flag=false;
				break;
			}
		}
		if(flag)
			cout<<"没有你要查找的人!!!"<<endl;
	}
};
class colleague:public book
{
private:
	string workpost;
public:
	void save_new()
	{
		ofstream outDate("friend.txt",ios::app);
		if(!outDate)
		{
			cout<<"对不起,打开文件失败!!!"<<endl;
			system("pause");
			return;}
		outDate<<name<<"\t"<<number<<"\t"<<qq<<"\t"
			<<workpost<<"\t"<<address<<endl;
		outDate.close();
	}
	void add_person()
	{
		book::add_person();
		cout<<"工作职位:";
		cin>>workpost;
		save_new();
		cout<<"新联系人的信息已经保存好了!"<<endl;
		system("pause");
	}
	void print()
	{
		ifstream inDate("colleague.txt",ios::in);
		if(!inDate)
		{
			cout<<"对不起,文件找不到!"<<endl;
			system("pause");
			return;
		}
		bool flag=true;
		string record;
		while(getline(inDate,record))
		{
			cout<<"\t"<<record<<endl;
			flag=false;
		}
		if(flag)
			cout<<"你的同事信息为空,快添加吧!"<<endl;

	}
	void select()
	{
		ifstream inDate("colleague.txt",ios::in);
		if(!inDate)
		{
			cout<<"对不起,文件找不到!"<<endl;
			system("pause");
			return;}
		string sign;
		cout<<"输入你想查找的联系人的姓名:";
		cin>>sign;
		bool flag=true;
		string str;
		while(inDate>>name)
		{
			getline(inDate,str);
			if(name==sign)
			{
				cout<<"你要找的联系人是:"<<endl;
				cout<<"\t"<<"电话"<<"\t\t"<<"QQ"<<"\t\t"<<"职位"<<"\t\t"<<"地址"<<endl;
				cout<<str<<endl;
				flag=false;
				break;
			}
		}
		if(flag)
			cout<<"没有你要查找的人!!!"<<endl;
	}
};
Friend m1;
family m2;
colleague m3;
book *emp[3]={&m1,&m2,&m3};
char inter_face()
{
	int choose;
	system("cls");
	cout<<endl;
	cout<<"\t******个人通讯录系统******"<<endl;
	cout<<"\t*1.添加新联系人"<<endl;
	cout<<"\t*2.显示联系人信息"<<endl;
	cout<<"\t*3.查询联系人"<<endl;
	cout<<"\t*4.关闭通讯录"<<endl;
	cout<<"前选择操作类型:";
	cin>>choose;
	return choose;
}
void add()
{
	char p='y';
	int a;
	while(p=='y')
	{
		system("cls");
		cout<<"请选择添加联系人的类别(1.朋友组2.亲人组3.同事组)"<<endl;
		cin>>a;
		switch(a)
		{
		case 1:m1.add_person();
				break;
		case 2:m2.add_person();
			break;
		case 3:m3.add_person();
			break;
		}
	    cout<<"是否继续?(y/n)"<<endl;
		cin>>p;
		
	}
	if(p=='n'){
		system("pause");
		return;}
}
void show()
{
	char q='y';
	int b;
	while(q=='y')
	{
		system("cls");
		cout<<"请选择显示类别(1.朋友组2.亲人组3.同事组4.显示全部)"<<endl;
		cin>>b;
		switch(b)
		{
		case 1:cout<<"我的朋友"<<endl;
			cout<<"姓名"<<"\t"<<"电话"<<"\t\t"<<"QQ"<<"\t\t"<<"地址"<<"\t\t"<<"工作地方"<<endl;
			emp[0]->print();
				break;
		case 2:cout<<"我的亲人"<<endl;
			cout<<"姓名"<<"\t\t"<<"称呼"<<"\t"<<"电话"<<"\t\t"<<"QQ"<<"\t\t"<<"地址"<<endl;
			emp[1]->print();
			break;
		case 3:cout<<"我的同事"<<endl;
			cout<<"姓名"<<"\t"<<"电话"<<"\t\t"<<"QQ"<<"\t\t"<<"职位"<<"\t\t"<<"地址"<<endl;emp[2]->print();
			break;
		case 4:for(int i=0;i!=3;i++)
				   emp[i]->print();
		}
	    cout<<"是否继续?(y/n)"<<endl;
		cin>>q;
		
	}
	if(q=='n'){
		system("pause");
		return;}
}
void search()
{
	char r='y';
	int c;
	while(r=='y')
	{
		system("cls");
		cout<<"请选择查找类别(1.朋友组2.亲人组3.同事组)"<<endl;
		cin>>c;
		switch(c)
		{
		case 1:emp[0]->select();
				break;
		case 2:emp[1]->select();
			break;
		case 3:emp[2]->select();
			break;
		}
	    cout<<"是否继续?(y/n)"<<endl;
		cin>>r;
		
	}
	if(r=='n'){
		system("pause");
		return;}
}
int main()
{
	int choose;
	while(choose=inter_face())
	{
		switch(choose)
		{
		case 1:add();
			break;
		case 2:show();
			break;
		case 3:search();
			break;
		case 4:
			cout<<"谢谢使用!!!"<<endl;
			exit(0);
			break;
		default:break;
		}
	}
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -