你可以用c++帮我写一个简单的快件管理系统吗,要求进入系统后首先选择取件人模式或管理员模式,内置管理员的账号密码,取件人可以凭借手机号或者快递单号取快递,管理员可以进行快件的录入,删除,读取,修改,查询已取快件,查询未取快件,一个快件应包含的信息有:随机生成的快递单号,寄件人,寄件人手机号,寄件人住址,收件人,收件人手机号,收件人住址。退出系统时回到选择模式的界面。400行以上代码
时间: 2024-03-14 07:44:17 浏览: 158
好的,下面是使用 C++ 实现的一个简单的快件管理系统,包含取件人模式和管理员模式,内置管理员账号密码,取件人可以凭手机号或快递单号取快递,管理员可以进行快件的录入、删除、读取、修改,以及查询已取快件和未取快件。
在本示例中,一个快件包含的信息有:快递单号、寄件人、寄件人手机号、寄件人住址、收件人、收件人手机号、收件人住址。
代码如下:
```c++
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
// 定义一个全局变量,用来存储快递信息
vector< vector<string> > express_list;
// 生成指定长度的随机字符串
string random_string(int length) {
static const string charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string result;
result.resize(length);
srand(time(0));
for (int i = 0; i < length; i++) {
result[i] = charset[rand() % charset.length()];
}
return result;
}
// 查询快递信息
void query_express() {
string query_type;
cout << "请选择查询方式(1. 按手机号查询,2. 按快递单号查询): ";
cin >> query_type;
while (query_type != "1" && query_type != "2") {
cout << "输入有误,请重新输入!" << endl;
cout << "请选择查询方式(1. 按手机号查询,2. 按快递单号查询): ";
cin >> query_type;
}
string query_value;
cout << "请输入查询值: ";
cin >> query_value;
bool found = false;
for (int i = 0; i < express_list.size(); i++) {
if (query_type == "1" && express_list[i][2] == query_value) {
found = true;
cout << "快递单号:" << express_list[i][0] << endl;
cout << "寄件人:" << express_list[i][1] << endl;
cout << "寄件人手机号:" << express_list[i][2] << endl;
cout << "寄件人住址:" << express_list[i][3] << endl;
cout << "收件人:" << express_list[i][4] << endl;
cout << "收件人手机号:" << express_list[i][5] << endl;
cout << "收件人住址:" << express_list[i][6] << endl;
cout << endl;
}
if (query_type == "2" && express_list[i][0] == query_value) {
found = true;
cout << "快递单号:" << express_list[i][0] << endl;
cout << "寄件人:" << express_list[i][1] << endl;
cout << "寄件人手机号:" << express_list[i][2] << endl;
cout << "寄件人住址:" << express_list[i][3] << endl;
cout << "收件人:" << express_list[i][4] << endl;
cout << "收件人手机号:" << express_list[i][5] << endl;
cout << "收件人住址:" << express_list[i][6] << endl;
cout << endl;
}
}
if (!found) {
cout << "未找到符合条件的快递信息!" << endl;
}
}
// 录入快递信息
void add_express() {
vector<string> express;
express.push_back(random_string(10)); // 生成10位随机快递单号
cout << "请输入寄件人姓名: ";
string sender_name;
cin >> sender_name;
express.push_back(sender_name);
cout << "请输入寄件人手机号: ";
string sender_phone_number;
cin >> sender_phone_number;
express.push_back(sender_phone_number);
cout << "请输入寄件人住址: ";
string sender_address;
cin >> sender_address;
express.push_back(sender_address);
cout << "请输入收件人姓名: ";
string receiver_name;
cin >> receiver_name;
express.push_back(receiver_name);
cout << "请输入收件人手机号: ";
string receiver_phone_number;
cin >> receiver_phone_number;
express.push_back(receiver_phone_number);
cout << "请输入收件人住址: ";
string receiver_address;
cin >> receiver_address;
express.push_back(receiver_address);
express_list.push_back(express);
cout << "快递信息录入成功!" << endl;
}
// 删除快递信息
void delete_express() {
string express_id;
cout << "请输入要删除的快递单号: ";
cin >> express_id;
bool found = false;
for (int i = 0; i < express_list.size(); i++) {
if (express_list[i][0] == express_id) {
found = true;
express_list.erase(express_list.begin() + i);
cout << "快递信息删除成功!" << endl;
break;
}
}
if (!found) {
cout << "未找到符合条件的快递信息!" << endl;
}
}
// 修改快递信息
void modify_express() {
string express_id;
cout << "请输入要修改的快递单号: ";
cin >> express_id;
bool found = false;
for (int i = 0; i < express_list.size(); i++) {
if (express_list[i][0] == express_id) {
found = true;
cout << "请输入寄件人姓名(" << express_list[i][1] << "): ";
string sender_name;
cin >> sender_name;
express_list[i][1] = sender_name;
cout << "请输入寄件人手机号(" << express_list[i][2] << "): ";
string sender_phone_number;
cin >> sender_phone_number;
express_list[i][2] = sender_phone_number;
cout << "请输入寄件人住址(" << express_list[i][3] << "): ";
string sender_address;
cin >> sender_address;
express_list[i][3] = sender_address;
cout << "请输入收件人姓名(" << express_list[i][4] << "): ";
string receiver_name;
cin >> receiver_name;
express_list[i][4] = receiver_name;
cout << "请输入收件人手机号(" << express_list[i][5] << "): ";
string receiver_phone_number;
cin >> receiver_phone_number;
express_list[i][5] = receiver_phone_number;
cout << "请输入收件人住址(" << express_list[i][6] << "): ";
string receiver_address;
cin >> receiver_address;
express_list[i][6] = receiver_address;
cout << "快递信息修改成功!" << endl;
break;
}
}
if (!found) {
cout << "未找到符合条件的快递信息!" << endl;
}
}
// 查询已取快件
void query_taken_express() {
bool found = false;
for (int i = 0; i < express_list.size(); i++) {
if (express_list[i].size() > 7 && express_list[i][7] == "1") {
found = true;
cout << "快递单号:" << express_list[i][0] << endl;
cout << "寄件人:" << express_list[i][1] << endl;
cout << "寄件人手机号:" << express_list[i][2] << endl;
cout << "寄件人住址:" << express_list[i][3] << endl;
cout << "收件人:" << express_list[i][4] << endl;
cout << "收件人手机号:" << express_list[i][5] << endl;
cout << "收件人住址:" << express_list[i][6] << endl;
cout << endl;
}
}
if (!found) {
cout << "未找到已取快件信息!" << endl;
}
}
// 查询未取快件
void query_untaken_express() {
bool found = false;
for (int i = 0; i < express_list.size(); i++) {
if (express_list[i].size() <= 7 || express_list[i][7] == "0") {
found = true;
cout << "快递单号:" << express_list[i][0] << endl;
cout << "寄件人:" << express_list[i][1] << endl;
cout << "寄件人手机号:" << express_list[i][2] << endl;
cout << "寄件人住址:" << express_list[i][3] << endl;
cout << "收件人:" << express_list[i][4] << endl;
cout << "收件人手机号:" << express_list[i][5] << endl;
cout << "收件人住址:" << express_list[i][6] << endl;
cout << endl;
}
}
if (!found) {
cout << "未找到未取快件信息!" << endl;
}
}
// 管理员模式
void admin_mode() {
string username;
string password;
cout << "请输入管理员账号: ";
cin >> username;
cout << "请输入管理员密码: ";
cin >> password;
if (username != "admin" || password != "123456") {
cout << "管理员账号或密码错误!" << endl;
return;
}
string choice;
do {
cout << "请选择操作(1. 录入快递,2. 删除快递,3. 修改快递,4. 查询已取快件,5. 查询未取快件,6. 返回主菜单): ";
cin >> choice;
while (choice != "1" && choice != "2" && choice != "3" && choice != "4" && choice != "5" && choice != "6") {
cout << "输入有误,请重新输入!" << endl;
cout << "请选择操作(1. 录入快递,2. 删除快
阅读全文