CMPS 223 Data Structures and Algorithms Assignment 1: Template, List Implementation I. Purposes: Use dynamic memory allocation, class and function templates to implment list structure with following features: 1. It is expandable: When objects are inserted into list, the list will never be full (dynamic array will provide the feature). 2. The class template will help to build lists for different types of objects. II. What you are going to do: 1. Based one the following class template declaraction, implement each of teh functions for the class template defined below. 2. Write a menu-driven program to test your list class template based on the Menu.h and MenuTest.cpp files in item III. Here is the list class template: // List Class Template Implementation based on Dynaic Array. #ifndef DTLIST_H #define DTLIST_H #include #include #include #include using namespace std; template class DTList { protected: T * element; int count, capacity; public: DTList( int cap = 10); ~DTList(); DTList( const DTList& ); bool empty() const; // Expand the memory if the list is full before // a new object is inserted. DTList& insert( const T & , int ); // Return this for cascade calls. (obj, pos) T erase( int ); void display() const; friend template ostream& operator<<( ostream&, const DTList& ); }; #endif III. Menu.h and MenuTest.cpp files: Read the following two program and used it to make a driver program for testing your DTList class. /********** Menu.h file ************************/ #include #include using namespace std; class Menu { private: char ** menu; char choice[3]; public: Menu( char ** mu ) { menu = mu; } void show() { cout << endl; for ( int i = 0; menu[i] != 0 ; i ++ ) cout << "\t\t" << menu[i] << endl; } char select() { cout << "\t\t" << "Enter a selection : "; cin.getline(choice, 5); return choice[0]; } char prompt(char * msg) { cout << "\t\t" << msg; cin.getline(choice, 5); return choice[0]; } }; // end of file Menu.h ------------------------------------------ /*********** MenuTest.cpp file *********************************/ #include #include #include #include "Menu.h" using namespace std; int main() { char * testMenu[] = { "A : Choice A", "B : Choice B", 0 }; char choice = ' '; Menu m( testMenu ); while ( true ) { choice = m.prompt("Enter a command, Q to quit, H for help: "); switch ( toupper(choice) ) { case 'H' : m.show(); break; case 'Q' : exit(0); case 'A' : case 'B' : cout << "\n\t\tUser selection : " << choice << endl; break; default: cout << "\t\tIllegal selection.\n"; } } return 0; } // End of File MenuTest.cpp -------------------------- IV. Write a menu-driven program will prompt for a user's command input and perform action based on the definitions of the commands. prompt: "Enter a command (H for help, and Q to quit) :" Menu: +=========================================+ | 1 : List Template Class Implementation | +=========================================+ | F: Create one integer and one character | | list, and insert 10 random values in | | each list. The value ranges of lists | | 0 ... 99 and 'A' .. 'Z'. | +-----------------------------------------+ | S: Show two lists. | +-----------------------------------------+ | A: Ask for a int and a char value, | | insert the values at random poistions| | of the lists. | +-----------------------------------------+ | D: Generate a random position, and | | remove values at the positions of the| | int and char lists. | +-----------------------------------------+ | H: Show this menu. | +-----------------------------------------+ | Q: Exit program. | +-----------------------------------------+ V. How to hand your assignment 1. Name your CPP file which contains the main() as FLll01.cpp where 'F' is your first initial, and 'Lll' are the first 3 letters of your last name. Put your class declaration and definition into two different files with names based on the class defined inthe file (ex. DArray.h and DArray.cpp) except the cases where the class implementations are simple. 2. Zip all source (.cpp, .h and data) file into one zip file. The name zip file based on your name and assignment number. For example, John Doe first asignment can be name as JDoe01.zip by the following command: zip JDoe01.zip *.cpp *.h *.dat 3. Send your zip file as attachment with pine on helios to wang.cs.csubak.edu. 4. Add your name, class number and assignment number as the attachment comment. For example: "John Doe, CS 223, Assignment 1" You have to learn how to add attachment comment in pine ! V. How to hand your assignment 1. Name your CPP file which contains the main() as FLll01.cpp where 'F' is your first initial, and 'Lll' are the first 3 letters of your last name. Put your class declaration and definition into two different files with names based on the class defined inthe file (ex. DArray.h and DArray.cpp) except the cases where the class implementations are simple. 2. Zip all source (.cpp, .h and data) file into one zip file. The name zip file based on your name and assignment number. For example, John Doe first asignment can be name as JDoe01.zip by the following command: zip JDoe01.zip *.cpp *.h *.dat 3. Send your zip file as attachment with pine on helios to wang.cs.csubak.edu. 4. Add your name, class number and assignment number as the attachment comment. For example: "John Doe, CS 223, Assignment 1" You have to learn how to add attachment comment in pine !