通讯录管理系统C++版本
前言:小刘之前用C++写了一个通讯录管理系统具体描述如下;
系统功能说明
系统功能说明:
初始化功能后,根据命令指令提示操作相应的功能。
1.导入初始数据
根据模板文件,将模板文件的数据导入到系统中
2.显示信息
展示系统中通讯录列表数据
3.输入记录
根据提示将输入的姓名,手机号,邮件,年龄,性别,地址等信息添加到系统中
4.删除记录
根据通讯录列表记录的编号将系统中该记录删除
5.查询记录
根据提示的搜索条件进行按照姓名或者手机号的维度进行搜索查询
6.编辑记录
根据提示按照通讯录的编号查询此记录并且按照提示进行编辑操作
7.去重
根据提示的去重条件进行按照姓名或者手机号的维度进行去重
8.批量导出数据
将系统中的数据批量全部导出到模板导出文件中
9.退出
退出系统程序
开发环境
1.操作系统:Windows 10
2.运行环境:mingw64
3.开发工具:CLion 2020.1 x64
4.DEBUG模式运行项目
三、系统运行效果截图
1.导入模板文件
2.导入初始数据并显示数据
3.输入记录并显示数据
4.删除记录并显示信息
添加记录一共7个,删除编号为7的记录
5.查询数据并显示数据
按姓名查询
按手机查询
编辑记录
选择编号为4的记录进行编辑
6.去重数据并显示数据
按姓名去重
按手机号去重
7.导出数据到模板文件
项目源码如下
1.#include <iostream>
2.#include <string>
3.#include <fstream>
4.
5.using namespace std;
6.#define MAX 1000//定义通讯录最大容量为1000
7.
8./**
9. * 联系人结构体
10. */
11.struct person {
12. int id; //编号
13. string name; //姓名
14. string phone; //手机号
15. string email; //邮箱
16. string sex; //性别
17. int age; //年龄
18. string address; //住址
19. int state; //去重状态100 表示该记录已重复
20.};
21.
22./**
23. * 通讯录结构体
24. */
25.struct contact {
26. struct person p[MAX];
27. int size; //容量
28. int index; //自增
29.};
30.
31./**
32. * 操作菜单
33. */
34.void showMenu() {
35. cout << "\n*********通讯录管理系统**********" << endl;
36. cout << "********* 1.导入初始数据 **********" << endl;
37. cout << "********* 2.显示信息 **********" << endl;
38. cout << "********* 3.输入记录 **********" << endl;
39. cout << "********* 4.删除记录 **********" << endl;
40. cout << "********* 5.查询记录 **********" << endl;
41. cout << "********* 6.编辑记录 **********" << endl;
42. cout << "********* 7.去重 **********" << endl;
43. cout << "********* 8.批量导出数据 **********" << endl;
44. cout << "********* 0.退出通讯录 **********" << endl;
45. cout << "请输入你的选择:" << endl;
46.}
47.
48./**
49. * 显示联系人函数
50. * @param con
51. */
52.void showTable(contact *con) {
53. cout << "================显示联系人=================" << endl;
54. if (con->size == 0) {
55. cout << "暂无联系人" << endl;
56. } else {
57. for (int i = 0; i < con->size; i++) {
58. cout
59. << " 编号: " << con->p[i].id
60. << " 姓名: " << con->p[i].name
61. << " 手机: " << con->p[i].phone
62. << " 邮箱: " << con->p[i].email
63. << " 年龄: " << con->p[i].age
64. << " 性别: " << con->p[i].sex
65. << " 地址: " << con->p[i].address
66. << endl;
67. }
68. }
69.}
70.
71./**
72. * 添加联系人函数
73. * @param con
74. */
75.void addPerson(contact *con) {//传入数组的指针
76. if (con->size == MAX) {
77. cout << con->size;
78. cout << "通讯录已满" << endl;
79. } else {
80. cout << "输入姓名:";
81. string name;
82. cin >> name;
83.
84. cout << "输入手机号:";
85. string phone;
86. cin >> phone;
87.
88. cout << "输入邮箱:";
89. string email;
90. cin >> email;
91.
92.
93. cout << "输入年龄:";
94. int age;
95. cin >> age;
96.
97. cout << "输入性别【男/女】:";
98. string sex;
99. cin >> sex;
100. cout << "输入地址:";
101. string address;
102. cin >> address;
103. con->p[con->size].name = name;
104. con->p[con->size].phone = phone;
105. con->p[con->size].email = email;
106. con->p[con->size].age = age;
107. con->p[con->size].sex = sex;
108. con->p[con->size].address = address;
109.
110. con->p[con->size].id = con->index;
111. con->size++;
112. con->index++;
113. }
114. cout << "添加成功" << endl;
115.}
116.
117./**
118. * 封装查询联系人是否存在
119. * @param con
120. * @param name
121. * @return
122. */
123.int isExist(contact *con, string name) {
124. for (int i = 0; i < con->size; i++) {
125. if (con->p[i].name == name) {
126. return i;
127. }
128. }
129. return -1;
130.}
131.
132./**
133. * id是否存在
134. * @param con
135. * @param id
136. * @return
137. */
138.int isIdExist(contact *con, int id) {
139. for (int i = 0; i < con->size; i++) {
140. if (con->p[i].id == id) {
141. return i;
142. }
143. }
144. return -1;
145.}
146.
147.
148./**
149. * 按照编号id 删除
150. * @param con
151. */
152.void deleteById(contact *con) {
153. int id;
154. cout << "输入要删除的记录编号";
155. cin >> id;
156. int res = isIdExist(con, id);
157. if (res != -1) {
158. for (int i = res; i < con->size; i++) {
159. con->p[res] = con->p[res + 1];
160. }
161. cout << "删除成功" << endl;
162. con->size--;
163. } else {
164. cout << "查无此记录" << endl;
165. }
166.}
167.
168./**
169. * 修改联系人函数
170. * @param con
171. */
172.void updateById(contact *con) {
173. int id;
174. cout << "输入要修改的联系人编号" << endl;
175. cin >> id;
176. int res = isIdExist(con, id);
177. if (res != -1) {
178. cout
179. << "编号:" << con->p[res].id
180. << "姓名:" << con->p[res].name
181. << "手机:" << con->p[res].phone
182. << "邮箱:" << con->p[res].email
183. << "年龄:" << con->p[res].age
184. << "性别:" << con->p[res].sex
185. << "地址:" << con->p[res].address
186. << endl;
187.
188. cout << "输入姓名:";
189. string name;
190. cin >> name;
191. con->p[res].name = name;
192.
193. cout << "输入手机号:";
194. string phone;
195. cin >> phone;
196. con->p[res].phone = phone;
197.
198. cout << "输入邮箱:";
199. string email;
200. cin >> email;
201. con->p[res].email = email;
202.
203. cout << "输入年龄:";
204. int age;
205. cin >> age;
206. con->p[res].age = age;
207.
208. cout << "输入性别【男/女】:";
209. string sex;
210. cin >> sex;
211. con->p[res].sex = sex;
212.
213. cout << "输入地址:";
214. string address;
215. cin >> address;
216. con->p[res].address = address;
217.
218. cout << "修改成功" << endl;
219. } else {
220. cout << "查无此人" << endl;
221. }
222.}
223.
224.
225./**
226. * 退出系统函数
227. * @return
228. */
229.int exitSystem() {
230. exit(0);
231.}
232.
233./**
234. * 导入数据 按照模板导入数据,一行为一个属性字段的值
235. */
236.void importInfo(contact *con) {
237.
238. // 以读模式打开文件
239. ifstream infile;
240. infile.open("import.txt");
241.
242. if (!infile.is_open()) {
243. cout << "无法找到这个文件!" << endl;
244.
245. }
246. string buff;
247. string arr[6];
248. int index = 0;
249. cout << "读取模板文件如下" << endl;
250. while (getline(infile, buff)) {
251. cout << buff << endl;
252. arr[index] = buff;
253. index++;
254. }
255. std::string str = arr[3];
256. int n = atoi(str.c_str());
257. con->p[con->size].name = arr[0];
258. con->p[con->size].phone = arr[1];
259. con->p[con->size].email = arr[2];
260. con->p[con->size].age = n;
261. con->p[con->size].sex = arr[4];
262. con->p[con->size].address = arr[5];
263.
264. con->p[con->size].id = con->index;
265. con->size++;
266. con->index++;
267.
268. infile.close();
269. // 关闭打开的文件
270. infile.close();
271.
272.}
273.
274./**
275. * 导出数据
276. */
277.void exportInfo(contact *con) {
278. if (con->size == 0) {
279. cout << "暂无联系人" << endl;
280. } else {
281. ofstream ofile; //定义输出文件
282. ofile.open("exportInfo.txt"); //作为输出文件打开
283. for (int i = 0; i < con->size; i++) {
284. ofile
285. << " 编号:" << con->p[i].id
286. << " 姓名:" << con->p[i].name
287. << " 姓名:" << con->p[i].phone
288. << " 姓名:" << con->p[i].email
289. << " 年龄:" << con->p[i].age
290. << " 性别:" << con->p[i].sex
291. << " 地址:" << con->p[i].address
292. << endl;
293. }
294. ofile.close(); //关闭文件
295.
296. cout << "批量导出数据完成" << endl;
297. }
298.
299.
300.}
301.
302.
303./**
304. * 去重检索
305. * @param con
306. */
307.void deWeight(contact *con) {
308. cout << "请输入要去重检索的维度:a:姓名;b:手机号 :\n";
309. string i;
310. cin >> i;
311. string msg;
312. if (i == "a") {
313. string name = con->p[0].name;
314. for (int i = 1; i < con->size; i++) {
315. if (con->p[i].name == name) {
316. con->p[i].state = 100; //重复的标识
317. }
318. }
319. for (int i = 0; i < con->size; i++) {
320. if (con->p[i].state != 100) {
321. cout
322. << " 编号:" << con->p[i].id
323. << " 姓名:" << con->p[i].name
324. << " 手机:" << con->p[i].phone
325. << " 邮箱:" << con->p[i].email
326. << " 年龄:" << con->p[i].age
327. << " 性别:" << con->p[i].sex
328. << " 地址:" << con->p[i].address
329. << endl;
330. }
331.
332. con->p[i].state = 0;//恢复
333. }
334.
335.
336. } else if (i == "b") {
337. string phone = con->p[0].phone;
338.
339. for (int i = 1; i < con->size; i++) {
340. if (con->p[i].phone == phone) {
341. con->p[i].state = 100;
342. }
343. }
344. for (int i = 0; i < con->size; i++) {
345. if (con->p[i].state != 100) {
346. cout
347. << " 编号:" << con->p[i].id
348. << " 姓名:" << con->p[i].name
349. << " 手机:" << con->p[i].phone
350. << " 邮箱:" << con->p[i].email
351. << " 年龄:" << con->p[i].age
352. << " 性别:" << con->p[i].sex
353. << " 地址:" << con->p[i].address
354. << endl;
355. }
356. }
357.
358. } else {
359. cout << "请输入合法的命令" << endl;
360. }
361.}
362.
363.
364./**
365. * 按照名称搜索
366. * @param con
367. * @param name
368. */
369.void selectByName(contact *con, string name) {
370. for (int i = 0; i < con->size; i++) {
371. if (con->p[i].name == name) {
372. cout
373. << " 编号:" << con->p[i].id
374. << " 姓名:" << con->p[i].name
375. << " 手机:" << con->p[i].phone
376. << " 邮箱:" << con->p[i].email
377. << " 年龄:" << con->p[i].age
378. << " 性别:" << con->p[i].sex
379. << " 地址:" << con->p[i].address
380. << endl;
381. }
382. }
383.}
384.
385./**
386. * 按照手机号搜索
387. * @param con
388. * @param phone
389. */
390.void selectByPhone(contact *con, string phone) {
391. for (int i = 0; i < con->size; i++) {
392. if (con->p[i].phone == phone) {
393. cout
394. << " 编号:" << con->p[i].id
395. << " 姓名:" << con->p[i].name
396. << " 姓名:" << con->p[i].phone
397. << " 姓名:" << con->p[i].email
398. << " 年龄:" << con->p[i].age
399. << " 性别:" << con->p[i].sex
400. << " 地址:" << con->p[i].address
401. << endl;
402. }
403. }
404.}
405.
406./**
407. * 查询
408. * @param con
409. */
410.void select(contact *con) {
411. cout << "请输入要查看搜索的维度:a:姓名;b:手机号";
412. string i;
413. cin >> i;
414. string msg;
415. if (i == "a") {
416. cout << "请输入姓名:";
417. cin >> msg;
418. selectByName(con, msg);
419. } else if (i == "b") {
420. cout << "请输入手机号:";
421. cin >> msg;
422. selectByPhone(con, msg);
423. } else {
424. cout << "请输入合法的命令" << endl;
425. }
426.}
427.
428.
429./**
430.通讯录管理系统主程序
431.*/
432.int main() {
433.
434. contact con; //结构体
435. con.size = 0; //长度
436. con.index = 1; //索引
437. while (true) {
438. showMenu(); //循环显示菜单
439. int i;
440. cin >> i;
441. switch (i) {
442. case 1:
443. importInfo(&con); //导入数据
444. break;
445. case 2:
446. showTable(&con); //显示信息
447. break;
448. case 3:
449. addPerson(&con); //输入记录
450. break;
451. case 4:
452. deleteById(&con); //删除记录
453. break;
454. case 5:
455. select(&con); //查询记录
456. break;
457. case 6:
458. updateById(&con); //编辑记录
459. break;
460. case 7:
461. deWeight(&con); //去重检索
462. break;
463. case 8:
464. exportInfo(&con); //批量导出数据
465. break;
466. case 0:
467. exitSystem(); //退出通讯录
468. break;
469. }
470. }
471.}
有啥不懂得小伙伴们加群交流啦:852665736;
无偿有偿免费分享源码以及技术和面试文档,更多优秀精致的源码技术栈分享请关注微信公众号:gh_817962068649
通讯录管理系统C++版本相关推荐
- 通讯录管理系统(c语言版本)
通讯录管理系统 (c语言版本) 一:通讯录基本功能 二:实现代码分析 1:建立文件 2:test.c test.c完整代码 3:contact.c contact.c完整代码 3:contact.h ...
- 基于C++实现(控制台+界面)通讯录管理系统【100010012】
个人通讯录管理系统 问题描述: 主要内容: 个人通讯录是记录了同学(包含一起上学的学校名称).同事(包含共事的单位名称).朋友(包含认识的地点).亲戚(包含称呼)等与本人有关人员的数据集. 具体要求: ...
- 链表实现c语言通讯录管理系统,C++链表实现通讯录管理系统
用数据结构里面线性结构的链表实现,供大家参考,具体内容如下 文件操作未写 有登录操作,复制源码需要更改登录模块的密码文件存放位置 使用VS2017编译器需要保留开头:#define _CRT_SECU ...
- 基于Linux中的通讯录管理系统(C语言+双向循环链表+MySQL)
文章目录 系统功能实现 相关软件前提 部分重要的功能代码 Makefile menu.c MySQL API函数使用 C语言连接MySQL: 调用SQL命令 双向循环列表功能 效果实现 这个通讯录管理 ...
- 基于C++和QT实现的个人通讯录管理系统
资源下载地址:https://download.csdn.net/download/sheziqiong/85722043 资源下载地址:https://download.csdn.net/downl ...
- 在qt实现手机通讯录系统_通讯录管理系统的设计与实现(QT,SQlite)
通讯录管理系统的设计与实现(QT,SQlite)(任务书,外文翻译,毕业论文15000字,程序代码,数据库,答辩PPT) 摘 要 现今社会随着通讯以及交通的发展,人与人之间的联系越来越多,越来越紧密, ...
- 基于javaweb的校园班级同学通讯录管理系统(java+ssm+html+jsp+mysql)
基于javaweb的校园班级同学通讯录管理系统(java+ssm+html+jsp+mysql) 运行环境 Java≥8.MySQL≥5.7.Tomcat≥8 开发工具 eclipse/idea/my ...
- 通讯录管理系统C++版
用c++编写的基础版本,很好理解. 原创不易,禁止抄袭,转载请注明出处: 功能:编写一个通讯录系统包含手机通讯录和手机卡通讯录,实现对通讯录的添加.修改.删除.浏览.查找.以及通讯录的清空. 总体描述 ...
- JAVA趣味课程:手机通讯录管理系统(连接数据库管理信息)
今天课堂上正好讲到JAVA连接jdbc管理sqlite数据库的操作,讲完他的基本用法之后,就又把之前的手机通讯录管理系统掏出来,改装完成数据库版本的增删改查等存取工作.那么下面开始需求分析以及逻辑编码 ...
最新文章
- 详解布局之--静态、自适应、流式、响应式
- SpringBoot入门实战项目各阶段目录
- 了解模型、视图和控制器
- python选取元音开头的单词_一学生易错词汇aan的选择元音字母开头的单词用an辅音字母...
- getprocaddress得到为0_基于ZU+系列MPSoC芯片的USB3.0/2.0接口硬件设计
- 通信工程中常用算法c语言,通信工程常见面试题.doc
- 拿下我人生中第7个Offer,社招面试心得
- [CodeChef FEB15]Payton numbers(CUSTPRIM)解题报告
- 韩国飞中国机票炒至近万元,一票难求
- windows常用命令及相关命令
- CANOpen中SDO和PDO的COB-ID理解
- 知乎cookies的介绍_使用cookie登陆知乎
- 练习题:让用户提供半径,然后计算出对应圆的周长和面积
- python决策树 value_机器学习之ID3算法详解及python代码实现
- IPC网络高清摄像机基础知识3(Insta360硬件设计之路 “来自2015年”)
- 含TDA7540的收音高频头软件源代码
- 注意营养,这可能是目前最好的离线下载方式
- 支付宝六(商户会员卡之模板创建)
- opencv c++ 图像噪声及去噪
- 「IOS 网络踩坑」错误 Error Domain=NSURLErrorDomain Code=-1004