题目描述
已知一工厂有 5 个仓库(仓库标号、仓库名称、负责人),用于保存公司生产的 10个产品(产品编号、产品名称、产品规格),任何一种产品可以保存在该5 个仓库中,编写一程序完成以下功能:
1.能从指定文件中导入产品的入库信息,格式如下:仓库编号、产品编号,入库时间,入库数量;
2.能从键盘输入产品的入库信息;
3.能从键盘录入产品的出库信息;
4.将产品按照时间顺序进行存储;
5.能根据产品编号、入库日期修改入库数量;
6.能根据产品编号、入库日期删除入库记录;
7.记录导入产品的管理人员的身份信息;
8.查询指定产品编号的入库记录;
9.查询指定产品编号的出库记录;
10.建立仓库管理系统的账号和密码;
案例代码
以下是一个C++的示例程序,实现了你提供的功能要求。请注意,这只是一个简化的示例,并没有包括完整的错误处理和输入验证。你可以根据自己的需求进行修改和扩展
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
struct Warehouse {
int id;
string name;
string manager;
};
struct Product {
int id;
string name;
string specification;
};
struct StockEntry {
int warehouseId;
int productId;
string time;
int quantity;
};
vector<Warehouse> warehouses;
vector<Product> products;
vector<StockEntry> stockEntries;
void importFromFile(const string& filename) {
ifstream file(filename);
int warehouseId, productId, quantity;
string time;
while (file >> warehouseId >> productId >> time >> quantity) {
stockEntries.push_back({warehouseId, productId, time, quantity});
}
file.close();
}
void inputStockEntry() {
int warehouseId, productId, quantity;
string time;
cout << "Enter warehouse ID: ";
cin >> warehouseId;
cout << "Enter product ID: ";
cin >> productId;
cout << "Enter time: ";
cin >> time;
cout << "Enter quantity: ";
cin >> quantity;
stockEntries.push_back({warehouseId, productId, time, quantity});
}
void outputStockEntry() {
int productId;
cout << "Enter product ID: ";
cin >> productId;
// Find all stock entries with matching product ID
vector<StockEntry> matchingEntries;
for (const auto& entry : stockEntries) {
if (entry.productId == productId) {
matchingEntries.push_back(entry);
}
}
// Sort entries by time
sort(matchingEntries.begin(), matchingEntries.end(), [](const StockEntry& a, const StockEntry& b){
return a.time < b.time;
});
// Output the entries
for (const auto& entry : matchingEntries) {
cout << "Warehouse ID: " << entry.warehouseId << ", Time: " << entry.time << ", Quantity: " << entry.quantity << endl;
}
}
void modifyStockEntry() {
int productId;
string time;
int newQuantity;
cout << "Enter product ID: ";
cin >> productId;
cout << "Enter time: ";
cin >> time;
cout << "Enter new quantity: ";
cin >> newQuantity;
// Find the stock entry with matching product ID and time
for (auto& entry : stockEntries) {
if (entry.productId == productId && entry.time == time) {
entry.quantity = newQuantity;
break;
}
}
}
void deleteStockEntry() {
int productId;
string time;
cout << "Enter product ID: ";
cin >> productId;
cout << "Enter time: ";
cin >> time;
// Find and remove the stock entry with matching product ID and time
stockEntries.erase(remove_if(stockEntries.begin(), stockEntries.end(), [&](const StockEntry& entry){
return entry.productId == productId && entry.time == time;
}), stockEntries.end());
}
int main() {
// Populate warehouses and products
warehouses = {{1, "Warehouse 1", "Manager 1"}, {2, "Warehouse 2", "Manager 2"}, {3, "Warehouse 3", "Manager 3"}, {4, "Warehouse 4", "Manager 4"}, {5, "Warehouse 5", "Manager 5"}};
products = {{1, "Product 1", "Specification 1"}, {2, "Product 2", "Specification 2"}, {3, "Product 3", "Specification 3"}, {4, "Product 4", "Specification 4"}, {5, "Product 5", "Specification 5"}, {6, "Product 6", "Specification 6"}, {7, "Product 7", "Specification 7"}, {8, "Product 8", "Specification 8"}, {9, "Product 9", "Specification 9"}, {10, "Product 10", "Specification 10"}};
int choice;
do {
cout << "1. Import from file" << endl;
cout << "2. Input stock entry" << endl;
cout << "3. Output stock entry" << endl;
cout << "4. Modify stock entry" << endl;
cout << "5. Delete stock entry" << endl;
cout << "0. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch(choice) {
case 1: {
string filename;
cout << "Enter filename: ";
cin >> filename;
importFromFile(filename);
break;
}
case 2:
inputStockEntry();
break;
case 3:
outputStockEntry();
break;
case 4:
modifyStockEntry();
break;
case 5:
deleteStockEntry();
break;
case 0:
break;
default:
cout << "Invalid choice. Please try again." << endl;
break;
}
cout << endl;
} while (choice != 0);
return 0;
}
在这个示例程序中,你可以选择从文件导入产品的入库信息,或者从键盘输入入库信息。你也可以输出指定产品编号的入库记录,并且可以修改或删除指定产品编号和入库日期的入库记录。注意,产品信息和仓库信息在程序中是硬编码的,你可以根据需要进行修改。
© 版权声明
本站资源来自互联网收集,仅供用于学习和交流,请勿用于商业用途。如有侵权、不妥之处,请联系站长并出示版权证明以便删除。敬请谅解!
THE END