C++学习笔记:通讯录管理系统-创新互联
功能描述:
1、可以添加一定数量的联系人信息,包括(姓名、性别、年龄、电话、住址);
2、展示通讯录中所有联系人信息;
3、删除指定联系人;
4、在通讯录中查找指定联系人;
5、编辑通讯录中指定联系人信息;
6、清除通讯录中所有联系人信息;
源代码
分享名称:C++学习笔记:通讯录管理系统-创新互联
文章出自:http://myzitong.com/article/dpsohj.html
#include#includeusing namespace std;
#define MAX 1000
struct Person
{string m_Name;
string m_Sex;
int m_Age;
string m_Phone;
string m_Address;
};
struct AddressBooks
{struct Person personArray[MAX];
int m_Size;
};
void show_Menu()
{cout<< "****************************"<< endl;
cout<< "***** 1 Add a contact ******"<< endl;
cout<< "***** 2 Show a contact *****"<< endl;
cout<< "***** 3 Delete a contact ***"<< endl;
cout<< "***** 4 Find a contact *****"<< endl;
cout<< "***** 5 Edit a contact *****"<< endl;
cout<< "***** 6 Clear all contact **"<< endl;
cout<< "***** 0 Exit Address book **"<< endl;
cout<< "****************************"<< endl;
}
void Add_Contact(AddressBooks* Adr_B)
{if (Adr_B->m_Size == MAX)
{cout<< "Ops!! Address is full!!"<< endl;
return;
}
else
{string name;
cout<< "Please input name:"<< endl;
cin >>name;
Adr_B->personArray[Adr_B->m_Size].m_Name = name;
cout<< "Please input sex: (1 : women, 2 : man)"<< endl;
while (true)
{int sex = 0;
cin >>sex;
if (sex == 1)
{Adr_B->personArray[Adr_B->m_Size].m_Sex = "woman";
break;
}
else if (sex == 2)
{Adr_B->personArray[Adr_B->m_Size].m_Sex = "man";
break;
}
else
{cout<< "Input error! Please input 1 or 2"<< endl;
}
}
cout<< "Please input age :"<< endl;
while (true)
{int age = 0;
cin >>age;
if (age >0 && age< 110)
{Adr_B->personArray[Adr_B->m_Size].m_Age = age;
break;
}
else
{cout<< "Input error! Please check your input!"<< endl;
}
}
string phone_number;
cout<< "Please input phone_number:"<< endl;
cin >>phone_number;
Adr_B->personArray[Adr_B->m_Size].m_Phone = phone_number;
string Address;
cout<< "Please input Address: "<< endl;
cin >>Address;
Adr_B->personArray[Adr_B->m_Size].m_Address = Address;
Adr_B->m_Size++;
cout<< "Add contact successful!"<< endl;
}
system("pause");
system("cls");
}
void Show_contact(AddressBooks* Adr_B)
{if (Adr_B->m_Size == 0)
{cout<< "AddressBooks is empty!"<< endl;
}
else
{for (int i = 0; i< Adr_B->m_Size; ++i)
{cout<< "Name: "<< Adr_B->personArray[i].m_Name<< "\t"
<< "Sex : "<< Adr_B->personArray[i].m_Sex<< "\t"
<< "Age : "<< Adr_B->personArray[i].m_Age<< "\t"
<< "Phone : "<< Adr_B->personArray[i].m_Phone<< "\t"
<< "Address : "<< Adr_B->personArray[i].m_Address<< endl;
}
}
system("pause");
system("cls");
}
int Exist_check(AddressBooks* Adr_B, string name)
{for (int i = 0; i< Adr_B->m_Size; ++i)
{if (Adr_B->personArray[i].m_Name == name)
{return i;
}
}
return -1;
}
void Delete_contact(AddressBooks* Adr_B)
{cout<< "Please input the contact name to delete :"<< endl;
string name;
cin >>name;
int check_return = Exist_check(Adr_B, name);
if (check_return != -1)
{for (int i = check_return; i< Adr_B->m_Size; ++i)
{Adr_B->personArray[i] = Adr_B->personArray[i + 1];
}
Adr_B->m_Size--;
cout<< "Delete complete!"<< endl;
}
else
{cout<< "This person is not in the address book"<< endl;
}
system("pause");
system("cls");
}
void Find_contact(AddressBooks* Adr_B)
{cout<< "Please input the contact name to search :"<< endl;
string name;
cin >>name;
int check_return = Exist_check(Adr_B, name);
if (check_return != -1)
{cout<< "Name: "<< Adr_B->personArray[check_return].m_Name<< "\t"
<< "Sex : "<< Adr_B->personArray[check_return].m_Sex<< "\t"
<< "Age : "<< Adr_B->personArray[check_return].m_Age<< "\t"
<< "Phone : "<< Adr_B->personArray[check_return].m_Phone<< "\t"
<< "Address : "<< Adr_B->personArray[check_return].m_Address<< endl;
}
else
{cout<< "This person is not in the address book"<< endl;
}
system("pause");
system("cls");
}
void Edit_contact(AddressBooks* Adr_B)
{cout<< "Please input the contact name to Edit :"<< endl;
string name;
cin >>name;
int check_return = Exist_check(Adr_B, name);
if (check_return != -1)
{string name;
cout<< "Please input name:"<< endl;
cin >>name;
Adr_B->personArray[check_return].m_Name = name;
cout<< "Please input sex: (1 : women, 2 : man)"<< endl;
int sex = 0;
while (true)
{cin >>sex;
if (sex == 1)
{Adr_B->personArray[check_return].m_Sex = "woman";
break;
}
else if (sex == 2)
{Adr_B->personArray[check_return].m_Sex = "man";
break;
}
else
{cout<< "Input error! Please input 1 or 2"<< endl;
}
}
cout<< "Please input age :"<< endl;
while (true)
{int age = 0;
cin >>age;
if (age >0 && age< 110)
{Adr_B->personArray[check_return].m_Age = age;
break;
}
else
{cout<< "Input error! Please check your input!"<< endl;
}
}
string phone_number;
cout<< "Please input phone_number:"<< endl;
cin >>phone_number;
Adr_B->personArray[check_return].m_Phone = phone_number;
string Address;
cout<< "Please input Address: "<< endl;
cin >>Address;
cout<< "Edit contact successful!"<< endl;
}
else
{cout<< "This person is not in the address book"<< endl;
}
system("pause");
system("cls");
}
void Clear_contact(AddressBooks* Adr_B)
{cout<< "Please confirm again whether to clear the address book!!"<< endl;
cout<< "Clear ------ 1"<< endl;
cout<< "Cancel------ 2"<< endl;
int Clear_check = 0;
cin >>Clear_check;
if (Clear_check == 1)
{Adr_B->m_Size = 0;
cout<< "Address book cleared"<< endl;
}
system("pause");
system("cls");
}
int main()
{AddressBooks Adr_B;
int select = 0;
Adr_B.m_Size = 0;
while (true)
{show_Menu();
cin >>select;
switch (select)
{case 1: // add contact
Add_Contact(&Adr_B);
break;
case 2: // show contact
Show_contact(&Adr_B);
break;
case 3: // delete contact
Delete_contact(&Adr_B);
break;
case 4: // find contact
Find_contact(&Adr_B);
break;
case 5: //edit contact
Edit_contact(&Adr_B);
break;
case 6: //clear contact
Clear_contact(&Adr_B);
break;
case 0: // exit system
cout<< "Thanks for using Address book management system"<< endl;
return 0;
break;
default:
break;
}
}
return 0;
}
功能展示
1、初始界面展示我们注重客户提出的每个要求,我们充分考虑每一个细节,我们积极的做好网站制作、成都网站建设服务,我们努力开拓更好的视野,通过不懈的努力,创新互联赢得了业内的良好声誉,这一切,也不断的激励着我们更好的服务客户。 主要业务:网站建设,网站制作,网站设计,重庆小程序开发,网站开发,技术开发实力,DIV+CSS,PHP及ASP,ASP.Net,SQL数据库的技术开发工程师。2、添加一定数量的联系人信息,包括(姓名、性别、年龄、电话、住址);2、展示通讯录中所有联系人信息;3、删除指定联系人;
3.1 无联系人返回错误信息3.2 有联系人进行删除操作,提示成功信息;你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
分享名称:C++学习笔记:通讯录管理系统-创新互联
文章出自:http://myzitong.com/article/dpsohj.html