用c++实现一个完整的团购订单信息管理系统。该系统现团购订单信息的添加、查找、修改、删除、浏览等功能。要求输入登录口令,口令正确才可以继续操作。用结构体数组实现。具体功能说明如下。 (1)添加订单。 输入要添加的订单信息,包括订单编号(唯一)、商品编号、商品名称、商品单价、商品数量、收件人地址、收件人姓名、收件人电话等信息。判断订单编号是否已经存在,若存在则重新输入。将订单信息存入结构体数组中。 (2)查找订单。 设置二级菜单,可以通过订单编号、商品编号、收件人姓名等多途径进行订单查询,查 找出符合条件的一条或多条记录,并输出显示。 (3)修改订单。 先按订单编号查找订单,然后修改其信息。除订单编号外,可以修改商品编号、商品名 称、商品单价、商品数量、收件人地址、收件人姓名、收件人电话等信息。 (4)删除订单。 可输入订单编号进行删除,这时查询到的订单唯一,可直接删除,删除前要进行确认,确认是否真要删除。也可通过商品编号、收件人姓名等进行删除,这时查找到的订单不唯一,显示出所有符合条件的订单,要求输入要删除的订单号,删除唯一订单。 (5)浏览订单。 遍历存有所有订单信息的顺序表,按顺序依次显示所有订单。若无订单,则提示系统中无订单。
时间: 2023-12-19 11:04:49 浏览: 103
以下是一个简单的团购订单信息管理系统的 C++ 实现,代码中使用结构体数组实现存储订单信息,并使用口令保护系统。具体功能实现如下:
```cpp
#include <iostream>
#include <string>
using namespace std;
const int MAX_ORDERS = 100; // 最大订单数量
// 订单信息结构体
struct Order {
string orderNo; // 订单编号
string productNo; // 商品编号
string productName; // 商品名称
double price; // 商品单价
int quantity; // 商品数量
string address; // 收件人地址
string name; // 收件人姓名
string phone; // 收件人电话
};
// 订单管理系统类
class OrderManagementSystem {
public:
OrderManagementSystem(string password); // 构造函数
void run(); // 运行系统
private:
Order orders[MAX_ORDERS]; // 存储所有订单信息的结构体数组
int orderCount; // 订单数量
string password; // 系统登录密码
// 私有成员函数
void addOrder(); // 添加订单
void searchOrder(); // 查找订单
void modifyOrder(); // 修改订单
void deleteOrder(); // 删除订单
void browseOrders(); // 浏览订单
};
// 构造函数
OrderManagementSystem::OrderManagementSystem(string password) {
orderCount = 0;
this->password = password;
}
// 运行系统
void OrderManagementSystem::run() {
// 输入登录口令
string inputPwd;
cout << "请输入登录口令:";
cin >> inputPwd;
if (inputPwd != password) {
cout << "口令错误,系统无法启动!" << endl;
return;
}
// 显示功能菜单
cout << "欢迎使用团购订单信息管理系统!" << endl;
while (true) {
cout << "请选择要执行的操作:" << endl;
cout << "1. 添加订单" << endl;
cout << "2. 查找订单" << endl;
cout << "3. 修改订单" << endl;
cout << "4. 删除订单" << endl;
cout << "5. 浏览订单" << endl;
cout << "6. 退出系统" << endl;
int choice;
cin >> choice;
switch (choice) {
case 1:
addOrder();
break;
case 2:
searchOrder();
break;
case 3:
modifyOrder();
break;
case 4:
deleteOrder();
break;
case 5:
browseOrders();
break;
case 6:
cout << "感谢使用团购订单信息管理系统,再见!" << endl;
return;
default:
cout << "无效的选项,请重新选择。" << endl;
}
}
}
// 添加订单
void OrderManagementSystem::addOrder() {
// 输入订单信息
Order order;
cout << "请输入订单编号:";
cin >> order.orderNo;
// 判断订单编号是否已经存在
for (int i = 0; i < orderCount; i++) {
if (orders[i].orderNo == order.orderNo) {
cout << "订单编号已经存在,请重新输入。" << endl;
return;
}
}
cout << "请输入商品编号:";
cin >> order.productNo;
cout << "请输入商品名称:";
cin >> order.productName;
cout << "请输入商品单价:";
cin >> order.price;
cout << "请输入商品数量:";
cin >> order.quantity;
cout << "请输入收件人地址:";
cin >> order.address;
cout << "请输入收件人姓名:";
cin >> order.name;
cout << "请输入收件人电话:";
cin >> order.phone;
// 将订单信息存入数组
orders[orderCount++] = order;
cout << "订单添加成功!" << endl;
}
// 查找订单
void OrderManagementSystem::searchOrder() {
cout << "请选择查询方式:" << endl;
cout << "1. 按订单编号查询" << endl;
cout << "2. 按商品编号查询" << endl;
cout << "3. 按收件人姓名查询" << endl;
int choice;
cin >> choice;
switch (choice) {
case 1: {
string orderNo;
cout << "请输入订单编号:";
cin >> orderNo;
bool found = false;
for (int i = 0; i < orderCount; i++) {
if (orders[i].orderNo == orderNo) {
cout << "订单信息如下:" << endl;
cout << "订单编号:" << orders[i].orderNo << endl;
cout << "商品编号:" << orders[i].productNo << endl;
cout << "商品名称:" << orders[i].productName << endl;
cout << "商品单价:" << orders[i].price << endl;
cout << "商品数量:" << orders[i].quantity << endl;
cout << "收件人地址:" << orders[i].address << endl;
cout << "收件人姓名:" << orders[i].name << endl;
cout << "收件人电话:" << orders[i].phone << endl;
found = true;
break;
}
}
if (!found) {
cout << "未找到订单信息!" << endl;
}
break;
}
case 2: {
string productNo;
cout << "请输入商品编号:";
cin >> productNo;
bool found = false;
for (int i = 0; i < orderCount; i++) {
if (orders[i].productNo == productNo) {
cout << "订单编号:" << orders[i].orderNo << endl;
cout << "商品编号:" << orders[i].productNo << endl;
cout << "商品名称:" << orders[i].productName << endl;
cout << "商品单价:" << orders[i].price << endl;
cout << "商品数量:" << orders[i].quantity << endl;
cout << "收件人地址:" << orders[i].address << endl;
cout << "收件人姓名:" << orders[i].name << endl;
cout << "收件人电话:" << orders[i].phone << endl;
found = true;
}
}
if (!found) {
cout << "未找到订单信息!" << endl;
}
break;
}
case 3: {
string name;
cout << "请输入收件人姓名:";
cin >> name;
bool found = false;
for (int i = 0; i < orderCount; i++) {
if (orders[i].name == name) {
cout << "订单编号:" << orders[i].orderNo << endl;
cout << "商品编号:" << orders[i].productNo << endl;
cout << "商品名称:" << orders[i].productName << endl;
cout << "商品单价:" << orders[i].price << endl;
cout << "商品数量:" << orders[i].quantity << endl;
cout << "收件人地址:" << orders[i].address << endl;
cout << "收件人姓名:" << orders[i].name << endl;
cout << "收件人电话:" << orders[i].phone << endl;
found = true;
}
}
if (!found) {
cout << "未找到订单信息!" << endl;
}
break;
}
default:
cout << "无效的选项,请重新选择。" << endl;
}
}
// 修改订单
void OrderManagementSystem::modifyOrder() {
string orderNo;
cout << "请输入要修改的订单编号:";
cin >> orderNo;
bool found = false;
for (int i = 0; i < orderCount; i++) {
if (orders[i].orderNo == orderNo) {
cout << "请输入要修改的信息:" << endl;
cout << "商品编号(原值:" << orders[i].productNo << "):";
cin >> orders[i].productNo;
cout << "商品名称(原值:" << orders[i].productName << "):";
cin >> orders[i].productName;
cout << "商品单价(原值:" << orders[i].price << "):";
cin >> orders[i].price;
cout << "商品数量(原值:" << orders[i].quantity << "):";
cin >> orders[i].quantity;
cout << "收件人地址(原值:" << orders[i].address << "):";
cin >> orders[i].address;
cout << "收件人姓名(原值:" << orders[i].name << "):";
cin >> orders[i].name;
cout << "收件人电话(原值:" << orders[i].phone << "):";
cin >> orders[i].phone;
cout << "订单信息修改成功!" << endl;
found = true;
break;
}
}
if (!found) {
cout << "未找到订单信息!" << endl;
}
}
// 删除订单
void OrderManagementSystem::deleteOrder() {
cout << "请选择删除方式:" << endl;
cout << "1. 按订单编号删除" << endl;
cout << "2. 按商品编号删除" << endl;
cout << "3. 按收件人姓名删除" << endl;
int choice;
cin >> choice;
switch (choice) {
case 1: {
string orderNo;
cout << "请输入要删除的订单编号:";
cin >> orderNo;
bool found = false;
for (int i = 0; i < orderCount; i++) {
if (orders[i].orderNo == orderNo) {
cout << "订单信息如下:" << endl;
cout << "订单编号:" << orders[i].orderNo << endl;
cout << "商品编号:" << orders[i].productNo << endl;
cout << "商品名称:" << orders[i].productName << endl;
cout << "商品单价:" << orders[i].price << endl;
cout << "商品数量:" << orders[i].quantity << endl;
cout << "收件人地址:" << orders[i].address << endl;
cout << "收件人姓名:" << orders[i].name << endl;
cout << "收件人电话:" << orders[i].phone << endl;
cout << "确认要删除此订单吗?(Y/N)";
char confirm;
cin >> confirm;
if (confirm == 'Y' || confirm == 'y') {
for (int j = i; j < orderCount - 1; j++) {
orders[j] = orders[j + 1];
}
orderCount--;
cout << "订单删除成功!" << endl;
}
found = true;
break;
}
}
if (!found) {
cout << "未找到订单信息!" << endl;
}
break;
}
case 2: {
string productNo;
cout << "请输入要删除的商品编号:";
cin >> productNo;
int count = 0;
for (int i = 0; i < orderCount; i++) {
if (orders[i].productNo == productNo) {
count++;
}
}
if (count == 1) {
for (int i = 0; i < orderCount; i++) {
if (orders[i].productNo == productNo) {
cout << "订单信息如下:" << endl;
cout << "订单编号:" << orders[i].orderNo << endl;
cout << "商品编号:" << orders[i].productNo << endl;
cout << "商品名称:" << orders[i].productName << endl;
cout << "商品单价:" << orders[i].price << endl;
cout << "商品数量:" << orders[i].quantity << endl;
cout << "收件人地址:" << orders[i].address << endl;
cout << "收件人姓名:" << orders[i].name << endl;
cout << "收件人电话:" << orders[i].phone << endl;
cout << "确认要删除此订单吗?(Y/N)";
char confirm;
cin >> confirm;
if (confirm == 'Y' || confirm == 'y') {
for (int j = i; j < orderCount - 1; j++) {
orders[j] = orders[j + 1];
}
orderCount--;
cout << "订单删除成功!" << endl;
}
break;
}
}
}
else if (count > 1) {
cout << "找到以下订单信息:" << endl;
for (int i = 0; i < orderCount; i++) {
if (orders[i].productNo == productNo) {
cout << "订单编号:" << orders[i].orderNo << endl;
cout << "商品编号:" << orders[i].productNo << endl;
cout << "商品名称:" << orders[i].productName << endl;
cout << "商品单价:" << orders[i].price << endl;
cout << "商品数量:" << orders[i].quantity << endl;
cout << "收件人地址:" << orders[i].address << endl;
cout << "收件人姓名:" << orders[i].name << endl;
cout << "收件人电话:" << orders[i].phone << endl;
}
}
string orderNo;
cout << "请输入要删除的订单编号:";
cin >> orderNo;
bool found = false;
for (int i = 0; i < orderCount; i++) {
if (orders[i].orderNo == orderNo) {
for (int j = i; j < orderCount - 1; j++) {
orders[j] = orders[j + 1];
}
orderCount--;
cout << "订单删除成功!" << endl;
found = true;
break;
}
}
if (!found) {
cout << "未找到订单信息!" << endl;
}
}
else {
cout << "未找到订单信息!" << endl;
}
break;
}
case 3: {
string name;
cout << "请输入收件人姓名:";
cin >> name;
int count = 0;
for (int i = 0; i < orderCount; i++) {
if (orders[i].name == name) {
count++;
}
}
if (count == 1) {
for (int i = 0; i < orderCount; i++) {
if (orders[i].name == name) {
cout << "订单信息如下:" << endl;
cout << "订单编号:" << orders[i].orderNo << endl;
cout << "商品编号:" << orders[i].productNo << endl;
cout << "商品名称:" << orders[i].productName << endl;
cout << "商品单价:" << orders[i].price << endl;
cout << "商品数量:" << orders[i].quantity << endl;
cout << "收件人地址:" << orders[i].address << endl;
cout << "收件人姓名:" << orders[i].name << endl;
cout << "收件人电话:" << orders[i].phone << endl;
cout << "确认要删除此订单吗?(Y/N)";
char confirm;
cin >> confirm;
if (confirm == 'Y' || confirm == 'y') {
for (int j = i; j < orderCount - 1; j++) {
orders[j] = orders[j + 1];
}
orderCount--;
cout << "订单删除成功!" << endl;
}
break;
}
}
}
else if (count > 1) {
cout << "找到以下订单信息:" << endl;
for (int i = 0; i < orderCount; i++) {
if (orders[i].name == name)
阅读全文