blob: 1bfa66e96a166913453bcdc4a398465d098e9e71 (
plain) (
blame)
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
|
#include <iostream>
#include <cstring>
#include "Product.h"
void ProductArray::add(const Product& product) {
if (count >= allocated) {
std::cout << "No more products are allowed!" << std::endl;
return;
}
products[count++] = product;
}
Product* ProductArray::find(char* username) {
for (unsigned i = 0; i < count; ++i)
if (strcmp(username, products[i].name) == 0)
return &products[i];
return nullptr;
}
ProductArray newProductArray(unsigned allocatedSize) {
ProductArray pa;
pa.products = new Product[allocatedSize];
pa.count = 0;
pa.allocated = allocatedSize;
return pa;
}
void deleteProductArray(ProductArray& pa) {
delete[] pa.products;
pa.products = nullptr;
pa.count = pa.allocated = 0;
}
|