脚本宝典收集整理的这篇文章主要介绍了【黑马程序员】通讯录管理系统----个人改良版(附带程序打包),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
#include<iostream> using namespace std;
#define Max 1000
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; }
struct PErson { string p_name; int p_gender = 0; int p_age = 0; string p_phone; string p_addr; };
struct addressBook { struct person personArray[Max]; int p_size; };
void addperson(struct addressbook* ab) { if (ab->p_size == Max) { cout << "您输入的联系人信息已达最大值" << endl; return; } else { string name; cout << "请输入该联系人姓名" << endl; cin >> name; ab->personArray[ab->p_size].p_name = name;
int gender = 0; cout << "请输入该联系人性别" << endl; cout << "1、男" << endl; cout << "2、女" << endl; cin >> gender;
while (true) { if (gender == 1 || gender == 2) { ab->personArray[ab->p_size].p_gender = gender; break; } cout << "请输入正确的性别。" << endl; cin >> gender; }
int age = 0; cout << "请输入该联系人年龄" << endl; cin >> age; ab->personArray[ab->p_size].p_age = age;
string phone; cout << "请输入该联系人手机号码" << endl; cin >> phone; ab->personArray[ab->p_size].p_phone = phone;
string addr; cout << "请输入该联系人地址" << endl; cin >> addr; ab->personArray[ab->p_size].p_addr = addr;
ab->p_size++;
cout << "添加成功!" << endl;
System("pause"); system("cls"); } }
void showperson(struct addressbook* ab) { if (ab->p_size == 0) { cout << "当前记录为空" << endl; } else { for (int i = 0; i < ab->p_size; i++) { cout << "姓名F1a;" << ab->personArray[i].p_name << "t" << "性别:" << (ab->personArray[i].p_gender == 1 ? "男" : "女") << "t" << "年龄:" << ab->personArray[i].p_age << "t" << "电话:" << ab->personArray[i].p_phone << "t" << "地址:" << ab->personArray[i].p_addr << endl; } } system("pause"); system("cls"); }
int exist(addressbook* ab, string name) { for (int i = 0; i < ab->p_size; i++) { if (ab->personArray[i].p_name == name) { return i; } } return -1; }
void deleteperson(addressbook* ab) { cout << "请输入您要删除的联系人" << endl;
string name; cin >> name;
int ret = exist(ab, name);
if (ret != -1) { for (int i = ret; i < ab->p_size; i++) { ab->personArray[i] = ab->personArray[i + 1];//数据前移 } ab->p_size--; cout << "删除成功" << endl; } else { cout << "查无此人" << endl; } system("pause"); system("cls"); }
void findperson(addressbook* ab) { string name; cout << "请输入您要查找人的姓名" << endl; cin >> name;
int ret = exist(ab, name);
if (ret == -1) { cout << "查无此人" << endl; } else { cout << "姓名:" << ab->personArray[ret].p_name << "t" << "性别:" << (ab->personArray[ret].p_gender == 1 ? "男" : "女") << "t" << "年龄:" << ab->personArray[ret].p_age << "t" << "电话:" << ab->personArray[ret].p_phone << "t" << "地址:" << ab->personArray[ret].p_addr << endl; }
system("pause"); system("cls"); }
void modifyperson(addressbook* ab) { cout << "请输入您要查找人的姓名" << endl; string name; cin >> name;
int ret = exist(ab, name);
if (ret == -1) { cout << "查无此人" << endl; system("pause"); system("cls"); } else { cout << "请输入您要修改的联系人姓名" << endl; string new_name; cin >> new_name; ab->personArray[ret].p_name = new_name;
cout << "请输入您要修改的联系人性别" << endl; cout << "1、男" << endl; cout << "2、女" << endl; int new_gender; cin >> new_gender; while (true) { cin >> new_gender; if (new_gender == 1 || new_gender == 2) { ab->personArray[ret].p_gender = new_gender; break; } else { cout << "输入有误,请重新输入" << endl; } } cout << "请输入您要修改的联系人年龄" << endl; int new_age; cin >> new_age; ab->personArray[ret].p_age = new_age;
cout << "请输入您要修改的联系人手机号码" << endl; string new_phone; cin >> new_phone; ab->personArray[ret].p_phone = new_phone;
cout << "请输入您要修改的联系人地址" << endl; string new_addr; cin >> new_addr; ab->personArray[ret].p_addr = new_addr;
cout << "修改成功" << endl;
system("pause"); system("cls"); } }
void cleanpeople(addressbook* ab) { cout << "您是否要进行清空操作?" << endl; cout << "如果是(清空操作),请按1;不是,输入任意其他数字返回" << endl; int flag = 0; cin >> flag; if (flag == 1) { cout << "如果是(清空操作),请按2;不是,输入任意其他数字返回" << endl; cin >> flag; if (flag == 2) { cout << "如果是(清空操作),请按3;不是,输入任意其他数字返回" << endl; cin >> flag; if (flag == 3) { ab->p_size = 0; cout << "清空完成" << endl; } } } system("pause"); system("cls"); }
int main() { addressbook ab;
ab.p_size = 0; int select = 0;
while (true) { showMenu();
cin >> select;
swITch (select) { case 1://添加 addperson(&ab); break;
case 2://显示 showperson(&ab); break;
case 3://删除 /*{ cout << "请输入删除联系人的姓名" << endl; string name; cin >> name;
if (exist(&ab, name) == -1) { cout << "查无此人" << endl; } else { cout << "找到此人" << endl; } }*/ deleteperson(&ab); break;
case 4://查找 findperson(&ab); break;
case 5://修改 modifyperson(&ab); break;
case 6://清空 cleanpeople(&ab); break;
case 0://退出 cout << "欢迎下次使用" << endl; system("pause"); return 0; break; default: cout << "请输入合适的数" << endl; } } system("pause"); return 0; }
程序打包方法:
1,扩展--管理扩展--找到并下载 installer PRojects
2,新建项目与原项目在一起
如图所示
3,添加项目输出
创建快捷方式,并拖入user‘s desktop
在属性中重命名以及添加图标文件,图标文件可从其他地方拖进相应文件夹中
在User's Programs Menu 添加文件夹,在右边空白处右击,按照先前方式创建新的快捷方式,选择Applicaiton Folder,主输出,确定。
4,最后设置一些安装包属性以及环境需求,选择生成
5,安装与运行
安装完毕,运行成功。
以上是脚本宝典为你收集整理的【黑马程序员】通讯录管理系统----个人改良版(附带程序打包)全部内容,希望文章能够帮你解决【黑马程序员】通讯录管理系统----个人改良版(附带程序打包)所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。