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

Download the file linkedList.zip and modify the driver.cpp file by implementing

ID: 3537450 • Letter: D

Question

Download the file linkedList.zip and modify the driver.cpp file by implementing the helper function called listComplement() . The function will take the intersection of the list1 and list2 parameters and will place the results in a third parameter called results . The prototype for this function is as follows:


template

void listComplement(linkedListType& results,                              

                    linkedListType& list1,                              

                    linkedListType& list2);  

Hint: You only need to modify the areas of the code in the driver.cpp file that are marked with the TODO comments. Everything else should remain that same. You can implement this function anyway you like, but you must use the provided lists and function prototype. The printList() function provides an example on how to use a for-loop with an iterator for a passed in list parameter.

Output: The output for the program after the function is implemented should appear as follows:


List 1:   

21 41 86 34 71 89 11 44 76 77

List 2:   

76 41 8 64 21 89 31 24 71 86

The complement of List 1 with List 2 is:   

  34 11 44 77  

** Press any key to continue **

=======================================================

Files are located here: https://www.dropbox.com/sh/e8oz4rnq1rqq232/lqkBPKgH-3

Please provide "driver.ccp" file in a clean C++ source code format.   #include "stdafx.h" must be added at the top of the .ccp file.

DropBox is preferred.

Do not make any changes to linkedList.h!

Explanation / Answer

/**

* Driver.cpp - This file contains the driver code to test the

* linkedListType class implementation

*

* TODO: include your name and course number here.

*/

/* added stdafx..please add your name and course */


#include "stdafx.h"

#include <iostream>

#include <stdio.h>


#include "linkedList.h"


using namespace std;


template <class Type>

void printList(linkedListType<Type>& list);


template <class Type>

void listComplement(linkedListType<Type>& results,

linkedListType<Type>& list1,

linkedListType<Type>& list2);


int main(int argc, char **argv)

{

// Declare list variables

linkedListType<int> list1;

linkedListType<int> list2;

linkedListType<int> results;


// Add some data to list 1

list1.insertLast(21);

list1.insertLast(41);

list1.insertLast(86);

list1.insertLast(34);

list1.insertLast(71);

list1.insertLast(89);

list1.insertLast(11);

list1.insertLast(44);

list1.insertLast(76);

list1.insertLast(77);


// Add some data to list 2

list2.insertLast(76);

list2.insertLast(41);

list2.insertLast(8);

list2.insertLast(64);

list2.insertLast(21);

list2.insertLast(89);

list2.insertLast(31);

list2.insertLast(24);

list2.insertLast(71);

list2.insertLast(86);


// Print out the lists

cout << " List 1: ";

printList(list1);


cout << " List 2: ";

printList(list2);


listComplement(results, list1, list2);


cout << " The complement of List 1 with List 2 is: ";

printList(results);


cout << " ** Press any key to continue ** ";

getchar();


return 0;

}


template <class Type>

void printList(linkedListType<Type>& list)

{

for (linkedListIterator<Type> itr = list.begin(); itr != list.end(); ++itr)

{

cout << *itr << " ";

}


return;

}


template <class Type>

void listComplement(linkedListType<Type>& results,

linkedListType<Type>& list1,

linkedListType<Type>& list2)

{

// TODO: Provide the implementation details for this function here. You may

  // find the search() method in the linkedListType class useful.

//DONE

for (linkedListIterator<Type> itr = list1.begin(); itr != list1.end(); ++itr)

{

   //search for item in other list

if(list2.search(*itr))

{

//if found it is part of intersection list

results.insertLast(*itr);

}

}

return;

}

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