-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhone Inventory Management System-Using Namespace.cpp
More file actions
102 lines (86 loc) · 2.67 KB
/
Phone Inventory Management System-Using Namespace.cpp
File metadata and controls
102 lines (86 loc) · 2.67 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <string>
using namespace std;
namespace Inventory {
namespace Electronics {
class Smartphone {
private:
string modelName;
float price;
int quantity;
public:
void setModelName(const string& name) {
modelName = name;
}
void setPrice(float p) {
price = p;
}
void setQuantity(int q) {
quantity = q;
}
string getModelName() const {
return modelName;
}
float getPrice() const {
return price;
}
int getQuantity() const {
return quantity;
}
};
}
}
int main() {
using namespace Inventory::Electronics;
Smartphone phones[10];
int phoneCount = 0;
int choice;
while (true) {
cout << "Menu:\n";
cout << "1. Add a phone\n";
cout << "2. Display phones\n";
cout << "3. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
if (choice == 1) {
if (phoneCount >= 10) {
cout << "Cannot add more phones. Array is full.\n";
} else {
string name;
float p;
int q;
cout << "Enter model name: ";
cin >> name;
cout << "Enter price: ";
cin >> p;
cout << "Enter quantity: ";
cin >> q;
Smartphone phone;
phone.setModelName(name);
phone.setPrice(p);
phone.setQuantity(q);
phones[phoneCount] = phone;
phoneCount++;
cout << "Phone added successfully!\n";
}
} else if (choice == 2) {
if (phoneCount == 0) {
cout << "No phones added yet.\n";
} else {
cout << "Phone List:\n";
for (int i = 0; i < phoneCount; i++) {
cout << "Model Name: " << phones[i].getModelName() << endl;
cout << "Price: $" << phones[i].getPrice() << endl;
cout << "Quantity: " << phones[i].getQuantity() << endl;
cout << "-----------------------\n";
}
}
} else if (choice == 3) {
cout << "Exiting program.\n";
break;
} else {
cout << "Invalid choice. Please try again.\n";
}
}
return 0;
}