目录
一:前言
在当今这个高度互联的时代,信息的管理和组织变得尤为重要,尤其是在个人和职业生活中,有效的联系人管理能够极大地提升我们的效率和生活质量。为此,我们设计并开发了一款基于C++语言的通讯录管理系统,旨在为用户提供一个强大、灵活且用户友好的工具,帮助他们轻松管理个人和工作相关的联系信息。
二:
题目及要求: 通信录管理系统
一、问题描述:
联系人信息包括:姓名、英文姓名、公司、手机号、电子邮件、与本人关系。对一个有N个联系人的通信录,通过该系统实现对该通信录中联系人信息的录入、显示、查询、修改、删除、统计等操作。(“英文姓名”即姓名的拼音,“与本人关系”可枚举为“亲人”、“朋友”、“同学”、“同事”和“其他”,主要作用是为联系人分组。)
二、功能要求:
本系统需要实现以下功能
(1)联系人信息录入(执行一次菜单录入一个联系人信息)
(2)联系人信息显示(显示所有联系人信息)
(3)联系人信息查询(分别按姓名和与本人关系查询)
(4) 联系人信息删除 (按姓名)
(5) 联系人信息修改(按姓名)
(6)联系人信息排序(按英文姓名字典顺序)
(7)联系人信息统计(按“与本人关系”统计人数)
(8)退出系统
三:系统功能代码
1.联系人信息录入
void input(Person person[]) // 联系人信息录入
{
int num = 0;
cout << "------------请开始输入-------------" << endl;
cout << " 请输入将录入系统的人数: ";
cin >> num ; cout << endl;
for (int i = num; i>0; i--) // 巧妙地index
{
cout << "请输入联系人姓名: "; cin >> name;
person[index].setname(name);
cout << "请输入联系人英文姓名: "; cin >> ename;
person[index].setename(ename);
cout << "请输入与联系人关系: "; cin >> relationship;
person[index].setrelationship(relationship);
cout << "请输入联系人电话: "; cin >> phone;
person[index].setphone(phone);
cout << "请输入联系人地址: "; cin >> address;
person[index].setaddress(address);
cout << "请输入联系人邮箱: "; cin >> email;
person[index].setemail(email);
cout << "请输入联系人公司: "; cin >> company;
person[index].setcompany(company);
index++;
cout << endl;
}
cout << "完成操作!" << endl;
}
2.查询所有人信息
void show_all( Person person[]) //查询所有人的信息
{
for (int i = 0; i < index; i++)
{
cout << "姓名: " << person[i].getname() << endl;
cout << "英文姓名:" << person[i].getename() << endl;
cout << "关系: " << person[i].getrelationship() << endl;
cout << "电话: " << person[i].getphone() << endl;
cout << "地址: " << person[i].getaddress() << endl;
cout << "邮箱: " << person[i].getemail() << endl;
cout << "公司: " << person[i].getcompany() << endl;
cout << endl;
}
}
3.特定查询联系人
void search(Person person[]) // 特定查询
{
int num , flag = 0;
cout << "1:姓名查找||2:关系关系" << endl;
cout << "请输入: "; cin >> num;
switch (num)
{
case 1: {
cout << "请输入姓名: "; cin >> name;
{ for (int i = 0; i < index; i++)
{
if (name == person[i].getname())
{
cout << "姓名: " << person[i].getname() << endl;
cout << "英文姓名:" << person[i].getename() << endl;
cout << "关系: " << person[i].getrelationship() << endl;
cout << "电话: " << person[i].getphone() << endl;
cout << "地址: " << person[i].getaddress() << endl;
cout << "邮箱: " << person[i].getemail() << endl;
cout << "公司: " << person[i].getcompany() << endl;
flag++;
}
}
}
if(flag==0)
cout << "查无此人!" << endl;
break;
}
case 2: {
cout << "请输入关系: "; cin >> relationship;
{
for (int i = 0; i < index; i++)
{
if (relationship == person[i].getrelationship())
{
cout << "姓名: " << person[i].getname() << endl;
cout << "英文姓名:" << person[i].getename() << endl;
cout << "关系: " << person[i].getrelationship() << endl;
cout << "电话: " << person[i].getphone() << endl;
cout << "地址: " << person[i].getaddress() << endl;
cout << "邮箱: " << person[i].getemail() << endl;
cout << "公司: " << person[i].getcompany() << endl;
cout << endl;
flag++;
}
}
}
if(flag==0)
cout << "无此关系的联系人!" << endl;
break;
}
}
}
4.修改联系人信息
void modify(Person person[])
{
int num , flag = 0;
do {
cout << "输入姓名修改: "; cin >> name;
for (int i = 0; i < index; i++)
{
if (name == person[i].getname())
{
cout << "请输入需要修改的信息: \n"
<< "1.关系\n"
<< "2.电话\n"
<< "3.邮件\n"
<< "4.地址\n"
<< "5.公司\n"
<< "6.姓名\n"
<< "7.英文姓名\n";
while (1)
{
cout << "请选择需要执行的功能序号(1-7):"; cin >> num;
if (num > 0 && num < 8)
break;
else
cout << "命令无效,请重试!" << endl;;
}
cout << endl;
switch (num)
{
case 1: {
cout << "请输入修改后的关系:"; cin >> relationship;
person[i].setrelationship(relationship);
break;
}
case 2: {
cout << "请输入修改后的电话:"; cin >> phone;
person[i].setphone(phone);
break;
}
case 3: {
cout << "请输入修改后的邮件:"; cin >> email;
person[i].setemail(email);
break;
}
case 4: {
cout << "请输入修改后的地址:"; cin >> address;
person[i].setaddress(address);
break;
}
case 5: {
cout << "请输入修改后的公司:"; cin >> company;
person[i].setcompany(company);
break;
}
case 6: {
cout << "请输入修改后的姓名:"; cin >> name;
person[i].setname(name);
break;
}
case 7: {
cout << "请输入修改后的英文姓名:"; cin >> ename;
person[i].setename(ename);
break;
}
}
flag++;
}
}
if(flag==0)
cout << "查无此人!" << endl;
while (1)
{
cout << "重新修改请输入1\t返回目录输入0" << endl;
cin >> num;
if (num==1||num==0)
break;
else
cout << "命令无效,请重试!" << endl;;
}
} while (num);
}
5.联系人信息排列
考虑到大多数读者是新手小白,完成大学作业。使所以这里我就不使用STL里的sort,而使用冒泡排列。
void arrange(Person person[]) //用冒泡排列排序
{
for (int i = 0; i < index - 1; i++)
{
for (int j = 0; j < index - 1 - i; j++)
{
if (person[i].getename() >person[i + 1].getename())
{
ename = person[i].getename();
person[i].setename(person[i + 1].getename());
person[i + 1].setename(ename);
name = person[i].getname();
person[i].setname(person[i+1].getname());
person[i+1].setname(name);
email = person[i].getemail();
person[i].setemail(person[i + 1].getemail());
person[i + 1].setemail(email);
phone = person[i].getphone();
person[i].setphone(person[i + 1].getphone());
person[i + 1].setphone(phone);
address = person[i].getaddress();
person[i].setaddress(person[i + 1].getaddress());
person[i + 1].setaddress(address);
relationship = person[i].getrelationship();
person[i].setrelationship(person[i + 1].getrelationship());
person[i + 1].setrelationship(relationship);
company = person[i].getcompany();
person[i].setcompany(person[i + 1].getcompany());
person[i + 1].setcompany(company);
}
}
}
for (int i = 0; i < index; i++)
{
cout << "姓名: " << person[i].getname() << endl;
cout << "英文姓名:" << person[i].getename() << endl;
cout << "关系: " << person[i].getrelationship() << endl;
cout << "电话: " << person[i].getphone() << endl;
cout << "地址: " << person[i].getaddress() << endl;
cout << "邮箱: " << person[i].getemail() << endl;
cout << "公司: " << person[i].getcompany() << endl;
cout << endl;
}
}
6.联系人信息删除
void erase(Person person[]) //删除特定联系人
{
int num , flag = 0;
do {
cout << "输入姓名删除: "; cin >> name;
for (int i = 0; i < index; i++)
{
if (name == person[i].getname())
{
person[i].setname(person[i + 1].getname());
person[i].setename(person[i + 1].getename());
person[i].setemail(person[i + 1].getemail());
person[i].setphone(person[i + 1].getphone());
person[i].setrelationship(person[i + 1].getrelationship());
person[i].setaddress(person[i + 1].getaddress());
person[i].setcompany(person[i + 1].getcompany());
flag++;
}
}
if(flag==0)
cout << "查无此人!" << endl;
while (1)
{
cout << "重新修改请输入1\t返回目录输入0" << endl;
cin >> num;
if (num == 1 || num == 0)
break;
else
cout << "命令无效,请重试!" << endl;;
}
index--; //这里是重点
} while (num);
}
目录
void count(Person person[]) // 统计与本人关系的人数
{
int num;
do {
int total = 0; // 这里total必须是do while里的局部变量
cout << "输入与本人的关系: "; cin >> relationship ;
for (int i = 0; i < index; i++)
{
if (relationship == person[i].getrelationship())
{
total++;
}
}
cout << "与本人关系" << relationship << "共: " << total << "人" << endl;
while (1)
{
cout << "重新统计请输入1\t返回目录输入0" << endl;
cin >> num;
if (num == 1 || num == 0)
break;
else
cout << "命令无效,请重试!" << endl;;
}
} while (num);
}
四:源代码
#include<iostream>
#include<string>
#include<windows.h>
using namespace std;
class Person {
private:
string name;
string email;
string phone;
string address;
string company;
string relationship;
string ename;
public:
void setename(string ename)
{
this->ename = ename;
}
void setname(string name)
{
this->name = name;
}
void setemail(string email)
{
this->email = email;
}
void setphone(string phone)
{
this->phone = phone;
}
void setaddress(string address)
{
this->address = address;
}
void setcompany(string company)
{
this->company = company;
}
void setrelationship(string relationship)
{
this->relationship = relationship;
}
string getname()
{
return name;
}
string getemail()
{
return email;
}
string getaddress()
{
return address;
}
string getcompany()
{
return company;
}
string getrelationship()
{
return relationship;
}
string getphone()
{
return phone;
}
string getename()
{
return ename;
}
};
int index = 0; //索引脚标
Person person[50]; // 默认最大存储五十个人
string name;
string email;
string address;
string company;
string relationship;
string phone;
string ename;
void input(Person person[]) // 联系人信息录入
{
int num = 0;
cout << "------------请开始输入-------------" << endl;
cout << " 请输入将录入系统的人数: ";
cin >> num ; cout << endl;
for (int i = num; i>0; i--) // 巧妙地index
{
cout << "请输入联系人姓名: "; cin >> name;
person[index].setname(name);
cout << "请输入联系人英文姓名: "; cin >> ename;
person[index].setename(ename);
cout << "请输入与联系人关系: "; cin >> relationship;
person[index].setrelationship(relationship);
cout << "请输入联系人电话: "; cin >> phone;
person[index].setphone(phone);
cout << "请输入联系人地址: "; cin >> address;
person[index].setaddress(address);
cout << "请输入联系人邮箱: "; cin >> email;
person[index].setemail(email);
cout << "请输入联系人公司: "; cin >> company;
person[index].setcompany(company);
index++;
cout << endl;
}
cout << "完成操作!" << endl;
}
void show_all( Person person[]) //查询所有人的信息
{
for (int i = 0; i < index; i++)
{
cout << "姓名: " << person[i].getname() << endl;
cout << "英文姓名:" << person[i].getename() << endl;
cout << "关系: " << person[i].getrelationship() << endl;
cout << "电话: " << person[i].getphone() << endl;
cout << "地址: " << person[i].getaddress() << endl;
cout << "邮箱: " << person[i].getemail() << endl;
cout << "公司: " << person[i].getcompany() << endl;
cout << endl;
}
}
void search(Person person[]) // 特定查询
{
int num , flag = 0;
cout << "1:姓名查找||2:关系关系" << endl;
cout << "请输入: "; cin >> num;
switch (num)
{
case 1: {
cout << "请输入姓名: "; cin >> name;
{ for (int i = 0; i < index; i++)
{
if (name == person[i].getname())
{
cout << "姓名: " << person[i].getname() << endl;
cout << "英文姓名:" << person[i].getename() << endl;
cout << "关系: " << person[i].getrelationship() << endl;
cout << "电话: " << person[i].getphone() << endl;
cout << "地址: " << person[i].getaddress() << endl;
cout << "邮箱: " << person[i].getemail() << endl;
cout << "公司: " << person[i].getcompany() << endl;
flag++;
}
}
}
if(flag==0)
cout << "查无此人!" << endl;
break;
}
case 2: {
cout << "请输入关系: "; cin >> relationship;
{
for (int i = 0; i < index; i++)
{
if (relationship == person[i].getrelationship())
{
cout << "姓名: " << person[i].getname() << endl;
cout << "英文姓名:" << person[i].getename() << endl;
cout << "关系: " << person[i].getrelationship() << endl;
cout << "电话: " << person[i].getphone() << endl;
cout << "地址: " << person[i].getaddress() << endl;
cout << "邮箱: " << person[i].getemail() << endl;
cout << "公司: " << person[i].getcompany() << endl;
cout << endl;
flag++;
}
}
}
if(flag==0)
cout << "无此关系的联系人!" << endl;
break;
}
}
}
void modify(Person person[])
{
int num , flag = 0;
do {
cout << "输入姓名修改: "; cin >> name;
for (int i = 0; i < index; i++)
{
if (name == person[i].getname())
{
cout << "请输入需要修改的信息: \n"
<< "1.关系\n"
<< "2.电话\n"
<< "3.邮件\n"
<< "4.地址\n"
<< "5.公司\n"
<< "6.姓名\n"
<< "7.英文姓名\n";
while (1)
{
cout << "请选择需要执行的功能序号(1-7):"; cin >> num;
if (num > 0 && num < 8)
break;
else
cout << "命令无效,请重试!" << endl;;
}
cout << endl;
switch (num)
{
case 1: {
cout << "请输入修改后的关系:"; cin >> relationship;
person[i].setrelationship(relationship);
break;
}
case 2: {
cout << "请输入修改后的电话:"; cin >> phone;
person[i].setphone(phone);
break;
}
case 3: {
cout << "请输入修改后的邮件:"; cin >> email;
person[i].setemail(email);
break;
}
case 4: {
cout << "请输入修改后的地址:"; cin >> address;
person[i].setaddress(address);
break;
}
case 5: {
cout << "请输入修改后的公司:"; cin >> company;
person[i].setcompany(company);
break;
}
case 6: {
cout << "请输入修改后的姓名:"; cin >> name;
person[i].setname(name);
break;
}
case 7: {
cout << "请输入修改后的英文姓名:"; cin >> ename;
person[i].setename(ename);
break;
}
}
flag++;
}
}
if(flag==0)
cout << "查无此人!" << endl;
while (1)
{
cout << "重新修改请输入1\t返回目录输入0" << endl;
cin >> num;
if (num==1||num==0)
break;
else
cout << "命令无效,请重试!" << endl;;
}
} while (num);
}
void arrange(Person person[]) //用冒泡排列排序
{
for (int i = 0; i < index - 1; i++)
{
for (int j = 0; j < index - 1 - i; j++)
{
if (person[i].getename() >person[i + 1].getename())
{
ename = person[i].getename();
person[i].setename(person[i + 1].getename());
person[i + 1].setename(ename);
name = person[i].getname();
person[i].setname(person[i+1].getname());
person[i+1].setname(name);
email = person[i].getemail();
person[i].setemail(person[i + 1].getemail());
person[i + 1].setemail(email);
phone = person[i].getphone();
person[i].setphone(person[i + 1].getphone());
person[i + 1].setphone(phone);
address = person[i].getaddress();
person[i].setaddress(person[i + 1].getaddress());
person[i + 1].setaddress(address);
relationship = person[i].getrelationship();
person[i].setrelationship(person[i + 1].getrelationship());
person[i + 1].setrelationship(relationship);
company = person[i].getcompany();
person[i].setcompany(person[i + 1].getcompany());
person[i + 1].setcompany(company);
}
}
}
for (int i = 0; i < index; i++)
{
cout << "姓名: " << person[i].getname() << endl;
cout << "英文姓名:" << person[i].getename() << endl;
cout << "关系: " << person[i].getrelationship() << endl;
cout << "电话: " << person[i].getphone() << endl;
cout << "地址: " << person[i].getaddress() << endl;
cout << "邮箱: " << person[i].getemail() << endl;
cout << "公司: " << person[i].getcompany() << endl;
cout << endl;
}
}
void erase(Person person[]) //删除特定联系人
{
int num , flag = 0;
do {
cout << "输入姓名删除: "; cin >> name;
for (int i = 0; i < index; i++)
{
if (name == person[i].getname())
{
person[i].setname(person[i + 1].getname());
person[i].setename(person[i + 1].getename());
person[i].setemail(person[i + 1].getemail());
person[i].setphone(person[i + 1].getphone());
person[i].setrelationship(person[i + 1].getrelationship());
person[i].setaddress(person[i + 1].getaddress());
person[i].setcompany(person[i + 1].getcompany());
flag++;
}
}
if(flag==0)
cout << "查无此人!" << endl;
while (1)
{
cout << "重新修改请输入1\t返回目录输入0" << endl;
cin >> num;
if (num == 1 || num == 0)
break;
else
cout << "命令无效,请重试!" << endl;;
}
index--; //这里是重点
} while (num);
}
void count(Person person[]) // 统计与本人关系的人数
{
int num;
do {
int total = 0; // 这里total必须是do while里的局部变量
cout << "输入与本人的关系: "; cin >> relationship ;
for (int i = 0; i < index; i++)
{
if (relationship == person[i].getrelationship())
{
total++;
}
}
cout << "与本人关系" << relationship << "共: " << total << "人" << endl;
while (1)
{
cout << "重新统计请输入1\t返回目录输入0" << endl;
cin >> num;
if (num == 1 || num == 0)
break;
else
cout << "命令无效,请重试!" << endl;;
}
} while (num);
}
int main()
{
int num = 0;
do
{
cout << "-----------------------------\n" //主界面主菜单menu
<< " \t通讯录管理系统\n"
<< " 1.\t联系人信息录入\n"
<< " 2.\t联系人信息显示(all)\n"
<< " 3.\t联系人信息查询\n"
<< " 4.\t联系人信息修改\n"
<< " 5.\t联系人信息排列\n"
<< " 6.\t联系人信息删除\n"
<< " 7.\t联系人信息统计\n"
<< " 0.\t退出系统\n\n"
<< "------------------------------" << endl;
while (1)
{
cout << "请选择需要执行的功能序号(1-5):"; cin >> num;
if (num > 0 && num < 9)
break;
else
cout << "命令无效,请重试!" << endl;;
}
switch (num)
{
case 1: {
input(person);
system("pause");
system("cls");
break;
}
case 2: {
show_all(person);
system("pause");
system("cls");
break;
}
case 3: {
search(person);
system("pause");
system("cls");
break;
}
case 4:{
modify(person);
system("pause");
system("cls");
break;
}
case 5: {
arrange(person);
system("pause");
system("cls");
break;
}
case 6: {
erase(person);
system("pause");
system("cls");
break;
}
case 7: {
count(person);
system("pause");
system("cls");
break;
}
}
} while (num);
return 0;
}