通讯录管理系统
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | #include <stdlib.h> #include <iostream> #include <ostream> #include <string> using namespace std; #define MAX 100 //最大容量 //联系人结构体 姓名、性别、年龄、联系电话、家庭住址 struct Person { string Name; //姓名 int Sex; // 1为男 2为女 int Age; //年龄 string Phone; //手机号 string Addr; //家庭住址 }; struct Addressbooks { struct Person personArray[MAX]; int size; //结构体大小 }; /*栈区*/ 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 AddPerson(Addressbooks* ans) { //添加联系人 if (ans->size >= MAX) { cout << "通讯录已满,无法添加" << endl; return ; } else { string name; cout << "请输入姓名:" << endl; cin >> name; ans->personArray[ans->size].Name = name; cout << "请输入性别:" << endl; cout << "1 -- 男" << endl; cout << "2 -- 女" << endl; int sex = 0; while ( true ) { cin >> sex; if (sex == 1 || sex == 2) { ans->personArray[ans->size].Sex = sex; break ; } else { cout << "输入有误,请重新输入" ; } } cout << "请输入年龄:" << endl; int age = 0; cin >> age; ans->personArray[ans->size].Age = age; cout << "请输入联系电话:" << endl; string phone = "" ; cin >> phone; ans->personArray[ans->size].Phone = phone; cout << "请输入家庭住址:" << endl; string address; cin >> address; ans->personArray[ans->size].Addr = address; ans->size += 1; cout << "添加成功" << endl; system ( "pause" ); system ( "cls" ); //清屏 } } void ShowPerson(Addressbooks * ans) { //显示联系人 if (ans->size == 0) { cout << "当前记录为空" << endl; } else { for ( int i = 0; i < ans->size; i++) { cout << "姓名:" << ans->personArray[i].Name << "\t" ; cout << "性别:" << (ans->personArray[i].Sex == 1 ? "男" : "女" ) << "\t" ; cout << "年龄:" << ans->personArray[i].Age << "\t" ; cout << "电话:" << ans->personArray[i].Phone << "\t" ; cout << "住址:" << ans->personArray[i].Addr << endl; } } system ( "pause" ); system ( "cls" ); } int isExist(Addressbooks *ans , string name) { //判断联系人 for ( int i = 0; i < ans->size ; i ++) { if (ans->personArray[i].Name == name) { return i; } } return -1; } void DeletePerson(Addressbooks *ans) { //删除联系人 cout << "请输入您要删除的联系人" << endl; string name; cin >> name; int res = isExist(ans , name); if (res != -1) { ans->personArray[res] = ans->personArray[res + 1]; ans->size --; cout << "删除成功" << endl; } else { cout << "查无此人" << endl; } system ( "pause" ); system ( "cls" ); } void FindPerson(Addressbooks * ans) { //查找联系人 cout << "请输入您要查找的联系人" << endl; string name; cin >> name; int ret = isExist(ans, name); if (ret != -1) { cout << "姓名:" << ans->personArray[ret].Name << "\t" ; cout << "性别:" << ans->personArray[ret].Sex << "\t" ; cout << "年龄:" << ans->personArray[ret].Age << "\t" ; cout << "电话:" << ans->personArray[ret].Phone << "\t" ; cout << "住址:" << ans->personArray[ret].Addr << endl; } else { cout << "查无此人" << endl; } system ( "pause" ); system ( "cls" ); } void ModifyPerson(Addressbooks * ans) { //修改联系人 cout << "请输入您要修改的联系人" << endl; string name; cin >> name; int ret = isExist(ans, name); if (ret != -1) { //姓名 string name; cout << "请输入姓名:" << endl; cin >> name; ans->personArray[ret].Name = name; cout << "请输入性别:" << endl; cout << "1 -- 男" << endl; cout << "2 -- 女" << endl; //性别 int sex = 0; while ( true ) { cin >> sex; if (sex == 1 || sex == 2) { ans->personArray[ret].Sex = sex; break ; } cout << "输入有误,请重新输入" ; } //年龄 cout << "请输入年龄:" << endl; int age = 0; cin >> age; ans->personArray[ret].Age = age; //联系电话 cout << "请输入联系电话:" << endl; string phone = "" ; cin >> phone; ans->personArray[ret].Phone = phone; //家庭住址 cout << "请输入家庭住址:" << endl; string address; cin >> address; ans->personArray[ret].Addr = address; cout << "修改成功" << endl; } else { cout << "查无此人" << endl; } system ( "pause" ); system ( "cls" ); } void CleanPerson(Addressbooks * ans) { //清空通讯录 ans->size = 0; cout << "通讯录已清空" << endl; system ( "pause" ); system ( "cls" ); } int main() { Addressbooks ans; ans.size = 0; int select = 0; while (1) { ShowMenu(); cin >> select; if (select == 1) { AddPerson(&ans); } else if (select == 2) { ShowPerson(&ans); } else if (select == 3) { DeletePerson(&ans); } else if (select == 4) { FindPerson(&ans); } else if (select == 5) { ModifyPerson(&ans); } else if (select == 6) { CleanPerson(&ans); } else if (select == 0) { cout << "欢迎下次使用" << endl; return 0; break ; } else { break ; } } return 0; } |
__EOF__

本文作者:比尔的歌
本文链接:https://www.cnblogs.com/PengQ/p/17269869.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
本文链接:https://www.cnblogs.com/PengQ/p/17269869.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下