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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
#ifndef _Data_BOX
#define _Data_BOX
// Declaration for the class PlainBox
template<class itemtype>
class Data
{
private:
// Data field
int capacity;
int num_used;
itemtype *vStore;
public:
Data (int Default_Size=10);
~Data(){delete [] vStore;};
bool isFull(int count);
bool isEmpty(int count1);
int arrayCapacity();
int numUsed(int count2);
void setItem (const itemtype& Entry,int count4);
itemtype getItem (int index);
int ADD(const itemtype& Entry, int count3);
int PosOfElem(const itemtype& Entry);
int SetPosOfElem(int pos,int number,int count2);
int Helper(const itemtype& Entry,int Default_Size,int capacity);
};
template<class itemtype>
Data<itemtype>::Data(int Default_Size){
capacity=10;
num_used=0;
vStore= new itemtype[Default_Size];
}
template<class itemtype>
bool Data<itemtype>::isFull(int count){
if(count==capacity)
cout<<"Array is Full"<<endl;
else
cout<<"Array is not full"<<endl;
return 0;
}
template<class itemtype>
bool Data<itemtype>::isEmpty(int count1){
if(count1==0)
cout<<"Array is empty"<<endl;
else
cout<<"Array is not empty"<<endl;
return 0;
}
template<class itemtype>
int Data<itemtype>::arrayCapacity(){return capacity;}
template<class itemtype>
int Data<itemtype>::numUsed(int count2){return count2;}
template<class itemtype>
void Data<itemtype>::setItem(const itemtype& Entry,int count4){
if(count4<=10){
vStore[num_used]=Entry;
num_used++;}
else
cout<<"Error, out of bounds."<<endl;
}
template<class itemtype>
itemtype Data<itemtype>::getItem(int index){
return vStore[index];
}
template<class itemtype>
int Data<itemtype>::ADD(const itemtype& Entry,int count3){
if(count3<=10){
vStore[num_used]=Entry;
num_used++;}
else
Helper(Entry,20,capacity);
return 0;
}
template<class itemtype>
int Data<itemtype>::PosOfElem(const itemtype& Entry){
for(int i=0;i<capacity;i++){
if(vStore[i]==Entry)
return i+1;
}
cout<<"Error"<<endl;
return -1;
}
template<class itemtype>
int Data<itemtype>::SetPosOfElem(int pos,int number, int count2){
if(pos>count2)
cout<<"Error"<<endl;
else
vStore[pos-1]=number;
return 0;
}
template<class itemtype>
int Data<itemtype>::Helper(const itemtype& Entry,int Default_Size, int capacity){
capacity=20;
int count=0;
double *vStore2;
vStore2= new itemtype[Default_Size];
delete [] vStore2;
for(int i=0;i<10;i++){
vStore2[i]=vStore[i];
count++;
}
if(count>capacity){
cout<<"Out of bounds"<<endl;
}
else
vStore2[count]=Entry;
num_used++;
return 0;
}
#endif
|