设计出模拟手机通信录管理系统,实现对手机中的通信录进行管理。基本功能: (1)查询功能:选择此功能时,可实现按姓名查询或按电话查询。(2)增加功能:能录入新数据(一个结点包括:姓名、电话号码、分类(可选项有:A 办公类 B 个人类 C 商务类)、电子邮件)。例如:张三 商务类 Chuny@126.C++om当录入了重复的姓名和电话号码时,则提示数据录入重复并取消录入;当通信录中超过15条信息时,存储空间已满,不能再录入新数据;录入的新数据能按递增的顺序自动进行条目编号。(4)修改功能:选中某个人的姓名时,可对此人的相应数据进行修改。(5)删除功能:选中某个人的姓名时,可对此人的相应数据进行删除,并自动调整后续条目的编号。
时间: 2024-03-08 22:46:18 浏览: 66
通讯录程序课程设计(模拟手机通信录的功能,能功实现添加、删除、修改手机能信录;)
4星 · 用户满意度95%
以下是一个简单的通讯录管理系统的实现示例,使用C++语言编写:
```cpp
#include <iostream>
#include <string>
using namespace std;
// 定义通讯录节点结构体
struct ContactNode {
int id; // 条目编号
string name; // 姓名
string phone; // 电话号码
string category; // 分类
string email; // 电子邮件
ContactNode *next; // 下一个节点指针
};
// 定义通讯录类
class ContactList {
public:
ContactList() {
head = new ContactNode();
head->next = NULL;
size = 0;
}
~ContactList() {
ContactNode *p = head;
while (p) {
ContactNode *q = p->next;
delete p;
p = q;
}
}
// 查询功能
void search(string key, int mode) {
ContactNode *p = head->next;
bool found = false;
while (p) {
if ((mode == 1 && p->name == key) || (mode == 2 && p->phone == key)) {
found = true;
cout << "编号:" << p->id << endl;
cout << "姓名:" << p->name << endl;
cout << "电话:" << p->phone << endl;
cout << "分类:" << p->category << endl;
cout << "邮箱:" << p->email << endl << endl;
}
p = p->next;
}
if (!found) {
cout << "未找到匹配记录!" << endl << endl;
}
}
// 增加功能
void add(string name, string phone, string category, string email) {
// 判断是否已经存在相同的姓名或电话号码
ContactNode *p = head->next;
while (p) {
if (p->name == name || p->phone == phone) {
cout << "已存在相同姓名或电话号码,无法添加!" << endl << endl;
return;
}
p = p->next;
}
// 判断是否超出存储空间
if (size >= 15) {
cout << "通讯录已满,无法添加新记录!" << endl << endl;
return;
}
// 插入新节点
p = head;
while (p->next) {
if (p->next->name > name) {
break;
}
p = p->next;
}
ContactNode *newNode = new ContactNode();
newNode->id = ++size;
newNode->name = name;
newNode->phone = phone;
newNode->category = category;
newNode->email = email;
newNode->next = p->next;
p->next = newNode;
cout << "添加成功!" << endl;
cout << "编号:" << newNode->id << endl;
cout << "姓名:" << newNode->name << endl;
cout << "电话:" << newNode->phone << endl;
cout << "分类:" << newNode->category << endl;
cout << "邮箱:" << newNode->email << endl << endl;
}
// 修改功能
void modify(string name) {
ContactNode *p = head->next;
bool found = false;
while (p) {
if (p->name == name) {
found = true;
cout << "请输入新的电话号码:";
string phone;
cin >> phone;
cout << "请输入新的分类:";
string category;
cin >> category;
cout << "请输入新的电子邮件:";
string email;
cin >> email;
p->phone = phone;
p->category = category;
p->email = email;
cout << "修改成功:" << endl;
cout << "编号:" << p->id << endl;
cout << "姓名:" << p->name << endl;
cout << "电话:" << p->phone << endl;
cout << "分类:" << p->category << endl;
cout << "邮箱:" << p->email << endl << endl;
break;
}
p = p->next;
}
if (!found) {
cout << "未找到匹配记录!" << endl << endl;
}
}
// 删除功能
void remove(string name) {
ContactNode *p = head;
bool found = false;
while (p->next) {
if (p->next->name == name) {
found = true;
ContactNode *q = p->next;
p->next = q->next;
delete q;
size--;
// 调整编号
p = p->next;
while (p) {
p->id--;
p = p->next;
}
cout << "删除成功!" << endl << endl;
break;
}
p = p->next;
}
if (!found) {
cout << "未找到匹配记录!" << endl << endl;
}
}
private:
ContactNode *head; // 头节点
int size; // 记录数量
};
int main() {
// 初始化通讯录
ContactList contactList;
// 循环菜单
while (true) {
cout << "请选择操作:" << endl;
cout << "1. 查询" << endl;
cout << "2. 添加" << endl;
cout << "3. 修改" << endl;
cout << "4. 删除" << endl;
cout << "5. 退出" << endl;
int choice;
cin >> choice;
switch (choice) {
case 1: {
cout << "请选择查询方式:" << endl;
cout << "1. 按姓名查询" << endl;
cout << "2. 按电话查询" << endl;
int mode;
cin >> mode;
cout << "请输入查询关键词:";
string key;
cin >> key;
contactList.search(key, mode);
break;
}
case 2: {
cout << "请输入姓名:";
string name;
cin >> name;
cout << "请输入电话号码:";
string phone;
cin >> phone;
cout << "请输入分类(A 办公类 B 个人类 C 商务类):";
string category;
cin >> category;
cout << "请输入电子邮件:";
string email;
cin >> email;
contactList.add(name, phone, category, email);
break;
}
case 3: {
cout << "请输入要修改的姓名:";
string name;
cin >> name;
contactList.modify(name);
break;
}
case 4: {
cout << "请输入要删除的姓名:";
string name;
cin >> name;
contactList.remove(name);
break;
}
case 5: {
cout << "谢谢使用!" << endl;
return 0;
}
default: {
cout << "无效的操作,请重新选择!" << endl;
break;
}
}
}
return 0;
}
```
这个示例为命令行版本的通讯录管理系统,可以根据需要进行改进。
阅读全文