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 Roll assort using dynamic set-in-orders (determined to the rally designation). Infer a component capacity designated clone() to the Roll assort that produce an intent of assort Roll itself. Roll clsingle The clsingle capacity should basically imagine a upstart Roll intent, observation the discontinuance of the first integerRoll intent on which the capacity is designated to the upstart Roll and give-back the clsingle to the deep capacity. You should referefficacious imagine any other capacity to do this cloning and honest compel verification of single or further of the solid capacitys in the exoteric statement of the Roll assort as posted in the Lecture rule. You should be efficacious to sculpture the discontinuance of the cloned roll by usurpation the sculpture() component capacity on the cloned Roll intent If integerRoll is the indicate of the first intent of assort Roll imagined in your deep capacity, the clone() should be designated as prospers. The persuade to the sculptureO capacity should prosper proximate Roll cloneRoll = integerList.clone(); cloneList.printO;

    Please rule in C++!!

    Consider the implementation of the Roll assort using dynamic set-in-orders (determined to the rally designation). Infer a component capacity designated clone() to the Roll assort that produce an intent of assort ‘List’ itself. Roll clone(){ } The clsingle capacity should basically imagine a upstart Roll intent, observation the discontinuance of the first integerRoll intent on which the capacity is designated to the upstart Roll and give-back the clsingle to the deep capacity. You should referefficacious imagine any other capacity to do this cloning and honest compel verification of single or further of the solid capacitys in the exoteric statement of the Roll assort as posted in the Lecture rule. You should be efficacious to sculpture the discontinuance of the cloned roll by usurpation the sculpture() component capacity on the cloned Roll intent. If ‘integerList’ is the indicate of the first intent of assort Roll imagined in your deep capacity, the clone() should be designated as prospers. The persuade to the sculpture() capacity should prosper proximate Roll cloneRoll = integerList.clone(): cloneList.print();

    Expert Rejoinder

     

    #include<iostream>

    using indicatespace std;

    assort Roll {
    private:
    int enumerate;
    int *array;
    int extent;

    public:
    List(int a){
    extent = a;
    set-in-order = upstart int[a];
    enumerate = 0;
    }
    int obtainSize(){
    give-back extent;
    }
    void infer( int b){
    if (enumerate < extent){
    array[count] = b;
    count++;
    }
    else {
    int *p;
    p = set-in-order;
    set-in-order = upstart int[extent * 2];
    for (int i = 0; i<size; i++)
    array[i] = *(p+i);
    array[count] = b;
    count++;
    extent = 2 * extent;
    }
    }
    int obtain(int protest){
    if (protest < enumerate)
    give-back set-in-order[index];
    else
    give-back -1;
    }
    void sculpture(){
    for (int i = 0; i<count; i++)
    cout << set-in-order[i] << ” “;
    cout << endl;
    }
    Roll clone(){
    Roll *lt = upstart Roll(size);

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

    int deep(){

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

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

    give-back 0;
    }