-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.cpp
55 lines (49 loc) · 1.32 KB
/
Utilities.cpp
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
/*
name: Youngeun Hong
ID: 159100171
Email: yhong38@myseneca.ca
Date: 2019-07-17
*/
// Workshop 8 - Smart Pointers
// Utilities.cpp
// Chris Szalwinski from Cornel Barna
// 2019/03/17
#include <memory>
#include "List.h"
#include "Element.h"
#include "Utilities.h"
using namespace std;
namespace sict {
List<Product> mergeRaw(const List<Description>& desc, const List<Price>& price) {
List<Product> priceList;
// TODO: Add your code here to build a list of products
// using raw pointers
for (size_t i = 0; i < desc.size(); i++) {
for (size_t j = 0; j < price.size(); j++) {
if (desc[i].code == price[j].code) {
Product* ptr = new Product(desc[i].desc, price[j].price);
ptr->validate();
priceList += ptr;
delete ptr;
ptr = nullptr;
}
}
}
return priceList;
}
List<Product> mergeSmart(const List<Description>& desc, const List<Price>& price) {
List<Product> priceList;
// TODO: Add your code here to build a list of products
// using smart pointers
for (size_t i = 0; i < desc.size(); i++) {
for (size_t j = 0; j < price.size(); j++) {
if (desc[i].code == price[j].code) {
std::unique_ptr<Product> ptr(new Product(desc[i].desc, price[j].price));
ptr->validate();
priceList += ptr;
}
}
}
return priceList;
}
}