You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LABMS/ContactManager.cpp

50 lines
1.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "ContactManager.h"
#include <iostream>
void ContactManager::addContact() {
Contact newContact;
std::cout << "请输入联系人姓名: ";
std::cin >> newContact.name;
std::cout << "请输入联系人电话: ";
std::cin >> newContact.phone;
newContact.id = contacts.size() + 1;
contacts.push_back(newContact);
}
void ContactManager::displayContacts() const {
std::cout << "通讯录如下:" << std::endl;
for (const auto& contact : contacts) {
std::cout << "ID" << contact.id << ", 姓名: " << contact.name << ", 电话: " << contact.phone << std::endl;
}
}
void ContactManager::findContact() const {
int id;
std::cout << "请输入要查找的联系人ID ";
std::cin >> id;
for (const auto& contact : contacts) {
if (contact.id == id) {
std::cout << "找到联系人ID " << contact.id << ", 姓名: " << contact.name << ", 电话: " << contact.phone << std::endl;
return;
}
}
std::cout << "未找到联系人。" << std::endl;
}
void ContactManager::deleteContact() {
int id;
std::cout << "请输入要删除的联系人ID ";
std::cin >> id;
for (auto it = contacts.begin(); it != contacts.end(); ++it) {
if (it->id == id) {
contacts.erase(it);
std::cout << "已删除联系人。" << std::endl;
return;
}
}
std::cout << "未找到联系人。" << std::endl;
}