C++ ——通讯录管理系统

本文详细描述了一个基于C++的通讯录管理系统,包括添加、显示、删除、查找、修改和清空联系人功能的代码实现。通过结构体和菜单设计,展示了如何管理1000个联系人的基本信息。
摘要由CSDN通过智能技术生成

通讯录管理系统

系统需求

通讯录是一个可以记录亲人、好友信息的工具。
主要利用C++来实现一个通讯录管理系统。
系统中需要实现的功能如下:

  • 添加联系人: 向通讯录中添加新人,信息包括(姓名、性别、年龄、联系电话、家庭住址)最多记录1000人。
  • 显示联系人: 显示通讯录中所有联系人信息。
  • 删除联系人: 按照姓名进行删除指定联系人。
  • 查找联系人: 按照姓名查看指定联系人信息。
  • 修改联系人: 按照姓名重新修改指定联系人。
  • 清空联系人: 清空通讯录中所有信息。
  • 清空联系人: 清空通讯录中所有信息
  • 退出通讯录: 退出当前使用的通讯录

代码:

#include<iostream>
#include<string>
using namespace std;

//创建联系人结构体
struct people
{
	string name;      //姓名
	string sex;       //性别
	string age;       //年龄
	string number;    //电话号码
	string address;   //地址
};

//菜单栏
void showMenu() {
	cout << "请输入要选择的操作:" << endl;
	cout << "-----------------------------" << endl;
	cout << "--------1、添加联系人--------" << endl;
	cout << "--------2、显示联系人--------" << endl;
	cout << "--------3、删除联系人--------" << endl;
	cout << "--------4、查找联系人--------" << endl;
	cout << "--------5、修改联系人--------" << endl;
	cout << "--------6、清空联系人--------" << endl;
	cout << "--------7、退出通讯录--------" << endl;
	cout << "-----------------------------" << endl;
}

// 添加联系人:向通讯录中添加新人
void AddPeople(struct people peopleArray[], int len) {
	cout << "添加联系人" << endl;
	string determine;
	cout << "请输入通讯录信息:" << endl;

	for (int i = len; i < 1000; i++)
	{
		cout << "姓名:";
		cin >> peopleArray[i].name;

		cout << "性别:";
		cin >> peopleArray[i].sex;
		while (true)
		{
			if (peopleArray[i].sex != "男" && peopleArray[i].sex != "女") {
				cout << "性别输入有误!请重新输入:";
				cin >> peopleArray[i].sex;
			}
			else {
				break;
			}
		}
		cout << "年龄:";
		cin >> peopleArray[i].age;
		cout << "电话号码:";
		cin >> peopleArray[i].number;
		cout << "地址:";
		cin >> peopleArray[i].address;
		system("pause");
		system("cls");
		break;
	}
}


//显示联系人:显示通讯录中所有联系人信息
void printPeople(struct people peopleArray[]) {
	cout << "显示联系人" << endl;
	for (int i = 0; i < 1000; i++)
	{
		if (peopleArray[i].name != "")
		{
			cout << "姓名:" << peopleArray[i].name << "	性别:" << peopleArray[i].sex
				<< "	 年龄:" << peopleArray[i].age << "	电话号码:" << peopleArray[i].number
				<< "	地址:" << peopleArray[i].address << endl;
		}
		if (peopleArray[0].name == "")
		{
			cout << "空!" << endl;
			break;
		}
	}
	system("pause");
	system("cls");
}


//删除联系人:按照姓名进行删除指定联系人
void delectPeople(struct people peopleArray[], string delectName) {
	for (int i = 0; i < 1000; i++)
	{
		if (peopleArray[i].name == delectName && peopleArray[i].name != "")
		{ //找到指定姓名的联系人
			for (int j = i; j < 1000; j++) {
				if (peopleArray[j].name != "")   //所有后面的联系人信息往前移动,覆盖要删除的联系人
				{
					peopleArray[j].name = peopleArray[j + 1].name;
					peopleArray[j].sex = peopleArray[j + 1].sex;
					peopleArray[j].age = peopleArray[j + 1].age;
					peopleArray[j].number = peopleArray[j + 1].number;
					peopleArray[j].address = peopleArray[j + 1].address;
				}
				else {
					break;
				}
			}
			cout << delectName << "已删除!" << endl;
			break;
		}
	}
	system("pause");
	system("cls");
}

//查找联系人:按照姓名查看指定联系人信息
void SeekPeople(struct people peopleArray[], string seekName) {
	for (int i = 0; i < 3000; i++)
	{
		if (peopleArray[i].name == seekName && peopleArray[i].name != "")
		{
			cout << "要查找的联系人信息:" << endl;
			cout << "姓名:" << peopleArray[i].name << "	性别:" << peopleArray[i].sex
				<< "	年龄:" << peopleArray[i].age << "	 电话号码:" << peopleArray[i].number
				<< "	地址:" << peopleArray[i].address << endl;
			break;
		}
	}
	system("pause");
	system("cls");
}


//修改联系人:按照姓名修改指定联系人信息
void modifyPeople(struct people peopleArray[], string modifyName) {
	for (int i = 0; i < 1000; i++) {
		if (peopleArray[i].name == modifyName && peopleArray[i].name != "")
		{
			cout << "请输入联系人" << modifyName << "要修改的信息" << endl;
			cout << "姓名:";
			cin >> peopleArray[i].name;
			cout << "性别:";
			cin >> peopleArray[i].sex;
			while (true)
			{
				if (peopleArray[i].sex != "男" && peopleArray[i].sex != "女") {
					cout << "性别输入有误!请重新输入:";
					cin >> peopleArray[i].sex;
				}
				else {
					break;
				}
			}
			cout << "年龄:";
			cin >> peopleArray[i].age;
			cout << "电话号码:";
			cin >> peopleArray[i].number;
			cout << "地址:";
			cin >> peopleArray[i].address;
			break;
		}
	}
	system("pause");
	system("cls");
}

//清空联系人:清空通讯录中的所有信息
void emptyPeople(struct people peopleArray[]) {
	for (int i = 0; i < 1000; i++)
	{
		if (peopleArray[i].name != "")
		{
			peopleArray[i].name = "";
			peopleArray[i].sex = "";
			peopleArray[i].age = "";
			peopleArray[i].number = "";
			peopleArray[i].address = "";
		}
	}
	cout << "清空联系人成功!" << endl;
	system("pause");
	system("cls");
}

int main() {
	int len = 0;
	int select;
	//创建通讯录
	struct people peopleArray[1000];
	for (int i = 0; i < 1000; i++)
	{
		//显示菜单
		showMenu();
		cout << "请输入操作序号:";
		cin >> select;
		switch (select)
		{
		case 1:
		{
			cout << "------------------------------" << endl;
			//添加联系人信息
			AddPeople(peopleArray, len);
			len++;
			cout << "------------------------------" << endl;
			break;
		}
		case 2:
		{
			cout << "------------------------------" << endl;
			//显示联系人信息
			printPeople(peopleArray);
			cout << "------------------------------" << endl;
			break;
		}
		case 3:
		{
			cout << "------------------------------" << endl;
			//删除指定姓名的联系人信息
			string delectName;
			cout << "请输入要删除的联系人姓名:";
			cin >> delectName;
			delectPeople(peopleArray, delectName);
			cout << "------------------------------" << endl;
			break;
		}
		case 4:
		{
			cout << "------------------------------" << endl;
			//查找指定姓名的联系人信息
			string seekName;
			cout << "请输入要查找的联系人姓名:";
			cin >> seekName;
			SeekPeople(peopleArray, seekName);
			cout << "------------------------------" << endl;
			break;
		}
		case 5:
		{
			cout << "------------------------------" << endl;
			//修改指定姓名的联系人信息
			string modifyName;
			cout << "请输入要修改的联系人姓名:";
			cin >> modifyName;
			modifyPeople(peopleArray, modifyName);
			cout << "------------------------------" << endl;
			break;
		}
		case 6:
		{
			cout << "------------------------------" << endl;
			//清空联系人信息
			emptyPeople(peopleArray);
			cout << "------------------------------" << endl;
			break;
		}
		}
		if (select == 7)
			break;
	}
	cout << "退出通讯录成功!" << endl;
	system("pause");
	return 0;
}

显示栏

1、添加联系人界面

添加联系人界面

2、显示联系人界面

显示联系人界面

3、删除联系人界面

删除联系人界面

4、查找联系人界面

查找联系人界面

5、修改联系人界面

修改联系人界面

6、清空联系人界面

清空联系人界面

7、提出通讯录界面

退出通讯录界面

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值