#include #include #include "list.h" #include "item.h" using namespace std; void List::createList(int size) { itemList = new Item [size]; arrayLength = size; } void List::print() { totalPrice = 0; cout << "Name Amount Units Price Extended Price" << endl; for(int j =0; j < arrayLength; j++) { itemList[j].display(); //cout << "flag" << j << arrayLength << endl; totalPrice = totalPrice + itemList[j].extendedPrice; } cout << "\nTotal Price: " << totalPrice << endl; } void List::addItem() { string n, u; double a; double p; cout << "Enter the name of the item: "; cin >> n; cout << "Enter the units of the item: "; cin >> u; cout << "Enter the amount: "; cin >> a; cout << "Enter the price per each " << u << ": "; cin >> p; addToArray(); itemList[arrayLength - 1].create(n, u, a, p); } void List::removeItem(std::string name) { //cout << "Array length " << arrayLength << endl; for(int i =0; i < arrayLength; i++) { if(name == itemList[i].returnName()) { //delete itemList[i]; for(int k = i; k < arrayLength - 1; k++) { itemList[k] = itemList[k+1]; } //delete &itemList[arrayLength - 1]; //itemList[arrayLength - 1] = NULL; arrayLength--; return; } } cout << "Item not found" << endl; //need to shift all items } void List::addToArray() { if(arrayLength == 0) { delete [] itemList; itemList = new Item [arrayLength + 1]; arrayLength = arrayLength + 1; } else { temp = new Item [arrayLength]; for(int h = 0; h < arrayLength; h++) { temp[h] = itemList[h]; } //temp = itemList; delete [] itemList; //itemList = NULL; itemList = new Item [arrayLength + 1]; for(int l = 0; l < arrayLength; l++) { itemList[l] = temp[l]; } //itemList = temp; delete [] temp; //temp = NULL; arrayLength = arrayLength + 1; } }