c++通讯录管理系统(函数,指针,结构体)

最多存储1000人

#include<iostream>
using namespace std;
//添加联系人(姓名,性别,年龄)
//显示联系人
//删除联系人:按照姓名删
//查找联系人:按照名字查
//修改联系人:按照名字修改
//清空联系人:清空全部
//退出通讯录:退出
struct people {
	string name;
	string sex;
	int age;
};
void add(people arr[],int i) {
	
	cout<<"请输入姓名:" << endl;
	cin >> arr[i].name;
	cout << "请输入性别:" << endl;
	cin >> arr[i].sex;
	cout << "请输入年龄:" << endl;
	cin >> arr[i].age;
}
void show(people arr[],  int i) {
	for (int j = 0; j < i; j++) {
		cout<<"姓名:" << arr[j].name << "\t性别:" << arr[j].sex << "\t年龄:" << arr[j].age << endl;
	}
}
int flag=-1;
void delet(people arr[], int * i) {
	cout<<"输入删除人的姓名:" << endl;
	string name;
	cin >> name;
	for (int j = 0; j < *i; j++) {
		if (name == arr[j].name) {
			flag = 1;
			for (int m = j; m < *i-1; m++) {
				arr[m] = arr[m + 1];
			}
			*i=*i-1;
			cout << "删除成功!!!" << endl;
			break;
		}
	}
	if (flag == -1) {
		cout << "查无此人!" << endl;
	}
	flag = -1;
}

void find(people arr[], int i) {
	cout<<"输入要查找的姓名:" << endl;
	string tmp;
	cin >> tmp;
	for (int j = 0; j < i; j++) {
		if (tmp == arr[j].name) {
			cout << "姓名:" << arr[j].name << "\t性别:" << arr[j].sex << "\t年龄:" << arr[j].age << endl;
			cout << "查找成功!!!" << endl;
			flag = 1;
			break;
		}
	}
	if (flag == -1) {
		cout << "查无此人!" << endl;
	}
	flag = -1;
}
void update(people arr[], int i) {
	cout << "输入要修改的人的姓名:" << endl;
	string tmp;
	cin >> tmp;
	for (int j = 0; j < i; j++) {
		if (tmp == arr[j].name) {
			cout << "姓名:" << arr[j].name << "\t性别:" << arr[j].sex << "\t年龄:" << arr[j].age << endl;
			cout<< "姓名:" <<endl;
			string name;
			cin >> name;
			arr[j].name = name;
			cout << "性别:" << endl;
			string sex;
			cin >> sex;
			arr[j].sex = sex;
			cout << "年龄:" << endl;
			int age;
			cin >> age;
			arr[j].age = age;
			cout<<"修改成功!" << endl;
			cout << "姓名:" << arr[j].name << "\t性别:" << arr[j].sex << "\t年龄:" << arr[j].age << endl;
			flag = 1;
			break;
		}
	}
	if (flag == -1) {
		cout << "查无此人!" << endl;
	}
	flag = -1;
}
void trun(people arr[], int * i) {
	*i = 0;
	cout<<"清空成功" << endl;
}
int main() {
	people arr[1000];//最多存储1000人
	int i=0;
	while (true) {
		cout << "1《添加联系人》" << endl;
		cout << "2《显示联系人》" << endl;
		cout << "3《删除联系人》" << endl;
		cout << "4《查找联系人》" << endl;
		cout << "5《修改联系人》" << endl;
		cout << "6《清空联系人》" << endl;
		cout << "7《退出通讯录》" << endl;
		cout << "您要做的操作是:" << endl;
		int choise;
		cin>>choise;
		switch (choise)
		{
		case 1:
			cout << "1《添加联系人》" << endl;
			add(arr,i);
			cout << "添加成功!!!" << endl;
			i++;
			system("pause");//按任意键继续
			system("cls");//清屏
			break;
		case 2:
			cout << "2《显示联系人》" << endl;
			show(arr,i);
			cout << "显示成功!!!" << endl;
			system("pause");
			system("cls");
			break;
		case 3:
			cout << "3《删除联系人》" << endl;
			delet(arr, &i);
			system("pause");
			system("cls");
			break;
		case 4:
			cout << "4《查找联系人》" << endl;
			find(arr, i);
			system("pause");
			system("cls");
			break;
		case 5:
			cout << "5《修改联系人》" << endl;
			update(arr, i);
			system("pause");
			system("cls");
			break;
		case 6:
			cout << "6《清空联系人》" << endl;
			trun(arr, &i);
			system("pause");
			system("cls");
			break;
		case 7:
			cout<< "7《退出通讯录》" << endl;
			cout<<"退出成功!!!" << endl;
			return false;
			
		default:
			cout << "输入错误!!!" << endl;
			system("pause");
			system("cls");
			break;
		}
	}
	system("pause");
	return 0;

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值