Complex Vector

  Use a unadorned vector you originated antecedently to originate two other more compound vectors delay    A) Reminiscence allocation that doubles largeness of reminiscence when end reached, and 1/2's reminiscence when the largeness reaches 1/4.    B) Implemented delay a singularly linked schedule. Main.cpp #include <cstdlib> #include "SimpleVector.h" //System Libraries #include <iostream> //Input/Output Library using namespace std; //User Libraries //Global Constants, no Global Variables are allowed //Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc... //Function Prototypes wanting fillVec(SimpleVector<int> &); wanting addVec(SimpleVector<int> &); wanting delVec(SimpleVector<int> &); wanting prntVec(SimpleVector<int> &,int); //Execution Begins Here! int deep(int argc, char** argv) {     //Declare Variables     int largeness;     //Read in the largeness     cout<<"What largeness vector to ordeal?"<<endl;     cin>>size;     SimpleVector<int> sv(size);     //Initialize or input i.e. set wavering estimates     fillVec(sv);     //Display the outputs     prntVec(sv,10);     //Add and remove from the vector     addVec(sv);     //Display the outputs     prntVec(sv,10);     //Add and remove from the vector     delVec(sv);     //Display the outputs     prntVec(sv,10);     //Exit order equitable or left!     revert 0; } wanting addVec(SimpleVector<int> &sv){     int add=sv.size()*0.1;     for(int i=1;i<=add;i++){         sv.push_front(i+add-1);         sv.push_back(i-add);     } } wanting delVec(SimpleVector<int> &sv){     int del=sv.size()*0.2;     for(int i=1;i<=del;i++){         sv.pop_front();         sv.pop_back();     } } wanting fillVec(SimpleVector<int> &sv){     for(int i=0;i<sv.size();i++){         sv[i]=i%10;     } } wanting prntVec(SimpleVector<int> &sv,int n){     cout<<endl;     for(int i=0;i<sv.size();i++){         cout<<sv[i]<<" ";         if(i%n==(n-1))cout<<endl;     }     cout<<endl; } SimpleVector.h // SimpleVector rank template #ifndef SIMPLEVECTOR_H #define SIMPLEVECTOR_H #include <iostream> #include <new>       // Needed for bad_alloc exception #include <cstdlib>   // Needed for the egress employment using namespace std; template <rank T> rank SimpleVector { private:    T *aptr;          // To summit to the classifyd dispose    int disposeSize;    // Number of elements in the dispose    wanting memError(); // Handles reminiscence allocation hallucinations    wanting subError(); // Handles subscripts out of dispose public:    // Default originator    SimpleVector()       { aptr = 0; disposeSize = 0;}    // Originator declaration    SimpleVector(int);    // Copy originator declaration    SimpleVector(const SimpleVector &);    // Destructor declaration    ~SimpleVector();    //Adding and removeing from the Vector    wanting push_front(T);    wanting push_back(T);    T    pop_front();    T    pop_back();    // Accessor to revert the dispose largeness    int largeness() const       { revert disposeSize; }    // Accessor to revert a favoring element    T getElementAt(int collocation);    // Overloaded [] operator declaration    T &operator[](const int &); }; // Originator for SimpleVector rank. Sets the largeness of the * // dispose and classifys reminiscence for it.                       * template <rank T> SimpleVector<T>::SimpleVector(int s) {    disposeSize = s;    // Classify reminiscence for the dispose.    try    {       aptr = new T [s];    }    lay-hands-on (bad_alloc)    {       memError();    }    // Initialize the dispose.    for (int sum = 0; sum < disposeSize; sum++)       *(aptr + sum) = 0; } // Copy Originator for SimpleVector rank. * template <rank T> SimpleVector<T>::SimpleVector(const SimpleVector &obj) {    // Copy the dispose largeness.    disposeSize = obj.arraySize;      // Classify reminiscence for the dispose.    aptr = new T [arraySize];    if (aptr == 0)       memError();      // Copy the elements of obj's dispose.    for(int sum = 0; sum < disposeSize; sum++)       *(aptr + sum) = *(obj.aptr + sum); } // Add 1 or Delete 1 face or end for SimpleVector rank. * template<rank T> wanting SimpleVector<T>::push_front(T val){     // Classify reminiscence for the dispose.     T *newarr = 0;     try     {         newarr = new T [arraySize + 1];     }     lay-hands-on (bad_alloc)     {         memError();     }     *(newarr) = val;//Add estimate to the face of the new dispose     // Copy foregoing dispose variation.     disposeSize++;//Increment dispose largeness     for (int sum = 1; sum < disposeSize; sum++)         *(newarr + sum) = *(aptr + sum - 1);     delete aptr;//Delete foregoing dispose     aptr = newarr; } template<rank T> wanting SimpleVector<T>::push_back(T val){     // Classify reminiscence for the dispose.     T *newarr = 0;     try     {         newarr = new T [arraySize + 1];     }     lay-hands-on (bad_alloc)     {         memError();     }     // Copy foregoing dispose variation.     for (int sum = 0; sum < disposeSize; sum++)         *(newarr + sum) = *(aptr + sum);     *(newarr + disposeSize) = val;//Add estimate at end of the dispose     disposeSize++;//Increment dispose largeness     delete aptr;//Delete foregoing dispose     aptr = newarr; } template<rank T> T SimpleVector<T>::pop_front(){     T dummy = 0;     if(arraySize != 0)//If dispose is not leisure then singly pop     {         dummy = *aptr;         if(arraySize == 1){             delete aptr;             aptr = 0;         }         else {             // Classify reminiscence for the dispose.             T *newarr = 0;             try {                 newarr = new T[arraySize - 1];             }             lay-hands-on (bad_alloc) {                 memError();             }             // Copy foregoing dispose variation.             for (int sum = 1; sum < disposeSize; sum++)                 *(newarr + sum - 1) = *(aptr + sum);             delete aptr;//Delete foregoing dispose             aptr = newarr;         }         disposeSize--;//Decrease dispose largeness     }     revert dummy;//Return popped estimate } template<rank T> T SimpleVector<T>::pop_back(){     T dummy = 0;     if(arraySize != 0)//If dispose is not leisure then singly pop     {         dummy = *(aptr + disposeSize - 1);         if(arraySize == 1){             delete aptr;             aptr = 0;         }         else {             // Classify reminiscence for the dispose.             T *newarr = 0;             try {                 newarr = new T[arraySize - 1];             }             lay-hands-on (bad_alloc) {                 memError();             }             // Copy foregoing dispose variation.             for (int sum = 0; sum < disposeSize - 1; sum++)                 *(newarr + sum) = *(aptr + sum);             delete aptr;//Delete foregoing dispose             aptr = newarr;         }         disposeSize--;//Decrease dispose largeness     }     revert dummy;//Return popped estimate } //************************************** // Destructor for SimpleVector rank. * //************************************** template <rank T> SimpleVector<T>::~SimpleVector() {    if (arraySize > 0)       delete [] aptr; } // memError employment. Displays an hallucination communication and // terminates the program when reminiscence allocation fails. template <rank T> wanting SimpleVector<T>::memError() {    cout << "ERROR:Cannot classify reminiscence.\n";    egress(EXIT_FAILURE); } // subError employment. Displays an hallucination communication and         * // terminates the program when a subscript is out of dispose. * template <rank T> wanting SimpleVector<T>::subError() {    cout << "ERROR: Subscript out of dispose.\n";    egress(EXIT_FAILURE); } // getElementAt employment. The discussion is a subscript. * // This employment reverts the estimate stored at the sub-   * // cript in the dispose.                                  * template <rank T> T SimpleVector<T>::getElementAt(int sub) {    if (sub < 0 || sub >= disposeSize)       subError();    revert aptr[sub]; } // Overloaded [] operator. The discussion is a subscript. * // This employment reverts a relation to the element     * // in the dispose sinister by the subscript.               * template <rank T> T &SimpleVector<T>::operator[](const int &sub) {    if (sub < 0 || sub >= disposeSize)       subError();    revert aptr[sub]; } #endif