C++通讯录的实现

把之前写的东西慢慢都移到优快云上面,以后方便查看。用C++实现简单的通讯录功能。这个逻辑和数据存储都比较简单,所以就不一一介绍了,代码通俗易懂。

#include<string>
#include<fstream>
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
#define MAX 100
//通讯录人的信息:姓名、电话
//通讯录的功能:添加通讯录名单信息、查找联系人电话号码、删除通讯录
class person {
public:
	string name;
	string tel;
};
struct Arry_person {

	int size=0;
	person Array[MAX];
	
	

};
void add_info(Arry_person &a) //添加人员信息
{
	if (a.size == MAX)
	{
		cout << "通讯录已满" << endl;
		return;
	}
	else {
		string name;
		string tel;
		cout << "请输入人名" << endl;
		cin >> name;
		a.Array[a.size].name = name;
		cout << "请输入手机号" << endl;
		cin >> tel;
		a.Array[a.size].tel = tel;
	}
	a.size++;
}
void lookfor(Arry_person &p) {
	string name;
	cout << "请输入你要查询的姓名" << endl;
	cin >> name;
	for (int i = 0; i < p.size; i++)
	{
		if (p.Array[i].name == name)
			cout << "已查询到该人的信息" << endl;
		cout << "此人的姓名" << name << " " << "此人的电话" << p.Array[i].tel << endl;
		
	}
}int isExit(Arry_person &p, string name) {

	for (int i = 0; i < p.size; i++)
	{
		if (p.Array[i].name == name)
			return i ;
	}
}
void display(Arry_person &p) {
	for (int i = 0; i < p.size; i++)
	{
		cout << "姓名" << p.Array[i].name << "电话" << p.Array[i].tel << endl;
	}


}
void delete_info(Arry_person &p) {
	cout << "请输入要删除人的姓名" << endl;
	string name;
	cin >> name;
	int num = isExit(p, name);
	for (int j = num; j < p.size-1; j++)
	{
		p.Array[j] = p.Array[j+1];
	}
	p.size--;

}
int main() {
	Arry_person a;
	while (true)
	{
		int chioce = 0;
		cout << "欢迎进入通讯录系统,请选择你需要的功能" << endl;
		cout << " 1.添加人员信息" << endl;
		cout << " 2.查找联系人电话号码" << endl;
		cout << " 3.删除联系人方式" << endl;
		cout << " 4.显示所有联系人信息" << endl;
		cout << " 5.退出系统" << endl;
		cin >> chioce;
		
		switch (chioce)
		{
		case 1:
			add_info(a);
			break;
		case 2:
			lookfor(a);
			break;
		case 3:
			delete_info(a);
			break;
		case 4:
			display(a);
			break;
		case 5:
			exit(0);
			break;
		default:
			break;
		}



	}



}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值