【C++实战小项目】通讯录(三)数组模拟实现通讯录三大功能
🧛♂️iecne个人主页::iecne的学习日志 💡每天关注iecne的作品,一起进步 💪学C++必看iecne 本文专栏:【实战小项目】 🐳希望大家多多支持🥰一起进步呀!
✨前言
哈喽大家好,我是iecne,本期为大家带来的是CPP/C++【C++实战小项目】实现基本通讯录模拟详解分析。包教包会,快来看看吧!
任务描述如何根据据C++基础入门编写一款不可视化通讯录,我们这次就来讲讲并且写一写添加用户
文章目录 ✨前言任务描述 一.分析通讯录二.删除2.1 Flowchat流程图2.2 string2_ 三.查找3.1 Flowchart流程图3.2 三千字代码实现 四.修改4.1 Flowchart流程图4.2 代码实现 总结
一.分析通讯录
首先制作一款通讯录我们可以将它分为以下部分
增加联系人 删除联系人 查找联系人 修改联系人 打印通讯录 排序通讯录
这一期我们就来实现准备删除查找与修改
二.删除
删除是string2_函数,我们就来看看
2.1 Flowchat流程图 Created with Raphaël 2.2.0 进入函数 提取数据 确认? 操作删除 回到开始页面 通知错误 yes no 2.2 string2_ void string2_() { string name1 = "请输入名字:>\n"; out06(name1); string chaname; input_string(chaname); chaname = stringaaaa; int s = 0; int ss = 0; cout << " 姓名"; for (int j = 1; j <= 12; j++) { cout << " "; } cout << "性别"; for (int j = 1; j <= 10; j++) { cout << " "; } cout << "年龄"; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << "电话"; for (int j = 1; j <= 20; j++) { cout << " "; } cout << "地址"; cout << "\n"; for (int i = 1; i <= z - 1; i++) { if (namez[i] == chaname) { s++; ss = i; cout << " "; cout << namez[i]; for (int j = 1; j <= 10; j++) { cout << " "; } cout << bgz[i]; for (int j = 1; j <= 10; j++) { cout << " "; } cout << agez[i]; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << phonez[i]; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << homez[i]; cout << "\n"; } } if (s == 0) { cout << "没有找到这个人"; } cout << "确认删除该联系人吗"; cout << endl; cout << "1.yes"; cout << endl << "2.no" << endl; int yesno1; cin >> yesno1; if (yesno1 == 1) { over(ss); } else { system("pause"); playfirst(); } }基本如图所示
三.查找
删除是string3_函数,我们来看看
3.1 Flowchart流程图 Created with Raphaël 2.2.0 进入函数 询问查找方式 提取数据 符合查找方式 输出 回到开始页面 通知错误 yes yes no3.2 三千字代码实现
然后我们再看看code
void string3_() { string string0 = "=====================================\n"; string string1 = "============1.通过名字查=============\n"; string string2 = "============2.通过性别查=============\n"; string string3 = "============3.通过年龄查=============\n"; string string4 = "============4.通过地址查=============\n"; out06(string0); out06(string1); out06(string2); out06(string3); out06(string4); out06(string0); int string7 = 0; string7 = input(string7); switch (string7) { case 1: cha1_(); case 2: cha2_(); case 3: cha3_(); case 4: cha4_(); } }通过switch来分别到cha1_ ~ cha4_
void cha1_() { string name1 = "请输入名字:>\n"; out06(name1); string chaname; input_string(chaname); chaname = stringaaaa; int s = 0; cout << " 姓名"; for (int j = 1; j <= 12; j++) { cout << " "; } cout << "性别"; for (int j = 1; j <= 10; j++) { cout << " "; } cout << "年龄"; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << "电话"; for (int j = 1; j <= 20; j++) { cout << " "; } cout << "地址"; cout << "\n"; for (int i = 1; i <= z - 1; i++) { if (namez[i] == chaname) { s++; cout << " "; cout << namez[i]; for (int j = 1; j <= 10; j++) { cout << " "; } cout << bgz[i]; for (int j = 1; j <= 10; j++) { cout << " "; } cout << agez[i]; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << phonez[i]; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << homez[i]; cout << "\n"; } } if (s == 0) { cout << "没有找到这个人"; } system("pause"); playfirst(); } void cha2_() { string name1 = "请输入性别:>\n"; out06(name1); string chaname; input_string(chaname); chaname = stringaaaa; if (chaname == "男")chaname = "男"; else if (chaname == "女") chaname = "女"; else chaname = "不男不女"; cout << " 姓名"; for (int j = 1; j <= 12; j++) { cout << " "; } cout << "性别"; for (int j = 1; j <= 10; j++) { cout << " "; } cout << "年龄"; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << "电话"; for (int j = 1; j <= 20; j++) { cout << " "; } cout << "地址"; cout << "\n"; int s = 0; for (int i = 1; i <= z - 1; i++) { if (bgz[i] == chaname) { s++; cout << " "; cout << namez[i]; for (int j = 1; j <= 10; j++) { cout << " "; } cout << bgz[i]; for (int j = 1; j <= 10; j++) { cout << " "; } cout << agez[i]; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << phonez[i]; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << homez[i]; cout << "\n"; } } if (s == 0) { cout << "没有找到这个人"; } system("pause"); playfirst(); } void cha3_() { string name1 = "请输入年龄:>\n"; out06(name1); int chaage; int s = 0; cin >> chaage; cout << " 姓名"; for (int j = 1; j <= 12; j++) { cout << " "; } cout << "性别"; for (int j = 1; j <= 10; j++) { cout << " "; } cout << "年龄"; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << "电话"; for (int j = 1; j <= 20; j++) { cout << " "; } cout << "地址"; cout << "\n"; cout << " "; for (int i = 1; i <= z - 1; i++) { if (agez[i] == chaage) { s++; cout << " 姓名"; for (int j = 1; j <= 12; j++) { cout << " "; } cout << "性别"; for (int j = 1; j <= 10; j++) { cout << " "; } cout << "年龄"; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << "电话"; for (int j = 1; j <= 20; j++) { cout << " "; } cout << "地址"; cout << "\n"; cout << " "; cout << namez[i]; for (int j = 1; j <= 10; j++) { cout << " "; } cout << bgz[i]; for (int j = 1; j <= 10; j++) { cout << " "; } cout << agez[i]; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << phonez[i]; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << homez[i]; cout << "\n"; } } if (s == 0) { cout << "没有找到这个人"; } system("pause"); playfirst(); } void cha4_() { string name1 = "请输入地址:>\n"; out06(name1); string chaname; input_string(chaname); chaname = stringaaaa; int s = 0; cout << " 姓名"; for (int j = 1; j <= 12; j++) { cout << " "; } cout << "性别"; for (int j = 1; j <= 10; j++) { cout << " "; } cout << "年龄"; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << "电话"; for (int j = 1; j <= 20; j++) { cout << " "; } cout << "地址"; cout << "\n"; cout << " "; for (int i = 1; i <= z - 1; i++) { if (homez[i] == chaname) { s++; cout << namez[i]; for (int j = 1; j <= 10; j++) { cout << " "; } cout << bgz[i]; for (int j = 1; j <= 10; j++) { cout << " "; } cout << agez[i]; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << phonez[i]; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << homez[i]; cout << "\n"; } } if (s == 0) { cout << "没有找到这个人"; } system("pause"); playfirst(); }四.修改 4.1 Flowchart流程图 Created with Raphaël 2.2.0 进入函数 输入名字 判断 修改各项值 回到开始页面 通知错误 yes no
4.2 代码实现 void string4_() { printf("请输入需要修改信息用户的名字:>\n"); string chaname; input_string(chaname); chaname = stringaaaa; int s = 0; cout << " 姓名"; for (int j = 1; j <= 12; j++) { cout << " "; } cout << "性别"; for (int j = 1; j <= 10; j++) { cout << " "; } cout << "年龄"; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << "电话"; for (int j = 1; j <= 20; j++) { cout << " "; } cout << "地址"; cout << "\n"; cout << " "; int ss = 0; for (int i = 1; i <= z - 1; i++) { if (namez[i] == chaname) { s++; ss = i; cout << namez[i]; for (int j = 1; j <= 10; j++) { cout << " "; } cout << bgz[i]; for (int j = 1; j <= 10; j++) { cout << " "; } cout << agez[i]; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << phonez[i]; for (int j = 1; j <= 20 - 1; j++) { cout << " "; } cout << homez[i]; cout << "\n"; } } if (s == 0) { cout << "没有找到这个人"; system("pause"); playfirst(); } printf(" \n0.退出 1.姓名 2.性别 3.年龄 4.电话 5.地址:>\n"); int num; cin >> num; switch (num) { case 1: printf("请输入你想修改的姓名:>\n"); cin >> namez[ss]; break; case 2: printf("请输入你想修改的性别:>\n"); cin >> bgz[ss]; break; case 3: printf("请输入你想修改的年龄:>\n"); cin >> agez[ss]; break; case 4: printf("请输入你想修改的电话:>\n"); cin >> phonez[ss]; break; case 5: printf("请输入你想修改的地址:>\n"); cin >> homez[ss]; break; case 0: printf("不修改退回界面\n"); break; default:printf("无效操作数!\n"); } system("pause"); playfirst(); }
总结
今天我们实现了通讯录的教程,至此该课示例的思想博主已经真真切切彻彻底底分享完了,相信大家对这个逻辑有了一定的理解,大家可以自己动手敲敲代码,感受一下,包教包会。若有任何侵权和不妥之处,请私信于我,定积极配合处理,看到必回!!!
帅的人已然点赞收藏关注,而丑的人还在犹豫,被犹豫了,快三连吧! 原创不易,还希望各位大佬支持一下 点赞,你的认可是我创作的动力! 收藏,你的青睐是我努力的方向! 评论,你的意见是我进步的财富!
感谢每一个观看本篇文章的朋友,更多精彩敬请期待~( ̄▽ ̄~)~: iecne的博客 若有任何侵权和不妥之处,请私信于我,定积极配合处理,看到必回!!!