-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransactionBasket.cpp
97 lines (78 loc) · 1.95 KB
/
transactionBasket.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
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
//By Gabriel Pereyra
#include "transactionBasket.h"
TransactionBasket::TransactionBasket()
{
mSize = 0;
Transaction *transactionList = new Transaction[mSize];
}
TransactionBasket::TransactionBasket(int newSize)
{
mSize = newSize;
Transaction *transactionList = new Transaction[mSize];
}
TransactionBasket::~TransactionBasket()
{
/*mSize = NULL;
delete[] mTransactionList;*/
}
//opens file and populates initial transactions
void TransactionBasket::populateWithFile(string fileName)
{
//tmp variables for storing the data
int transNum;
int tmpItem;
int tmpSize = 0;
mSize = LARGEST_SIZE; //default largest data size
Transaction *transactionList = new Transaction[mSize];
ifstream data;
data.open(fileName);
while (!data.eof())
{
data >> transNum;
data >> tmpItem;
transactionList[transNum - 1].addItem(tmpItem); //-1 cause array positioning
if (tmpSize != transNum)
tmpSize++;
}
data.close();
mSize = tmpSize;
}
//populates a new basket with the relevant transactions from the previous basket
void TransactionBasket::populate(TransactionBasket otherBasket)
{
Transaction *tmpList = new Transaction[mSize]; //tmp list to copy relevant transactions
int tmpSize = 0; //keeps track of new transactions to determine new size
//fill temp list
for (int i = 0; i < mSize; i++)
{
if (otherBasket.getTransaction(i).getRelevant() == true)
{
tmpList[tmpSize] = otherBasket.getTransaction(i);
tmpSize++;
}
}
//populate actual list
for (int j = 0; j < tmpSize; j++)
{
mTransactionList[j] = tmpList[j];
}
mSize = tmpSize;
}
//getters and setters for the size member
int TransactionBasket::getSize()
{
return mSize;
}
void TransactionBasket::setSize(int size)
{
mSize = size;
}
//getter for accessing specific transactions
Transaction& TransactionBasket::getTransaction(int position)
{
return mTransactionList[position];
}
void TransactionBasket::setTransaction(Transaction &newTrans, int choice)
{
mTransactionList[choice] = newTrans;
}