Instructor: Computer Science 343 Due: 5:00 P.M. D. J. Taylor Assignment 1 A programming language normally requires that the length of a vector be specified either at compile time or at the time the vector is created. This assignment asks you to use the facilities of C++ to create a vector type whose length can be changed arbitrarily after the vector has been created. In fact, you are to implement a vector that appears to contain an infinite number of entries, but with only finitely many having non-default values. You are to implement a class, FlexVec, that will create a vector of integers which behaves in this way. Both subscripts and the values of vector elements must be integers. The restriction to integers as vector elements is unreasonable, but helps to keep the assignment simple. Your class needs to contain four methods: a constructor, a destructor, a ``[]'' (subscripting) operator, and a ``status'' method. The constructor and the destructor perform their normal functions; a newly allocated vector should appear to contain a zero entry for all subscript values. The subscripting operator behaves as it would for a standard vector, as far as a user of the class is concerned. The ``status'' method is used to obtain some internal information that would not normally be of interest, but will help to demonstrate that your class is behaving properly. This method has three parameters, all of type reference to integer. The first is used to return the number of non-zero entries in the vector, the second to return the minimum subscript value corresponding to a non-zero entry, and the third to return the maximum subscript value corresponding to a non-zero entry. Use a simple but inefficient implementation for your class, in which you keep a linked list, sorted in subscript order, of all the non-zero elements of the vector. You may use library functions for lists in your implementation if you wish. To test your class, write a main program that provides the following facilities to a terminal user. Three instances of the class are created, at the beginning of program execution and are destroyed implicitly when your program terminates. Make sure that your program terminates ``properly'' so that the destructor for your class is actually executed (and, hence, tested). The program has no command-line parameters and accepts the following commands. = ? s * In each of these commands, is 0, 1, or 2 and specifies which of the three vectors is to be used. The first command stores the specified integer at the specified subscript position (and prints no output). The second fetches the value associated with the specified subscript and prints it out. The third prints the three pieces of status information returned by the ``status'' method. In each of the preceding commands, the two, three, or four components are separated by one or more spaces but there may not be any spaces preceding the first component of the command. The last ``command'' is a comment; if the first character of an input line is an asterisk, simply discard the rest of the line. (Such comments can be quite useful in a file of commands used for testing.) End of input is indicated by end-of-file rather than a special command. Perform reasonable error checking on the input commands, e.g., check for a first character that isn't one of the four specified, check for missing arguments, and so on. Testing Test your program using test cases of your own devising, that exercise the facilities of the FlexVec class, as well as testing the user interface. We will execute your submitted program using our own test files, but you must submit your own testing and provide appropriate documentation for it. Hints This should be a fairly short program. If you find yourself writing a long program or one containing many procedures, stop and think about what you're doing.