Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (68 loc) · 2.79 KB
/
Copy pathmain.cpp
File metadata and controls
78 lines (68 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "InventoryManager.h"
#include "OrderProcessor.h"
#include <iostream>
#include <limits>
#include <string>
int main() {
InventoryManager inventory;
OrderProcessor orders(inventory);
std::cout << "Welcome to StoryMcStoreface!\n";
while (true) {
std::cout << "\n1. View inventory\n2. Place order\n3. Exit\nChoice: ";
int choice;
if (!(std::cin >> choice)) {
if (std::cin.eof()) break;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Please enter a menu number.\n";
continue;
}
if (choice == 3) break;
if (choice == 1) {
// Tight coupling: the user interface reads inventory's array directly.
for (int i = 0; i < inventory.productCount; ++i) {
const InventoryManager::Product& item = inventory.products[i];
std::cout << item.id << " | " << item.name << " | $"
<< item.priceCents / 100 << '.';
if (item.priceCents % 100 < 10) std::cout << '0';
std::cout << item.priceCents % 100
<< " | In stock: " << item.quantity << '\n';
}
} else if (choice == 2) {
int productId, quantity;
std::cout << "Product ID: ";
if (!(std::cin >> productId)) {
if (std::cin.eof()) break;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Product ID must be a number.\n";
continue;
}
std::cout << "Quantity: ";
if (!(std::cin >> quantity)) {
if (std::cin.eof()) break;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Quantity must be a number.\n";
continue;
}
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::string name, email, cardLastFour;
std::cout << "Customer name: ";
std::getline(std::cin, name);
std::cout << "Email (display only; no email is sent): ";
std::getline(std::cin, email);
std::cout << "FAKE card last four digits (e.g., 1234): ";
std::getline(std::cin, cardLastFour);
if (name.empty() || email.empty() || cardLastFour.empty()) {
std::cout << "All fields are required.\n";
continue;
}
orders.placeOrder(productId, quantity, name, email, cardLastFour);
} else {
std::cout << "Unknown menu choice.\n";
}
}
std::cout << "Goodbye!\n";
return 0;
}