I am really confused here because i have posted 2x and got a

I am really confused here because i have posted 2x and got answers that where not accurate. I know that i need two .h files and the one included file. But no one has really showed me or broken it down in a way that i can understand. so i am asking for help i know that the cpp can not be changed in anyway and I have looked but can not find a way to do anything with the .h files with out changing it so if you are advanced in C++ i could really use your help on this one. THank you in advance.

Do not change anything in the supplied Ch16_Ex5_MainProgram.cpp except to add documentation and your name.

Please use the file names listed below since your file will have the following components:

Ch16_Ex5_MainProgram.cpp - given file


//22 34 56 4 19 2 89 90 0 14 32 88 125 56 11 43 55 -999

#include <iostream>
#include \"unorderedLinkedList.h\"

using namespace std;

int main()
{
unorderedLinkedList<int> list, subList;

int num;                                                                                                                       

            cout << \"Enter numbers ending with -999\" << endl;                                                                                                                     
cin >> num;                                                                                                     

            while (num != -999)                                                                                          
{
list.insertLast(num);                                                                  
cin >> num;                                                                                                     
}

            cout << endl;                                                                                                   

            cout << \"List: \";                                                
list.print();                                                                                                        
cout << endl;                                                                                                               
cout << \"Length of the list: \" << list.length() << endl;                                                                                                      

            list.divideMid(subList);

            cout << \"Lists after splitting list\" << endl;

            cout << \"list: \";
list.print();                                                                                                        
cout << endl;                                                                                                               
cout << \"Length of the list: \" << list.length() << endl;                  

            cout << \"sublist: \";
subList.print();                                                                                                  
cout << endl;                                                                                                               
cout << \"Length of subList: \" << subList.length() << endl;
system(\"pause\");
return 0;                                                          
}

linkedList.h
unorderedLinkedList.h

Dividing a linked list into two sublists of almost equal sizes:

Add the operation divideMid to the class linkedListType as follows:

void divideMid(linkedListType &sublist);
//This operation divides the given list into two sublists
//of (almost) equal sizes.
//Postcondition: first points to the first node and last
//          points to the last node of the first
//          sublist.
//          sublist.first points to the first node
//          and sublist.last points to the last node
//          of the second sublist.
Consider the following statements:

unorderedLinkedList <int> myList;
unorderedLinkedList <int> subList;

Suppose myList points to the list with elements 34 65 27 89 12 (in this order). The statement:

myList.divideMid(subList);

divides myList into two sublists: myList points to the list with the elements 34 65 27, and subList points to the sublist with the elements 89 12.

Write the definition of the function template to implement the operation divideMid. Also, write a program to test your function.

Solution

Dear Asker,

It seems like you are looking the right place/file to put the code for divideMid() into, since Ch16_Ex5_MainProgram.cpp and unorderedLinkedList.h files can not be modified. You need to put definition of of divideMid() function in \'unorderedLinkedList.cpp\' (assuming \'unorderedLinkedList.h\' has the corresponding declation i.e. typically implementation goes into \'xyz.cpp\' if declaration is in \'xyz.h\'), create it if it doesn\'t exist already. I can\'t provide any implementation of divideMid() unless I see code of those two header files.

Please remember following points:

1. Make sure to include  \'unorderedLinkedList.h\' in  \'unorderedLinkedList.cpp\'.

2. When you compile, compile both cpp files, e.g. with g++ do this

g++ -o  unorderedLinkedList.cpp Ch16_Ex5_MainProgram.cpp

Hope this helps.

I am really confused here because i have posted 2x and got answers that where not accurate. I know that i need two .h files and the one included file. But no on
I am really confused here because i have posted 2x and got answers that where not accurate. I know that i need two .h files and the one included file. But no on

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site