+/EE312

software design

git clone https://git.julia.blue/+/EE312

Joseph RyanProject 76241299

master
1.8 KiB75 linesraw
1/*
2 * Name: Joseph Ryan
3 * EID: jbr2558
4 * Project 7, CRM part 2
5 * EE 312, Spring 2017
6 */
7#include <iostream>
8#include <cassert>
9#include "String.h"
10#include "CustomerDB.h"
11
12using namespace std;
13
14const int default_capacity = 1;
15
16Customer::Customer(String name) { // done, please do not edit
17    this->bottles = 0;
18    this->rattles = 0;
19    this->diapers = 0;
20    this->name = name;
21}
22
23CustomerDB::CustomerDB(void) { // done, please do not edit
24    this->capacity = default_capacity;
25    this->data = new Customer[this->capacity];
26    this->length = 0;
27}
28
29int CustomerDB::size(void) { // done, please do not edit
30    return this->length;
31}
32
33CustomerDB::~CustomerDB(void) { // done, please do not edit
34    delete[] this->data;
35}
36
37void CustomerDB::clear(void) { // done, please do not edit
38    delete[] this->data;
39    this->capacity = default_capacity;
40    this->data = new Customer[this->capacity];
41    this->length = 0;
42}
43
44Customer &CustomerDB::operator[](int k) { // done, please do not edit
45    assert(k >= 0 && k < this->length);
46    return this->data[k];
47}
48
49Customer &CustomerDB::operator[](String
50                                 name) { // not done, your effort goes here
51    for(int i = 0; i < length; ++i) {
52        if(data[i].name == name) {
53            return data[i];
54        }
55    }
56    if(length == capacity) {
57        Customer* newData = new Customer[capacity *=2];
58        for(int i=0;i < length;++i){
59            newData[i] = data[i];
60        }
61        delete[] data;
62        data = newData;
63    }
64    data[length++] = Customer(name);
65    return data[length - 1];
66}
67
68bool CustomerDB::isMember(String name) { // not done, your effort goes here
69    for(int i = 0; i < length; ++i) {
70        if(data[i].name == name) {
71            return true;
72        }
73    }
74    return false;
75}