Assignment 07

Due: Thursday, April 3, 2014 at noon 100 pts

Instructions: You know how to submit; do it in the usual way. You will submit multiple files for this programming project. The cssubmit script will work as usual, picking up all .cpp and .h files in the current directory. So, make sure you have created a separate directory for your hw 7 program. You are to fully functionalize this project, writing functions for everything.

Background: Ralph wants to get organuhzized with all his sssstuff. There's only two things Ralph cares about, his letters and his Wookies. (He has a collection of stupid plastic letters and another collection of stupid plastic Wookies.) He wants a program written by you to run on his stupid plastic computer to sort his stuff. Now, since you don't yet know data entry or file I/O, you are going to randomly generate the collections of Ralph stuff to sort. Don't worry, he's not going to know any difference! Thus, after generating his collection of 10 random letters and 8 random Wookies, you will pass these collections to a templated sort algorithm, and then to a function to print them.

Specifications: Let's begin by assuming Ralph's world is comprised of 10 letters and 8 Wookies. Your program should:

    • define what a Wookie is. You yourself might want to know what a Wookie is! A Wookie is a name, weight, and height. Think struct.

  • declare an array to hold the required number of Wookies, and another to hold the required number of letters.

  • have a function called "init_array" to which you pass an array of Wookies that will make the Wookies in the array of Wookies have random weights and heights, and, for each, prompt for a name for the Wookie from the user. The weights should be between 12 and 78, inclusive; the heights should be between 10 and 34, inclusive.

  • have another function called "init_array" to which you pass a array of characters that will make the letters in the array random. The letters should all be uppercase from A to Z (ASCII 65 -> 90).

Notice you'll have two functions called "init_array".

  • a templated function to sort an array of stuff....any kind of stuff.

  • a templated function to output to the screen an array of stuff....any kind of stuff.

  • a operator overload to determine the greater of two Wookies. We dictate that a Wookie is "greater than" another Wookie if the sum of its height and weight is greater than that same sum for the other Wookie.

  • an overloaded insertion operator ( << ) so that you can output Wookies easily.

Details: There are several details to discuss.

  • The sort routine that you are to use is described as follows (we'll call it Ralph's Sort -- a name that is unique, interesting, intriguing, fashionable, descriptive, and, above all, imaginative). The filled portion of the array (henceforth known as 'the array') will be partitioned into two sub-arrays: the sorted sub-array and the unsorted sub-array. At first, the unsorted part will be full and the sorted part will be empty. For example, suppose we have

    • a[0] a[1] a[2] a[3] a[4] a[5] a[6] 5 9 -1 4 7 0 3

      • as our array to begin with. The sorted part is nonexistent and the unsorted is the entire array. The first step of Ralph's Sort is to examine the first value in the unsorted part and move it into its proper position in the sorted part. Thus we have

      • a[0] a[1] a[2] a[3] a[4] a[5] a[6] 5 9 -1 4 7 0 3

      • Next, examine the new first element of the unsorted part (a[1] = 9) and move it into its proper position in the sorted part. Since it is bigger than 5, it stays in its relative position. Thus, we have

      • a[0] a[1] a[2] a[3] a[4] a[5] a[6]

    • 5 9 -1 4 7 0 3 Next, examine the new first element of the unsorted part (a[2] = -1) and move it into its proper position in the sorted part. Its movement would look like

      • a[0] a[1] a[2] a[3] a[4] a[5] a[6] 5 9 -1 4 7 0 3 a[0] a[2] a[1] a[3] a[4] a[5] a[6] 5 -1 9 4 7 0 3 a[2] a[0] a[1] a[3] a[4] a[5] a[6] -1 5 9 4 7 0 3

      • And so on. This looks simple here, but when programming this routine, you may find it more difficult. Don't underestimate the difficulty of this problem. Note there is only one array in this process of sorting; you don't use a second array!

  • Besides inputting names of the wookies, you won't have any user interaction in this program. Simply load up the arrays of letters and wookies and then give the wookies names, sort them, and output them all in order (both letters and wookies), and you're good to go. When entering names, use names with no whitespace (no spaces).

  • Output format of a wookie should be: Bart weighs 25 oz and is 20 inches tall (total 45). (Of course, these are example values.)

When you submit: do so. You make up the names (....remember, no spaces!)

Good luck. And always remember that if you have any questions, don't ask Ralph. He'll be busy playing with his stupid plastic letters and his stupid plastic wookies.