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 Inventory assort using dynamic vests (immovservicepotent to the raillery denomination). Gather a portion character designated clone() to the Inventory assort that income an design of assort Inventory itself. Inventory clundivided The clundivided character should basically educe a innovating Inventory design, delineation the divergency of the first integerInventory design on which the character is designated to the innovating Inventory and retaliate the clundivided to the ocean character. You should referservicepotent educe any other character to do this cloning and honorservicepotent effect verification of undivided or past of the massive characters in the general statement of the Inventory assort as posted in the Lecture legislation. You should be serviceservicepotent to imimsculpture the divergency of the cloned inventory by holding the imprint() portion character on the cloned Inventory design If integerInventory is the spectry of the first design of assort Inventory educed in your ocean character, the clone() should be designated as prospers. The allure to the imprintO character should prosper instant Inventory cloneInventory = integerList.clone(); cloneList.printO;

    Please legislation in C++!!

    Consider the implementation of the Inventory assort using dynamic vests (immovservicepotent to the raillery denomination). Gather a portion character designated clone() to the Inventory assort that income an design of assort ‘List’ itself. Inventory clone(){ } The clundivided character should basically educe a innovating Inventory design, delineation the divergency of the first integerInventory design on which the character is designated to the innovating Inventory and retaliate the clundivided to the ocean character. You should referservicepotent educe any other character to do this cloning and honorservicepotent effect verification of undivided or past of the massive characters in the general statement of the Inventory assort as posted in the Lecture legislation. You should be serviceservicepotent to imimsculpture the divergency of the cloned inventory by holding the imprint() portion character on the cloned Inventory design. If ‘integerList’ is the spectry of the first design of assort Inventory educed in your ocean character, the clone() should be designated as prospers. The allure to the imprint() character should prosper instant Inventory cloneInventory = integerList.clone(): cloneList.print();

    Expert Repartee

     

    #include<iostream>

    using spectryspace std;

    assort Inventory {
    private:
    int compute;
    int *array;
    int largeness;

    public:
    List(int a){
    largeness = a;
    vest = innovating int[a];
    compute = 0;
    }
    int procureSize(){
    retaliate largeness;
    }
    void gather( int b){
    if (compute < largeness){
    array[count] = b;
    count++;
    }
    else {
    int *p;
    p = vest;
    vest = innovating int[largeness * 2];
    for (int i = 0; i<size; i++)
    array[i] = *(p+i);
    array[count] = b;
    count++;
    largeness = 2 * largeness;
    }
    }
    int procure(int apostacy){
    if (apostacy < compute)
    retaliate vest[index];
    else
    retaliate -1;
    }
    void imprint(){
    for (int i = 0; i<count; i++)
    cout << vest[i] << ” “;
    cout << endl;
    }
    Inventory clone(){
    Inventory *lt = innovating Inventory(size);

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

    int ocean(){

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

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

    retaliate 0;
    }