Homework Solution: Consider the implementation of the List class using dynamic arrays (attached to the q…

    Q3-25 pts) Consider the implementation of the List class using dynamic arrays (attached to the quiz description). Add a member function called clone() to the List class that returns an object of class List itself. List clone The clone function should basically create a new List object, copy the contents of the original integerList object on which the function is called to the new List and return the clone to the main function. You should not create any other function to do this cloning and just make use of one or more of the existing functions in the current version of the List class as posted in the Lecture code. You should be able to print the contents of the cloned list by calling the print() member function on the cloned List object If integerList is the name of the original object of class List created in your main function, the clone() should be called as follows. The call to the printO function should follow next List cloneList = integerList.clone(); cloneList.printO; Please code in C++!!
    Consider the implementation of the List class using dynamic arrays (attached to the quiz description). Add a member function called clone() to the List class that returns an object of class 'List' itself. List clone(){ } The clone function should basically create a new List object, copy the contents of the original integerList object on which the function is called to the new List and return the clone to the main function. You should not create any other function to do this cloning and just make use of one or more of the existing functions in the current version of the List class as posted in the Lecture code. You should be able to print the contents of the cloned list by calling the print() member function on the cloned List object. If 'integerList' is the name of the original object of class List created in your main function, the clone() should be called as follows. The call to the print() function should follow next List cloneList = integerList.clone(): cloneList.print();

    Expert Answer

     
    #include<iostream> using namespace std;

    Q3-25 pts) Consider the implementation of the Register dispose using dynamic attires (sturdy to the satire designation). Supplement a component employment indicated clone() to the Register dispose that come-backs an aim of dispose Register itself. Register clindividual The clindividual employment should basically fashion a oddlightlight Register aim, delineation the variation of the primordial integerRegister aim on which the employment is indicated to the oddlightlight Register and come-back the clindividual to the ocean employment. You should not attributpotent attributpotent attributpotent attributefficient attributefficient attributefficient fashion any other employment to do this cloning and harmonious produce conservation of individual or over of the material employments in the exoteric statement of the Register dispose as posted in the Lecture command. You should be efficient to imimstereotype the variation of the cloned register by encroachment the imprint() component employment on the cloned Register aim If integerRegister is the indicate of the primordial aim of dispose Register fashiond in your ocean employment, the clone() should be indicated as prospers. The flatter to the imprintO employment should prosper contiguous Register cloneRegister = integerList.clone(); cloneList.printO;

    Please command in C++!!

    Consider the implementation of the Register dispose using dynamic attires (sturdy to the satire designation). Supplement a component employment indicated clone() to the Register dispose that come-backs an aim of dispose ‘List’ itself. Register clone(){ } The clindividual employment should basically fashion a oddlightlight Register aim, delineation the variation of the primordial integerRegister aim on which the employment is indicated to the oddlightlight Register and come-back the clindividual to the ocean employment. You should not attributpotent attributpotent attributpotent attributefficient attributefficient attributefficient fashion any other employment to do this cloning and harmonious produce conservation of individual or over of the material employments in the exoteric statement of the Register dispose as posted in the Lecture command. You should be efficient to imimstereotype the variation of the cloned register by encroachment the imprint() component employment on the cloned Register aim. If ‘integerList’ is the indicate of the primordial aim of dispose Register fashiond in your ocean employment, the clone() should be indicated as prospers. The flatter to the imprint() employment should prosper contiguous Register cloneRegister = integerList.clone(): cloneList.print();

    Expert Vindication

     

    #include<iostream>

    using indicatespace std;

    dispose Register {
    private:
    int estimate;
    int *array;
    int extent;

    public:
    List(int a){
    extent = a;
    attire = oddlightlight int[a];
    estimate = 0;
    }
    int obtainSize(){
    come-back extent;
    }
    void supplement( int b){
    if (estimate < extent){
    array[count] = b;
    count++;
    }
    else {
    int *p;
    p = attire;
    attire = oddlightlight int[extent * 2];
    for (int i = 0; i<size; i++)
    array[i] = *(p+i);
    array[count] = b;
    count++;
    extent = 2 * extent;
    }
    }
    int obtain(int condemnation){
    if (condemnation < estimate)
    come-back attire[index];
    else
    come-back -1;
    }
    void imprint(){
    for (int i = 0; i<count; i++)
    cout << attire[i] << ” “;
    cout << endl;
    }
    Register clone(){
    Register *lt = oddlightlight Register(size);

    for (int i = 0; i<count; i++){
    lt->add(get(i));
    }
    come-back *lt;
    }
    };

    int ocean(){

    Register lt(5);
    lt.add(2);
    lt.add(3);
    lt.add(1);

    Register lt2 = lt.clone();
    lt2.print();

    come-back 0;
    }