Ex. 1 Download the following files in a new folder.
list.h
list.cpp
main.cpp
Create a project just like for the previous homework and include these three files. If you compile this on Linux, the compilation command could be:
g++ list.cpp main.cpp -o testlistwhere the executable would be "testlist".
a. Implement the function Insert_back that inserts a string as a new node at the back of the list. The function must start by creating a new node containing the string. If the list is empty, the function should assign the address of the new node to the pointer front. If the list is not empty, the function must locate the last node of the list first, then link the pointer next of this last node to the new node.
b. Implement the function Concatenate that returns a string obtained by the concatenation of the words in all the nodes of the list in order and separated by spaces. This is a list traversal function that declares an empty string in the beginning, and then uses the operator+ overloaded by the string class to concatenate to it the word field of every node in the list. The function returns this local variable of type string.
Here is the example of string manipulation shown in class that
might be useful:
string_test.cpp
b. Implement the function Access_index that returns a pointer to the node number i in the list, where the first node is at position 0. If the list has less than i+1 nodes, the function must return NULL.
This function will require a list traversal loop and a counter for the number of nodes the function has seen. The counter starts from 0 and is incremented at every iteration of the loop (every time we move to the next element of the list). The continuation condition must be a combination of the pointer traversing the list not being empty and the counter not being equal to i. The function must return the local pointer used to traverse the loop.
c. Implement the function Toupper_all that converts the first letter of every word in the list to uppercase. This is a simple list traversal function for which the operation to be done for every node is to assign to word[0] the value returned by the function toupper applied to this character.
The function toupper takes one single character as a parameter and returns the same character if it is not a letter, and an uppercase version of the character if it is a letter. This function is defined in the header <ctype.h>.
d. Implement the function Tolower_all that converts the first letter of every word in the list to lowercase. This is a simple list traversal function for which the operation to be done for every node is to assign to word[0] the value returned by the function tolower applied to this character.
The function tolower takes one single character as a parameter and returns the same character if it is not a letter, and an lowercase version of the character if it is a letter. This function is defined in the header <ctype.h>.
e. Implement the function Reverse_list that reverses the list. You will have to create a new list containing the same nodes as the list starting from front but in reverse order, then delete the old list and store the address of the first element of the new list in the pointer front.
To create a new list containing the nodes of the old ones in reverse order, you can start with a new empty list, then use a loop while the old list is not empty doing the following:
Note. You don't need to modify the main for this function. It already contains a test case for each of the new functions.
Turn in: the file list.cpp.