Complex Vector

  Use a simple agent you created afore to actualize two alternative added circuitous vectors with    A) Anamnesis allocation that doubles admeasurement of anamnesis aback end reached, and 1/2's anamnesis aback the admeasurement alcove 1/4.    B) Implemented with a abnormally affiliated list. Main.cpp #include <cstdlib> #include "SimpleVector.h" //System Libraries #include <iostream> //Input/Output Library application namespace std; //User Libraries //Global Constants, no Global Variables are allowed //Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc... //Function Prototypes abandoned fillVec(SimpleVector<int> &); abandoned addVec(SimpleVector<int> &); abandoned delVec(SimpleVector<int> &); abandoned prntVec(SimpleVector<int> &,int); //Execution Begins Here! int main(int argc, char** argv) {     //Declare Variables     int size;     //Read in the size     cout<<"What admeasurement agent to test?"<<endl;     cin>>size;     SimpleVector<int> sv(size);     //Initialize or ascribe i.e. set capricious values     fillVec(sv);     //Display the outputs     prntVec(sv,10);     //Add and decrease from the vector     addVec(sv);     //Display the outputs     prntVec(sv,10);     //Add and decrease from the vector     delVec(sv);     //Display the outputs     prntVec(sv,10);     //Exit date appropriate or left!     acknowledgment 0; } abandoned 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);     } } abandoned delVec(SimpleVector<int> &sv){     int del=sv.size()*0.2;     for(int i=1;i<=del;i++){         sv.pop_front();         sv.pop_back();     } } abandoned fillVec(SimpleVector<int> &sv){     for(int i=0;i<sv.size();i++){         sv[i]=i%10;     } } abandoned 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 chic template #ifndef SIMPLEVECTOR_H #define SIMPLEVECTOR_H #include <iostream> #include <new>       // Needed for bad_alloc exception #include <cstdlib>   // Needed for the avenue function application namespace std; template <class T> chic SimpleVector { private:    T *aptr;          // To point to the allocated array    int arraySize;    // Number of elements in the array    abandoned memError(); // Handles anamnesis allocation errors    abandoned subError(); // Handles subscripts out of range public:    // Default constructor    SimpleVector()       { aptr = 0; arraySize = 0;}    // Architect declaration    SimpleVector(int);    // Copy architect declaration    SimpleVector(const SimpleVector &);    // Destructor declaration    ~SimpleVector();    //Adding and adding from the Vector    abandoned push_front(T);    abandoned push_back(T);    T    pop_front();    T    pop_back();    // Accessor to acknowledgment the arrangement size    int size() const       { acknowledgment arraySize; }    // Accessor to acknowledgment a specific element    T getElementAt(int position);    // Overloaded [] abettor declaration    T &operator[](const int &); }; // Architect for SimpleVector class. Sets the admeasurement of the * // arrangement and allocates anamnesis for it.                       * arrangement <class T> SimpleVector<T>::SimpleVector(int s) {    arraySize = s;    // Admeasure anamnesis for the array.    try    {       aptr = new T [s];    }    bolt (bad_alloc)    {       memError();    }    // Initialize the array.    for (int calculation = 0; calculation < arraySize; count++)       *(aptr + count) = 0; } // Copy Architect for SimpleVector class. * arrangement <class T> SimpleVector<T>::SimpleVector(const SimpleVector &obj) {    // Copy the arrangement size.    arraySize = obj.arraySize;      // Admeasure anamnesis for the array.    aptr = new T [arraySize];    if (aptr == 0)       memError();      // Copy the elements of obj's array.    for(int calculation = 0; calculation < arraySize; count++)       *(aptr + count) = *(obj.aptr + count); } // Add 1 or Annul 1 advanced or aback for SimpleVector class. * template<class T> abandoned SimpleVector<T>::push_front(T val){     // Admeasure anamnesis for the array.     T *newarr = 0;     try     {         newarr = new T [arraySize + 1];     }     bolt (bad_alloc)     {         memError();     }     *(newarr) = val;//Add amount to the advanced of the new array     // Copy antecedent arrangement contents.     arraySize++;//Increment arrangement size     for (int calculation = 1; calculation < arraySize; count++)         *(newarr + count) = *(aptr + calculation - 1);     annul aptr;//Delete antecedent array     aptr = newarr; } template<class T> abandoned SimpleVector<T>::push_back(T val){     // Admeasure anamnesis for the array.     T *newarr = 0;     try     {         newarr = new T [arraySize + 1];     }     bolt (bad_alloc)     {         memError();     }     // Copy antecedent arrangement contents.     for (int calculation = 0; calculation < arraySize; count++)         *(newarr + count) = *(aptr + count);     *(newarr + arraySize) = val;//Add amount at aback of the array     arraySize++;//Increment arrangement size     annul aptr;//Delete antecedent array     aptr = newarr; } template<class T> T SimpleVector<T>::pop_front(){     T copy = 0;     if(arraySize != 0)//If arrangement is not abandoned again alone pop     {         copy = *aptr;         if(arraySize == 1){             annul aptr;             aptr = 0;         }         abroad {             // Admeasure anamnesis for the array.             T *newarr = 0;             try {                 newarr = new T[arraySize - 1];             }             bolt (bad_alloc) {                 memError();             }             // Copy antecedent arrangement contents.             for (int calculation = 1; calculation < arraySize; count++)                 *(newarr + calculation - 1) = *(aptr + count);             annul aptr;//Delete antecedent array             aptr = newarr;         }         arraySize--;//Decrease arrangement size     }     acknowledgment dummy;//Return popped value } template<class T> T SimpleVector<T>::pop_back(){     T copy = 0;     if(arraySize != 0)//If arrangement is not abandoned again alone pop     {         copy = *(aptr + arraySize - 1);         if(arraySize == 1){             annul aptr;             aptr = 0;         }         abroad {             // Admeasure anamnesis for the array.             T *newarr = 0;             try {                 newarr = new T[arraySize - 1];             }             bolt (bad_alloc) {                 memError();             }             // Copy antecedent arrangement contents.             for (int calculation = 0; calculation < arraySize - 1; count++)                 *(newarr + count) = *(aptr + count);             annul aptr;//Delete antecedent array             aptr = newarr;         }         arraySize--;//Decrease arrangement size     }     acknowledgment dummy;//Return popped value } //************************************** // Destructor for SimpleVector class. * //************************************** arrangement <class T> SimpleVector<T>::~SimpleVector() {    if (arraySize > 0)       annul [] aptr; } // memError function. Displays an absurdity bulletin and // terminates the affairs aback anamnesis allocation fails. arrangement <class T> abandoned SimpleVector<T>::memError() {    cout << "ERROR:Cannot admeasure memory.\n";    exit(EXIT_FAILURE); } // subError function. Displays an absurdity bulletin and         * // terminates the affairs aback a subscript is out of range. * arrangement <class T> abandoned SimpleVector<T>::subError() {    cout << "ERROR: Subscript out of range.\n";    exit(EXIT_FAILURE); } // getElementAt function. The altercation is a subscript. * // This action allotment the amount stored at the sub-   * // cript in the array.                                  * arrangement <class T> T SimpleVector<T>::getElementAt(int sub) {    if (sub < 0 || sub >= arraySize)       subError();    acknowledgment aptr[sub]; } // Overloaded [] operator. The altercation is a subscript. * // This action allotment a advertence to the element     * // in the arrangement indexed by the subscript.               * arrangement <class T> T &SimpleVector<T>::operator[](const int &sub) {    if (sub < 0 || sub >= arraySize)       subError();    acknowledgment aptr[sub]; } #endif

Order a unique copy of this paper

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
Top Academic Writers Ready to Help
with Your Research Proposal
Live Chat+1(978) 822-0999EmailWhatsApp

Order your essay today and save 20% with the discount code COURSEGUY