通讯管理系统

#include<string>
#include<iostream>
using namespace std;
#define max 1000
//写菜单功能,封装函数显示该界面   void showMenu()
void showMenu()
{
	cout << "1,添加联系人" << endl;
	cout << "2,显示联系人" << endl;
	cout << "3,删除联系人" << endl;
	cout << "4,查找联系人" << endl;
	cout << "5,修改联系人" << endl;
	cout << "6,清空联系人" << endl;
	cout << "0,退出联系人" << endl;
}
struct person {
	string m_name;
	int m_sex;
	int m_age;
	string m_phone;
	string m_addr;
};
struct addressbooks
{
	struct person personarry[max];
	int m_size = 0;
};
void addperson(struct addressbooks* abs)
{
	if (abs->m_size == max)
	{
		cout << "满员了!" << endl;
		return;
	}
	else
	{
		string name, phone, addr;
		int age = 0, sex = 0;
		cout << "请输入名字" << endl;
		cin >> name;
		abs->personarry[abs->m_size].m_name = name;
		cout << "请输入性别" << endl;
		cout << "1=男" << endl;
		cout << "2=女" << endl;
		while (true)
		{
			cin >> sex;
			if (sex == 1 || sex == 2)
			{
				abs->personarry[abs->m_size].m_sex = sex;
				break;
			}
			else
				cout << "请重新输入:" << endl;
		}
		cout << "请输入年龄:" << endl;
		cin >> age;
		abs->personarry[abs->m_size].m_age = age;
		cout << "请输入电话:" << endl;
		cin >> phone;
		abs->personarry[abs->m_size].m_phone = phone;
		cout << "请输入地址:" << endl;
		cin >> addr;
		abs->personarry[abs->m_size].m_addr = addr;
		abs->m_size++;
		cout << "添加成功" << endl;
		system("pause");//请按任意键继续
		system("cls");//清屏操作   新知识
	}
}
void indicate(struct addressbooks abs)
{
	if (abs.m_size == 0)
		cout << "当前记录为空" << endl;
	else
		for (int i = 0; i < abs.m_size;i++)
	{
		cout <<"姓名:	"<< abs.personarry[i].m_name;
		cout << "	性别:	"<<(abs.personarry[i].m_sex==1?"男" : "女");
		cout << "	年龄:	"<<abs.personarry[i].m_age;
		cout << "	电话:	"<<abs.personarry[i].m_phone;
		cout << "	地址:	"<<abs.personarry[i].m_addr << endl;
	}
	system("pause");//请按任意键继续
	system("cls");//清屏操作   新知识
}
//判断联系人是否存在,还需要把人名传递过来
int  exist(struct addressbooks *abs,string  name)
{
	for (int i = 0; i < abs->m_size; i++)
		if (name == abs->personarry[i].m_name)
		{
			return i;
		}
	return -1;
}
void delectperson(struct addressbooks* abs)
{
	string name;
	cout << "请输入删除联系人:" << endl;
	cin >> name;
	int ret = exist(abs, name);
	if (ret == -1)
	{
		cout << "查无此人" << endl;
	}
	else
	{
		for (int j = ret; j < abs->m_size; j++)
		{
			abs->personarry[j] = abs->personarry[j + 1];
		}
		abs->m_size--;
		cout << "删除成功" << endl;
	}
	system("pause");//请按任意键继续
	system("cls");//清屏操作   新知识
}
void seekperson(struct addressbooks abs)
{
	string Name;
	cout << "请输入查找联系人:" << endl;
	cin >> Name;
	int ret =exist(&abs, Name);
	if (ret == -1)
	{
		cout << "查无此人" << endl;
	}
	else
	{
		cout << "姓名:	" << abs.personarry[ret].m_name;
		cout << "	性别:	" << (abs.personarry[ret].m_sex == 1 ? "男" : "女");
		cout << "	年龄:	" << abs.personarry[ret].m_age;
		cout << "	电话:	" << abs.personarry[ret].m_phone;
		cout << "	地址:	" << abs.personarry[ret].m_addr << endl;
	}
	
	system("pause");//请按任意键继续
	system("cls");//清屏操作   新知识

}
void modifyperson(struct addressbooks* abs)
{
	string cname;
	cout << "请输入要修改的联系人:" << endl;
	cin >> cname;
	int ret = exist(abs, cname);
	if (ret != -1)
	{

		cout << "请输入姓名:" << endl;
		string Cname;
		cin >> Cname;
		abs->personarry[ret].m_name = Cname;
		cout << "请输入性别:" << endl;
		cout << "1=男" << endl;
		cout << "2=女" << endl;
		int sex;
		while (true)
		{
			cin >> sex;
			if (sex == 1 || sex == 2)
			{
				abs->personarry[abs->m_size].m_sex = sex;
				break;
			}
			else
				cout << "请重新输入:" << endl;
		}
		abs->personarry[ret].m_sex = sex;
		cout << "请输入年龄:" << endl;
		int age;
		cin >> age;
		abs->personarry[ret].m_age = age;
		cout << "请输入电话:" << endl;
		string  phone;
		cin >> phone;
		abs->personarry[ret].m_phone = phone;
		cout << "请输入地址:" << endl;
		string addr;
		cin >> addr;
		abs->personarry[ret].m_addr = addr;
		cout << "修改完成" << endl;
	}
	else
	{
		cout << "查无此人" << endl;
	}
	system("pause");//请按任意键继续
	system("cls");//清屏操作   新知识
}
void cleanperson(struct addressbooks* abs)
{
	abs->m_size = 0;
	cout << "已清空" << endl;
	system("pause");//请按任意键继续
	system("cls");//清屏操作   新知识

}
int main()
{
	addressbooks abs;
	abs.m_size = 0;
	int select = 0;
	while (true)
	{
		showMenu();
		cin >> select;
		switch (select)
		{
		case 1://添加
			addperson(&abs);
			break;
		case 2://显示
			indicate(abs);
			break;
		case 3://删除
			delectperson(&abs);
			break;
		case 4://查找
			seekperson(abs);
			break;
		case 5://修改
			modifyperson(&abs);
			break;
		case 6://清空
			cleanperson(&abs);
			break;
		case 0://退出
			cout << "欢迎下次使用" << endl;
			system("pause");//按任意键的意思;
			return 0;//退出系统;
			break;
		default:
			cout << "请重新输入" << endl;
			break;//只是退出switch!!
		}
	}
	system("pause");
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#define _CRT_SECURE_NO_WARNINGS 1 #ifndef __CONTACT_H_ #define __CONTACT_H_ #include<stdio.h> #include<stdlib.h> #include<string.h> #define PEO_MAX 30 #define STUID_MAX 10 #define NAME_MAX 20 #define SEX_MAX 10 #define TEL_MAX 15 typedef struct People { char id[STUID_MAX]; char name[NAME_MAX]; char sex[SEX_MAX]; char tel[TEL_MAX]; }*peo; typedef struct Contact { int count; struct People people[PEO_MAX]; }*pCon; void add_peo(pCon pcon); //添加联系人信息 void show_peo(pCon pcon); //显示指定联系人信息 void find_peo(pCon pcon); //查找联系人信息 void modify_peo(pCon pcon); //修改指定联系人信息 void clear_peo(pCon pcon); //清空联系人信息 void show_menu(); //菜单显示 #endif int search(pCon pcon, char *name) { int i = 0; for (i=0; i < pcon->count; i++) { if (strcmp(name, pcon->people[i].name) == 0) return i; } return -1; } void add_peo(pCon pcon) //添加联系人 { if (pcon->count == PEO_MAX) { printf("The contact has fullen."); return; } printf("please input studentID: "); scanf("%s",(pcon->people[pcon->count]).id); printf("please input name: "); scanf("%s", (pcon->people[pcon->count]).name); printf("please input sex : "); scanf("%s", (pcon->people[pcon->count]).sex); printf("please input tel: "); scanf("%s", (pcon->people[pcon->count]).tel); pcon->count++; } void show_peo(pCon pcon)//显示联系人 { int i = 0; for (; i < pcon->count; i++) { printf("studentID name sex tel \n"); printf("%s\t%s\t%s\t%s\n", pcon->people[i].id, pcon->people[i].name, pcon->people[i].sex, pcon->people[i].tel); } } void find_peo(pCon pcon) //查找联系人信息 { int i; char name[NAME_MAX]; printf("please input the people you want to find:"); scanf("%s", name); i = search(pcon, name); if (i == -1) printf("The people doesn't exsit.\n"); else printf("%s\t%s\t%s\t%s\n", pcon->people[i].id, pcon->people[i].name, pcon->people[i].sex, pcon->people[i].tel); } void modify_peo(pCon pcon) //修改指定联系人信息 { int i; char name[NAME_MAX]; printf("please input the people you want to modify:"); scanf("%s", name); i = search(pcon, name); if (i == -1) printf("The people doesn't exsit.\n"); else printf("please input studentID: "); scanf("%s", (pcon->people[i]).id); printf("please input name: "); scanf("%s", (pcon->people[i]).name); printf("please input sex : "); scanf("%s", (pcon->people[i]).sex); printf("please input tel: "); scanf("%s", (pcon->people[i]).tel); } void clear_peo(pCon pcon) //清空联系人 { pcon->count = 0; } void show_menu() //菜单显示 { printf("==========通讯录==========\n"); printf(" \n"); printf("*******[1]显示通讯录******\n"); printf("*******[2]查 询******\n"); printf("*******[3]修 改******\n"); printf("*******[4]结 束******\n"); } int main() { struct Contact my_contact; int input = 1; my_contact.count = 0; while (input) { show_menu(); printf("please input:"); scanf("%d", &input;); switch (input) { case 1: add_peo(&my;_contact); break; case 2: show_peo(&my;_contact); break; case 3: find_peo(&my;_contact); break; case 4: modify_peo(&my;_contact); break; case 5: clear_peo(&my;_contact); break; default: break; } } return 0; }

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值