通讯录管理系统 c++实现通讯录管理系统(控制台版)

编辑:
发布时间: 2020-12-18 16:51:12
分享:
此项目适合c++初学者,针对c++基础知识,涉及到变量、结构体定义使用、数组定义使用、指针定义使用等。

运行之后的结果如下:

代码:

#include #include using namespace std;#define MAX 1000//定义通讯录最大容量为1000//联系人结构体struct person{ string name; int sex; int age; string address; };//通讯录结构体struct contact{ struct person p[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;}//封装查询联系人是否存在int isExist { for { if { return i; } } return -1;}//添加联系人函数void addPerson{//传入数组的指针 if { cout << "通讯录已满"<> name; cout << "输入年龄"; int age; cin >> age; cout << "输入性别1:女 2:男"; int sex; cin >> sex; cout << "输入地址"; string address; cin >> address; con->p[con->size].name = name; con->p[con->size].age = age; con->p[con->size].sex = sex; con->p[con->size].address = address; con->size++; } cout << "添加成功"<> name; int res = isExist; if { for { con->p[res] = con->p[res + 1]; } cout << "删除成功" << endl; con->size--; } else { cout << "查无此人"<> name; int res = isExist; if { cout << "姓名:" << con->p[res].name << "年龄:" << con->p[res].age << "性别:" << << "地址:" << con->p[res].address << endl; cout << "输入修改姓名"; string nametemp; cin >> nametemp; con->p[res].name = nametemp; cout << "输入修改年龄" << endl; int age; cin >> age; con->p[res].age = age; cout << "输入修改性别1:女2:男" << endl; int sex; cin >> sex; con->p[res].sex = sex; cout << "输入修改地址" << endl; string address; cin >> address; con->p[res].address = address; cout << "修改成功" << endl; } else { cout << "查无此人" << endl; } system;}//查询联系人函数void search { string name; cout << "输入姓名查询"<> name; int res = isExist; if { cout << "姓名:" << con->p[res].name << "年龄:" << con->p[res].age << "性别:" <<<size = 0; cout << "已清空通讯录"<p[i].name <<"年龄:"<< con->p[i].age <<"地址:"<< con->p[i].address <<"性别:"<< << endl; } } system;}//退出系统函数int exitapp { exit;}/**通讯录管理系统主程序*/int main { contact con; con.size = 0; while { system;//清屏 showMenu; cout << "输入你的选择"; int select; cin >> select; switch { case 1: addPerson; break; case 2: deletecon; break; case 3: updateContact; break; case 4: search; break; case 5: showContact; break; case 6: clearContact; break; case 0://退出 exitapp; break; } }}

相关阅读
热门精选
孩子 皮肤