rendered paste bodyArrayMaster.h///////////////////////////////////////////////////////////////////////////////
#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();
};
ArrayMaster.cpp/////////////////////////////////////////////////////////////////////////////////
#include"ArrayMaster.h"
ArrayMaster::ArrayMaster(){
pitem = new item*[1];//a pointer to an array of pointers the size of item objects
pitem[0]=&item();/**/
}
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){
if(capacity>1){
resize(capacity,capacity++);
(*pitem)[capacity].setAll(catagory, description, priority);
}
else (*pitem)[0].setAll(catagory, description, priority);
}
string ArrayMaster::returnBoxContents(bool detailed, int menuChoice, bool all){
stringstream itemInformation;
do{
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;
}
Item.h///////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <string>
using namespace std;
class item{
private:
public:
string catagory, description, priority;
item(string catagory="",
string description="", string priority="");
string getcatagory();
string getdescription();
string getpriority();
void setAll(string newcatagory, string newdescription,
string newpriority);
};
Item.cpp////////////////////////////////////////////////////////////////////////////////////
#include "Item.h"
item::item(string catagory,
string description, string priority){
}
void item::setAll(string newcatagory, string newdescription,
string newpriority){
string catagory=newcatagory;
string description=newdescription;
string priority=newpriority;
}
string item::getcatagory(){
return catagory;
}
string item::getdescription(){
return description;
}
string item::getpriority(){
return priority;
}