Educational Objectives: After completing this assignment the student should have the following knowledge, ability, and skills:
Operational Objectives: Implement and test the function templates InsertionSort and Display. Build applications and test programs from previous projects.
Deliverables: Files:
tsort.h # contains function templates cstringcomp.h # from project 1 - will be re-tested cstringcomp.cpp # from project 1 - will be re-tested id.h # from project 2, with input operator and less-than operator added id.cpp # implements id.h log.txt # as usual: work log and testing diary
(We supply a makefile for this project.)
builds: [0..5]: x test1: [intsort] [0..5]: x test2: [stringsort] [0..5]: x test3: [charsort] [0..5]: x test4: [idsort] [0..10]: xx test5: [fcstringcomp] [0..5]: x test6: [fcstringcomp] [0..5]: x log.txt [answered questions] [0..10]: xx log.txt [including test diary] [-20..0]: ( x) project specs [-20..0]: ( x) code quality [-20..0]: ( x) dated submission deduction [2 pts per]: ( x) --- total [0..50]: xx Notes: 1. input files may vary over time 2. answers to questions should be near top of log Code quality includes: - conformance to assignment requirements and specifications - conformance to coding standards [see course organizer] - engineering and design, including appropriateness of name choices - readability
Background: See lecture notes Chapter 12. Templates.
Copy all files from LIB/proj6/. You should see at least these:
charsort.cpp # sorts files of characters idsort.cpp # sorts files of ID tokens intsort.cpp # sorts files of integers stringsort.cpp # sorts files of strings makefile # builds all required components of project deliverables.sh # submission configuration file
Begin your log file named log.txt. (See Assignments for details.)
Read and understand the supplied makefile. Pay careful attention to the targets and dependency relationships.
Read and understand the supplied client sort programs charsort.cpp, intsort.cpp, stringsort.cpp, and idsort.cpp. Pay careful attention to the similarities among these files.
Create the file tsort.h containing the function templates Display and InsertionSort, as detailed in the requirements section.
Test your templates by building and running charsort.x, intsort.x, and stringsort.x using the supplied makefile. (Command make intsort.x builds intsort.x.) Note: "make" also attempts to build idsort.x, which won't work until you have completed steps 7 and 8. So you need to make the 3 specific targets at this point.
Copy your files proj1/cstringcomp.h and proj1/cstringcomp.cpp to proj6/. If these need revision based on feedback from proj1, do that now.
Copy your files proj2/id.h and proj2/id.cpp into your proj6 directory. Modify these files by adding operator>> and operator<, as detailed below (and, of course, updating the file header doc).
Test your project thoroughly. Be sure to keep records and report the results in your test diary (part of log.txt).
Answer the questions at the end of this document. Place the questions, each followed by your answer, near the top of your log.txt (before the chronology and test diary).
General Identical Behavior Requirement. Except where specifically noted otherwise, behavior of executables must be identical to those of the area51 benchmark executables.
Turn in all deliverables using the submit script system. (Read here for reminders how the submit system works.)
Warning: Submit scripts do not work on the program and linprog servers. Use shell.cs.fsu.edu or quake.cs.fsu.edu to submit projects. If you do not receive two confirmations, the second with the contents of your project, there has been a malfunction.
In file tsort.h define and implement function templates with these prototypes:
template < typename T > void Display (const T* beg, const T* end, char ofc = '\0'); template < typename T > void InsertionSort (T* beg, T* end);
Both function templates use pointers to an unknown type T to define a range of values that is assumed, as usual, to be "half open", that is, include the beginning element and exclude the ending element. We use the notation [beg,end) to denote the range.
Display writes the data in the range [beg,end) to standard output. If the output formatting character ofc is '\0' then the output data is not separated by anything. If ofc is any other character, then ofc should be output preceeding each item in the range.
InsertionSort transforms the data in the range [beg,end) into sorted order using the InsertionSort algorithm. This is the same algorithm discussed in the Project 1 document and implemented in your file proj1/cstringsort.cpp.
The software will only work on types for which there is an input operator overload (to fill up an array using std::cin >> ...) and a less-than operator overload (so that the sort algorithm can compare two elements).
Overload these operators for class ID using the following prototypes:
std::istream& operator>> ( std::istream& is , ID& id ); bool operator< ( const ID& id1 , const ID& id2 );
The behavior of operator>> should be:
The behavior of < should be based on the value d = DictionaryComp( id1.GetName() , id2.GetName() ) according to these cases:
In words: first consider the name (independent of case), then use age to break ties.
Note that neither of these operators is a member operator of class ID, nor should either be a friend of the class.
Be sure that you have tested your code for syntax errors. All warnings should be eliminated.
Be sure that you have tested your code for logic errors with the supplied clients charsort.cpp, intsort.cpp and stringsort.cpp.
You should take some time to think about the results. For example, if you have a file of unsigned integers, that same file can be processed by charsort.x, intsort.x and stringsort.x, and the outputs differ. If there are an even number of entries in the file, it can also be processed by idsort.x! Make sure you can explain why and how this occurs.
Be sure that you have tested your templates for genericity by compiling and running idsort.cpp.
Be sure your code conforms to the C++ Code Standards (available also through the Course Organizer).
Be sure you understand why the parameters for all operators and functions discussed above are declared as they are.
A makefile has been supplied for this project. This does not mean it should be used with blind faith. Be sure that you understand this makefile, line-by-line (just as you should with any other supplied source code).
Answer the following questions. Submit the questions, each followed by your answer, near the beginning of your log, before the chronology and test diary.
As we experienced in Project 1, the various sorts operate on files using redirect:
intsort.x < datafile.in # sorted data should appear on screen intsort.x < datafile.in > datafile.out # sorted data should be in file datafile.out
It's up to you to creatively create your test data files.
Suppose you have a file data.9 with this content
250 16 28 562 10 15 28 400 122
Then the screen should appear as follows for the four sort executables:
intsort.x < data.9 A as entered: 250 16 28 562 10 15 28 400 122 A after sort: 10 15 16 28 28 122 250 400 562 stringsort.x < data.9 A as entered: 250 16 28 562 10 15 28 400 122 A after sort: 10 122 15 16 250 28 28 400 562 charsort.x < data.9 A as entered: 2501628562101528400122 A after sort: 0000111122222245556688 idsort.x < data.9 A as entered: 250 16 28 562 10 15 28 400 A after sort: 10 15 250 16 28 400 28 562
Be sure you understand why these results occur and why they are correct.
Suppose you have a file data.id with this content
Lacher 44 Harris 22 Lumber 44 Delta 21 Gamma 18 Braswel 50 Delta 22 Beta 20 Lumber 24 Delta 18 Leach 33 Bohning 22 delta 19 Delta 19 Beta 10 Lumbar 44 delta 21 Alpha 10
This is clearly intended to be data for idsort. But the file can be processed as a file of strings (and even as a file of char). The results are as follows:
idsort.x < data.id A as entered: Lacher 44 Harris 22 Lumber 44 Delta 21 Gamma 18 Braswel 50 Delta 22 Beta 20 Lumber 24 Delta 18 Leach 33 Bohning 22 delta 19 Delta 19 Beta 10 Lumbar 44 delta 21 Alpha 10 A after sort: Alpha 10 Beta 10 Beta 20 Bohning 22 Braswel 50 Delta 18 delta 19 Delta 19 Delta 21 delta 21 Delta 22 Gamma 18 Harris 22 Lacher 44 Leach 33 Lumbar 44 Lumber 24 Lumber 44 stringsort.x < data.id A as entered: Lacher 44 Harris 22 Lumber 44 Delta 21 Gamma 18 Braswel 50 Delta 22 Beta 20 Lumber 24 Delta 18 Leach 33 Bohning 22 delta 19 Delta 19 Beta 10 Lumbar 44 delta 21 Alpha 10 A after sort: 10 10 18 18 19 19 20 21 21 22 22 22 24 33 44 44 44 50 Alpha Beta Beta Bohning Braswel Delta Delta Delta Delta Gamma Harris Lacher Leach Lumbar Lumber Lumber delta delta charsort.x < data.id A as entered: Lacher44Harris22Lumber44Delta21Gamma18Braswel50Delta22Beta20Lumber24Delta18Leach33Bohning22delta19Delta19Beta10Lumbar44delta21Alpha10 A after sort: 000011111111222222222233444444458899ABBBBDDDDGHLLLLLaaaaaaaaaaaaaaaabbbccddeeeeeeeeeeeeeghhhhiillllllllmmmmmnnoprrrrrrrssttttttttuuuw
Be sure you understand why these results occur and why they are technically correct. In particular, note the role that type of variables plays.