-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputerAssembly.cpp
More file actions
331 lines (304 loc) · 7.57 KB
/
Copy pathComputerAssembly.cpp
File metadata and controls
331 lines (304 loc) · 7.57 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#include "ComputerAssembly.h"
#include "PCAssembly.h"
#include "MacAssembly.h"
ComputerAssembly::ComputerAssembly()
: totalCost(0), CA(NULL), Comp(NULL), powerSupply(NULL), battery(NULL), networkCard(NULL), storageDevice(NULL), deviceCase(NULL), RAM(NULL), physicalMemory(NULL) {}
// Create and return pointer to a storage device after taking user input and validation checks
// Parameter string to distinguish between laptops and tablets
StorageDevice* ComputerAssembly::createStorageDevice()
{
StorageDevice* SD = NULL;
int choice;
cout << "\nChoose the specs for your Storage Device\n";
cout << "1. 256GB HDD for $100\n";
cout << "2. 512GB HDD for $150\n";
cout << "3. 1TB HDD for $200\n";
cout << "4. 256GB SSD for $150\n";
cout << "5. 512GB SSD for $200\n";
cout << "6. 1TB SSD for $250\n\n";
while (true)
{
cin >> choice;
switch (choice)
{
case 1:
SD = new StorageDevice("HDD", 256, 100);
totalCost += 100;
return SD;
case 2:
SD = new StorageDevice("HDD", 512, 150);
totalCost += 150;
return SD;
case 3:
SD = new StorageDevice("HDD", 1024, 200);
totalCost += 200;
return SD;
case 4:
SD = new StorageDevice("SSD", 256, 150);
totalCost += 150;
return SD;
case 5:
SD = new StorageDevice("SSD", 512, 200);
totalCost += 200;
return SD;
case 6:
SD = new StorageDevice("SSD", 1024, 250);
totalCost += 250;
return SD;
default:
cout << "Please choose from the given options\n";
}
}
}
StorageDevice* ComputerAssembly::createStorageDevice(string)
{
StorageDevice* SD = NULL;
int choice;
cout << "\nChoose the specs for your Storage Device\n";
cout << "1. 64GB HDD for $30\n";
cout << "2. 128GB HDD for $50\n";
cout << "3. 256GB HDD for $95\n";
cout << "4. 64GB SSD for $40\n";
cout << "5. 128GB SSD for $70\n";
cout << "6. 256GB SSD for $135\n\n";
while (true)
{
cin >> choice;
switch (choice)
{
case 1:
SD = new StorageDevice("HDD", 64, 30);
totalCost += 30;
return SD;
case 2:
SD = new StorageDevice("HDD", 128, 50);
totalCost += 50;
return SD;
case 3:
SD = new StorageDevice("HDD", 256, 95);
totalCost += 95;
return SD;
case 4:
SD = new StorageDevice("SSD", 64, 40);
totalCost += 40;
return SD;
case 5:
SD = new StorageDevice("SSD", 128, 70);
totalCost += 70;
return SD;
case 6:
SD = new StorageDevice("SSD", 256, 135);
totalCost += 135;
return SD;
default:
cout << "Please choose from the given options\n";
}
}
}
// Create and return pointer to a NIC after taking user input and validation checks
NetworkCard* ComputerAssembly::createNetworkCard()
{
NetworkCard* NC = NULL;
int choice;
cout << "\nchoose your Network Card\n";
cout << "1. Wifi 15 Mbps for 40$\n";
cout << "2. Wifi 30 Mbps for 80$\n";
cout << "3. Ethernet 50 Mbps for 100$\n";
cout << "4. Ethernet 75 Mbps for 200$\n\n";
while (true)
{
cin >> choice;
switch (choice)
{
case 1:
NC = new NetworkCard("Wifi", 15, 40);
totalCost += 40;
return NC;
case 2:
NC = new NetworkCard("Wifi", 30, 80);
totalCost += 80;
return NC;
case 3:
NC = new NetworkCard("Ethernet", 50, 100);
totalCost += 100;
return NC;
case 4:
NC = new NetworkCard("EThernet", 75, 200);
totalCost += 200;
return NC;
default:
cout << "Please choose from the given options";
}
}
}
// give user three options of colors to choose from and returning it
string ComputerAssembly::chooseCaseColor()
{
cout << "Choose a color for your case\n1. Black\n2. Silver\n3. White\n\n";
int choice;
while (true)
{
cin >> choice;
switch (choice)
{
case 1:
return "Black";
case 2:
return "Silver";
case 3:
return "White";
default:
cout << "Please choose from the given options\n";
}
}
}
// Create and return pointer to a power Cable after taking user input and validation checks
PowerSupply* ComputerAssembly::createPowerSupply(int option1, int option2)
{
PowerSupply* pw = NULL;
int choice;
cout << "\nChoose your PowerCable\n";
cout << option1 << " watt options:\n";
cout << "1. 80 plus bronze for $100\n";
cout << "2. 80 plus silver for $120\n";
cout << "3. 80 plus gold for $140\n";
cout << option2 << " watt options:\n";
cout << "4. 80 plus bronze for $60\n";
cout << "5. 80 plus silver for $80\n";
cout << "6. 80 plus gold for $100\n\n";
while (true)
{
cin >> choice;
switch (choice)
{
case 1:
pw = new PowerSupply(option1, "80 PLUS Bronze", 100);
totalCost += 100;
return pw;
case 2:
pw = new PowerSupply(option1, "80 PLUS Silver", 120);
totalCost += 120;
return pw;
case 3:
pw = new PowerSupply(option1, "80 PLUS Gold", 140);
totalCost += 140;
return pw;
case 4:
pw = new PowerSupply(option2, "80 PLUS Bronze", 60);
totalCost += 60;
return pw;
case 5:
pw = new PowerSupply(option2, "80 PLUS Silver", 80);
totalCost += 80;
return pw;
case 6:
pw = new PowerSupply(option2, "80 PLUS Gold", 100);
totalCost += 100;
return pw;
default:
cout << "Choose from the given options:";
}
}
}
// Create and return pointer to a Battery after taking user input and validation checks
Battery* ComputerAssembly::createBattery(int lowerLimit, int upperLimit)
{
Battery* battery = NULL;
int choice;
cout << "\nHow much Battery do you need? (" << lowerLimit << "mAh - " << upperLimit << "mAh): ";
while (true)
{
cin >> choice;
if (!(choice % 2000) && choice >= lowerLimit && choice <= upperLimit)
{
battery = new Battery(choice,0.005*choice);
totalCost += battery->getPrice();
cout << "Cost is $" << battery->getPrice() << '\n';
return battery;
}
cout << "Choose a valid number\n";
}
}
// Create and return pointer to a RAM component after taking user input and validation checks
MainMemory* ComputerAssembly::createMainMemory(int lowerLimit, int upperLimit, int chipSize)
{
MainMemory* RAM = NULL;
int choice;
cout << "\nHow much ram do you need?(" << lowerLimit << "GB - " << upperLimit << "GB): ";
while (true)
{
cin >> choice;
if (!(choice % chipSize) && choice >= lowerLimit && choice <= upperLimit)
{
cout << "Cost is $" << 10 * choice << '\n';
totalCost += 10 * choice;
RAM = new MainMemory(choice, "Silicon");
return RAM;
}
cout << "choose a valid number\n";
}
}
ComputerAssembly::~ComputerAssembly()
{
delete powerSupply;
delete battery;
delete networkCard;
delete storageDevice;
delete deviceCase;
delete RAM;
delete physicalMemory;
}
// Give the user the choice of building a PC or Mac (Desktop, Laptop, Tablet)
// Once created give another option to display specs and/or cost
void ComputerAssembly::DisplayMenu()
{
int choice;
bool repeat = true;
cout << "Which Device do you want to create\n";
cout << "1. PC Desktop\n";
cout << "2. PC Laptop\n";
cout << "3. PC Tablet\n";
cout << "4. Mac Desktop\n";
cout << "5. Mac Laptop\n";
cout << "6. iPad\n";
while (repeat)
{
repeat = true;
cin >> choice;
if (choice >= 1 && choice <= 3)
{
CA = new PCAssembly;
CA->Build(Comp, choice);
repeat = false;
}
if (choice >= 4 && choice <= 6)
{
CA = new MacAssembly;
CA->Build(Comp, choice);
repeat = false;
}
}
repeat = true;
cout << "Congrats on your Purchase\n";
cout << "What do you want to do now ? \n";
cout << "1. Display specs\n";
cout << "2. See Cost\n";
cout << "3. Go home\n";
while (repeat)
{
cin >> choice;
switch (choice)
{
case 1:
Comp->getSpecs();
break;
case 2:
cout << "Cost = $" << Comp->getcost() << '\n';
break;
default:
return;
}
}
}
// Virtual Function (For building specific devices)
void ComputerAssembly::Build(Computer*& Comp, int choice) {}