Need help writing C++ programming assignment. Due by 700 am (central time) 8/2/2013
|
|
|
Using the C-struct feature, design, implement and test a new (programmer-defined) data type that can be used to represent and manipulate a collection of sorted integers. Such a data type can be used, for instance, by an instructor to process test scores (assuming test scores are recorded as integral values); each instance (object) of the data type would be able to represent a group of related test scores in that case. The operations supported should include the following: |
|
|
Checking to see if the collection is empty. |
|
|
|
NOTE: A collection is empty if it doesn't contain any values. |
|
|
Finding the number of values in the collection. |
|
|
Adding a new value to the collection. |
|
|
|
NOTE: |
You should NOT simply append the new item to the end of the array and then use a sorting algorithm of some kind to sort the array. You also should NOT use any temporary arrays to perfom the insertion. |
|
|
|
TIP: |
Adopt/adapt the StoreOrdered function of Assignment 4 . |
|
|
Finding the collection's lowest/highest value. |
|
|
|
NOTE: |
The lowest/highest value is undefined if the collection is empty. |
|
|
Finding the value at a given position in the collection, with position starting at 1 (i.e., array index 0 corresponds to position 1, array index 1 corresponds to position 2, and so on). |
|
|
|
NOTE: |
A positional value is undefined if the collection is empty. |
|
|
Finding the collection's average. |
|
|
|
NOTE: |
The average is undefined if the collection is empty. |
|
|
Removing an occurrence (if exists) of a specified value from the collection. |
|
|
Finding the number of occurences of a specified value in the collection. |
|
|
Resetting the collection to an empty collection. |
|
|
Adding a given collection into another collection. |
|
|
|
NOTE: |
The given collection (addend) and the collection to be added to (benend) may be the same collection before the operation takes place (in which case the operation will result in "each of the items in the original collection is duplicated exactly once"). |
|
|
|
TIP: |
The "adding a new value to collection" function (assuming implemented correctly) should prove useful here. |
|
|
Combining two given collections into a third one (which is a new collection to be returned). |
|
|
|
TIP: |
The "adding a new value to collection" function (assuming implemented correctly) should prove useful here. |
|
|
Testing to see if two given collections are identical. |
|
|
|
NOTE: |
Two collections are identical if they contain the same number of items and the values contained in every corresponding pair of items are equal. |
|
|
|
Some Specifics |
|
|
|
You will use a fixed-sized, compile-time array (and other supporting data members) to implement the new data type that can be used to declare variables (objects) each of which can represent a collection of up to MAX_SIZE integers. For the purpose of testing, set MAX_SISE to 10; your design and implementation of the data type, however, should enable the maximum size to be easily modified, i.e., only need to change the value that MAX_SIZE is set to. |
|
|
|
Goal |
|
|
|
To gain experience designing, implementing and testing a relatively simple programmer-defined data type using C-struct (and an action-oriented/procedural approach). |
|
|
|
Supplied Files and Sample Executable |
|
|
|
|
|
|
|
|
|
Some caveats: |
|
|
|
|
It was compiled using one of CS department's Linux machines. Thus, it may not run on machines that have different Unix operating systems (including different versions of Linux). It definitely will not run on Windows. |
|
|
|
|
To use the file, you should first do the following: (1) download the posted file (Assign06SampleExe.zip) onto you local machine, (2) unzip the downloaded file to obtain a6, and (3) upload the unzipped file (a6) to the desired working directory on your Linux account. |
|
|
|
|
You will most likely get an error message such as the one shown below when attempting to run the program (by entering ./a6 while in the directory containing the file): |
|
|
|
|
bash: ./a6: Permission denied |
|
|
|
|
If this happens, it is because the access permission for the file got changed during download/upload. To fix the problem, do the following while you are in the subdirectory containing the uploaded file (a6): |
|
|
|
|
chmod +x a6 |
|
|
|
|
Let me know as soon as possible (via e-mail) if you face any difficulties using the file, or if you discover some errors in my program. |
|
|
|
Your Tasks |
|
|
|
|
Thoroughly study and make sure that you fully understand the supplied header file SortedInt.h and the supplied test driver file assign06.cpp – you shouldn't have to make any changes to these files but you have to understand what's in them. |
|
|
|
NOTE: |
Your understanding (or lack thereof) of what's provided may affect your ability to answer some questions in exams. |
|
|
Implement all the functions whose specifications appear in the header file. For uniformity, start with the supplied (skeleton) implementation file SortedInt.cpp, where the invariant for the data type has already been written. |
|
|
Compile a test program using SortedInt.h, SortedInt.cpp and assign06.cpp, and run the program using appropriate test cases. |
|
|
|
An appropriate Makefile has also been provided for your convenience. If you have this Makefile in the same folder that you put the other files (SortedInt.h, SortedInt.cpp, assign06.cpp, and a6test.in): |
|
|
|
|
You can (re-)compile by simply entering make at the command line. |
|
|
|
|
And you can quickly run all the minimum required test cases (you probably want to do this only at a point where your program is at least mostly working) by simply entering make test at the command line. |
|
|
|
Deliverables |
|
|
|
|
Source files: SortedInt.h, SortedInt.cpp, assign06.cpp, and Makefile. |
|
|
Test run results: |
|
|
|
You should at least test your implementation using the cases included in this test input file . Be sure to check out this explanation page on how to use the file (and the utility of the Makefile mentioned above). |
|
|
|
NOTE: |
During grading, your program will typically be tested much more thoroughly than the minimum cases required above. |
NOTES:
|
|
Obviously, you will need to use separate compilation. |
|
|
Be sure to remove all irrelevant statements/comments in your code when submitting your work. |
|
|
|
Be sure to totally remove (not just commenting out) the |
|
|
|
|
cout << "... not implemented yet" << endl; |
|
|
|
line and remove all irrelevant comments (like // dummy value returned) once you have written the code. |
|
|
Be sure to read/follow the instructions on what/how to submit posted here . |
|
|
If you discover anything that appears incorrect, please let me know (through email) as soon as possible. |
|
|
Be sure to check back often for updates and/or further information. |
Assignment 6 Sample Test Input/Output Explanation
|
To generate/present the results for an extensive number of test cases can be quite awkward for at least 2 reasons: |
|
|
To manually generate and capture the test session can be quite tedious, time consuming, and boring. |
|
|
The output (which includes many menu listings) when printed consumes many pages (doesn't help in saving some trees, minimizing printer wear and tear, and avoiding attempts to staple pages together with undersized staplers, etc.). |
|
|
|
We can avoid the above awkwardness by taking advantage of Linux's support for input/output redirection. The following describes how I did so: |
|
|
I first created an input file that captures the input keystrokes I would enter had I run the program interactively. This resulted in a6test.in (one of the files in Assignment 6 sample test input/output ). |
|
|
I then uploaded a6test.in onto my Linux account, making sure that I placed it in the sub-directory where I had created my Assignment 6 executable (which is named a6). |
|
|
I then decided to have the corresponding output "redirected" to a file called a6test.out. |
|
|
I then issued the following command at the Linux command prompt (note that input redirection is effected through < and output redirection through >): |
|
|
|
./a6 auto < a6test.in > a6test.out |
|
|
(Actually, I could have replaced auto with any other word and the result would still be the same.) |
NOTES:
|
|
You would want to do the input/output redirection only when you are ready to do and capture the test cases one last time (and all at once) for submission. When you are still in the midst of testing/debugging your program, you would still want to do things the usual interactive way: |
|
|
|
./a6 |