rendered paste body#include<string>
#include<fstream>
#include<iostream>
#include<sstream>
using namespace std;
class ArrayMaster{
private:
public:
int capacity;
ArrayMaster();
~ArrayMaster();
Item **pitem;//2 stars to know that this pointer points to a pointer
Item **temppitem;
//int returnCapacity();
void storeItem(string catagory,string description, string priority);
string returnBoxContents(bool detailed=0, int menuChoice=0, bool all=0);
void resize(int &capacity, int newcapacity);
void deleteItem(int menuChoice);
void loadFile();
void saveToFile();
};
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include"ArrayMaster.h"
ArrayMaster::ArrayMaster(){
pitem = new Item*[1];//a pointer to an array of pointers the size of item objects
}
void ArrayMaster::resize(int &capacity, int newcapacity){//got to keep capacity updated
capacity=newcapacity;
temppitem = new Item*[capacity];
for (int i=0; i<capacity; i++){
pitem[i] = temppitem[i];
}
delete [] pitem;
pitem=temppitem;
}
void ArrayMaster::storeItem(string catagory
,string description, string priority){
capacity=1;
cout<<capacity;
if(capacity>1){
resize(capacity,capacity++);
(*pitem)[capacity].setAll(catagory, description, priority);
}
else{cout<<"\nTEST1\n";
pitem[0]->setAll(catagory, description, priority);///////////////////////////CRASH
cout<<"\nTEST2\n";}
}
string ArrayMaster::returnBoxContents(bool detailed, int menuChoice, bool all){
stringstream itemInformation;
do{
cout<<endl<<"capacity is "<<capacity<<endl;
if (menuChoice<capacity){
itemInformation <<"\nItem Number: "<<menuChoice<<endl;
itemInformation <<"Catagory: "<<(*pitem)[menuChoice].getcatagory()<<endl;
if (detailed == true){
itemInformation <<"Description: "<<(*pitem)[menuChoice].getdescription()<<endl;
itemInformation <<"Priority: "<<(*pitem)[menuChoice].getpriority()<<endl;
}
}
else{ itemInformation <<"\nItem "<<menuChoice<<" does not exist!"<<endl;
}
menuChoice++;
if (menuChoice==capacity){
all=0;
}
return itemInformation.str();
}while (all==1);
}
void ArrayMaster::deleteItem(int focus){
int shifts=capacity-focus;//shifts is the number of times to redirect pointers
for(int i=1;i<shifts;i++){
pitem[focus] = pitem[focus++];
}
pitem[focus] = NULL;
resize(capacity, capacity-1);
}
void ArrayMaster::loadFile(){
ifstream inStream;
inStream.open("defaultSettingFile.txt");
string catagory, description, priority;
while(!inStream.eof()){
inStream >>catagory>>description>>priority;
storeItem(catagory,description, priority);
}
inStream.close();
}
void ArrayMaster::saveToFile(){//this does NOT erase file prior to saving.
ofstream outStream;
outStream.open("userFile.txt");
int counter=0;
while(counter<capacity){
outStream<<(*pitem)[counter].getcatagory()<<endl;
outStream<<(*pitem)[counter].getdescription()<<endl;
outStream<<(*pitem)[counter].getpriority()<<endl;
counter++;
}
}
//int ArrayMaster::returnCapacity(){
// return capacity;
//}
ArrayMaster::~ArrayMaster(){
delete [] pitem;
}