Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use C++ 1. Implement the UnsortedList class to store a list of strings that are

ID: 3797788 • Letter: U

Question

Use C++

1. Implement the UnsortedList class to store a list of strings that are input into the list from data2.txt below.

- create a main.cpp file that gets the numbers from the file

- insert the word "cat" into the list

- insert another word "antibacterial" into the list

- delete the word "letter" from the list

- print out the following:

   --the entire list

   - the greatest

   - the least

2. There should be four files, the main.cpp, UnsortedList.cpp, ItemType.h, and the output file one called outfile1.txt

Contents of “data2.txt”

super formula    travel     free thick Josephine Clara education

Explanation / Answer

#include <iostream>

#include <algorithm>

using namespace std;

int binarySearch(int arr[], int l, int r, int x);

void printUnion(int arr1[], int arr2[], int m, int n)

{

    if (m > n)

    {

        int *tempp = arr1;

        arr1 = arr2;

        arr2 = tempp;

        int temp = m;

        m = n;

        n = temp;

    }

    sort(arr1, arr1 + m);

    for (int i=0; i<m; i++)

        cout << arr1[i] << " ";

    for (int i=0; i<n; i++)

        if (binarySearch(arr1, 0, m-1, arr2[i]) == -1)

            cout << arr2[i] << " ";

}

void printIntersection(int arr1[], int arr2[], int m, int n)

{

    if (m > n)

    {

        int *tempp = arr1;

        arr1 = arr2;

        arr2 = tempp;

        int temp = m;

        m = n;

        n = temp;

    }

    sort(arr1, arr1 + m);

    for (int i=0; i<n; i++)

        if (binarySearch(arr1, 0, m-1, arr2[i]) != -1)

            cout << arr2[i] << " ";

}

int binarySearch(int arr[], int l, int r, int x)

{

    if (r >= l)

    {

        int mid = l + (r - l)/2;

        if (arr[mid] == x) return mid;

        if (arr[mid] > x) return binarySearch(arr, l, mid-1, x);

        return binarySearch(arr, mid+1, r, x);

    }

    return -1;

}

int main()

{

    int arr1[] = {7, 1, 5, 2, 3, 6};

    int arr2[] = {3, 8, 6, 20, 7};

    int m = sizeof(arr1)/sizeof(arr1[0]);

    int n = sizeof(arr2)/sizeof(arr2[0]);

    cout << "Union of two arrays is ";

    printUnion(arr1, arr2, m, n);

    cout << " Intersection of two arrays is ";

    printIntersection(arr1, arr2, m, n);

    return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote