我可不是高手,刚刚学习而已 ,我的是通讯录的管理系统,只可以借鉴,不能抄的,自己看看 ,这个程序都差不多一个样子 不会的话 多多交流, 最后还希望给个最佳答案
#include <iostream>
#include <string>
#define MAX 1000
using namespace std;
void showMenu(); //打印欢迎界面
void addition(struct Contacts contacts[]); //添加联系人
void show(struct Contacts contacts[]); //显示联系人
void deleteition(struct Contacts contacts[]); //删除联系人
void loctition(struct Contacts contacts[]); //查找联系人
void change(struct Contacts contacts[]); //修改联系人
void empty(); //清空联系人
struct Contacts
{
string m_Name;
string m_Sex;
string m_Age;
string m_Phone;
string m_Address;
};
int g_count = 0;
void showMenu()
{
cout << "*******************************************" << endl;
cout << "************** 1、添加联系人 **************" << endl;
cout << "************** 2、显示联系人 **************" << endl;
cout << "************** 3、删除联系人 **************" << endl;
cout << "************** 4、查找联系人 **************" << endl;
cout << "************** 5、修改联系人 **************" << endl;
cout << "************** 6、清空联系人 **************" << endl;
cout << "************** 0、退出通讯录 **************" << endl;
cout << "*******************************************" << endl;
}
void addition(struct Contacts contacts[])
{
cout << "请输入姓名:";
cin >> contacts[g_count].m_Name;
cout << "请输入性别:";
cin >> contacts[g_count].m_Sex;
cout << "请输入年龄:";
cin >> contacts[g_count].m_Age;
cout << "请输入电话:";
cin >> contacts[g_count].m_Phone;
cout << "请输入地址:";
cin >> contacts[g_count].m_Address;
g_count++;
}
void show(struct Contacts contacts[])
{
if(g_count == 0)
{
cout << "您还没有联系人,请添加..." << endl;
cout << endl;
return;
}
else
{
for(int i = 0; i < g_count; i++)
{
cout << "姓名:" << contacts[i].m_Name
<< "\t性别:" << contacts[i].m_Sex
<< "\t年龄:" << contacts[i].m_Age
<< "\t电话:" << contacts[i].m_Phone
<< "\t地址:" << contacts[i].m_Address << endl;
}
}
}
void deleteition(struct Contacts contacts[])
{
string deletename;
cout << "请输入删除联系人的姓名:";
cin >> deletename;
for(int i = 0; i < g_count; i++)
{
if(deletename == contacts[i].m_Name)
{
for(int j = i; j < g_count-1; j++)
{
contacts[j] = contacts[j+1];
}
cout << "删除成功!" << endl;
g_count--;
return;
}
}
cout << "删除失败!" << endl;
cout << "原因:没有找到该联系人" << endl;
return;
}
void loctition(struct Contacts contacts[])
{
string deletename;
cout << "请输入查找联系人的姓名:";
cin >> deletename;
for(int i = 0; i < g_count; i++)
{
if(deletename == contacts[i].m_Name)
{
cout << "姓名:" << contacts[i].m_Name
<< "\t性别:" << contacts[i].m_Sex
<< "\t年龄:" << contacts[i].m_Age
<< "\t电话:" << contacts[i].m_Phone
<< "\t地址:" << contacts[i].m_Address << endl;
return;
}
}
cout << "抱歉,没有找到该联系人!" << endl;
}
void change(struct Contacts contacts[])
{
string deletename;
cout << "请输入修改联系人的姓名:";
cin >> deletename;
for(int i = 0; i < g_count; i++)
{
if(deletename == contacts[i].m_Name)
{
cout << "请输入姓名:";
cin >> contacts[i].m_Name;
cout << "请输入性别:";
cin >> contacts[i].m_Sex;
cout << "请输入年龄:";
cin >> contacts[i].m_Age;
cout << "请输入电话:";
cin >> contacts[i].m_Phone;
cout << "请输入地址:";
cin >> contacts[i].m_Address;
cout << "修改成功" << endl;
return;
}
}
cout << "抱歉,没有找到该联系人!" << endl;
return;
}
void empty()
{
if(g_count == 0)
{
cout << "你当前没有任何联系人,已是清空状态" << endl;
}
else
{
g_count = 0;
cout << "通讯录已清空" << endl;
}
}
int main()
{
int order = 0;
struct Contacts contacts[MAX];
while(true)
{
showMenu();
cout << "请输入你要操作功能的序号:";
cin >> order;
while(order < 0 || order > 6)
{
cout << "输入错误,请重新输入:";
cin >> order;
}
switch(order)
{
case 1:
addition(contacts);
break;
case 2:
show(contacts);
system("pause");
break;
case 3:
deleteition(contacts);
system("pause");
break;
case 4:
loctition(contacts);
system("pause");
break;
case 5:
change(contacts);
system("pause");
break;
case 6:
empty();
system("pause");
break;
case 0:
cout << "欢迎下次使用" << endl;
return 0;
}
system("CLS");
}
return 0;
}
|