Assignment 07

Due: Wednesday, March 22, 2017 at noon 100 points

Instructions: You know how to submit; do it in the usual way. However, this time 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. Do not create subdirectories in the hw7 directory. In fact, don't do that in any of our assignments!

Background: Turns out, Milhouse doesn't really like math all that much. Yeah, he can press buttons on his calculator, but the numbers are just lost on him. So, Milhouse is going to engage in a little entrepreneurial venture. He's going to open a pants store, and sell at a premium price the high-water trousers he gets from his distributor - premium price because he thinks they are provided by divine intervention. Thus, he will be provided with an inventory of pants from his distributor. Each pant has these properties:

  1. a waist measurement

  2. an inseam measurement

  3. a color

  4. availability

He's going to inventory them, recording each of these values. And then, when a customer comes into the Milhouse Trousery asking for what he has in a pant of waist measure 34, he wants to be able to quickly say that he has such and so pants of inseam this or that and color such and so. Thus, he's wanting to store information about all his stock in a quik-e-aksess filing: for each waist measurement, he'll have recorded the colors of the pants he's got available. Stating this to the customer, he can then do a more in-depth search if the customer is interested. This second filing of information is called an index file (array).

Specifications: You will begin by declaring a const array of strings you will initialize with values of the colors he exclusively deals in: "black", "blue", "red", "rainbow", "checkered", "electric green", and "polka dot". You will declare a struct for a pant that contains members for waist measure (int), inseam (int), a color (int from 0 to MAX_NUM_COLORS), available(bool). You will declare an array of (100) pants. Now, since there really isn't a distributor for Milhouse to order from (never mind that there really isn't a Milhouse!), you are going to randomly generate data for this array of pants. Walk down the array assigning random values for the members: waist from 20 to 40, inclusive; inseams from 14 to 45, inclusive; colors from 0 to MAX; availability to be true for all. NOTE: the integer value assigned for color will be your index into the const array of colors, thus avoiding recording and processing string values - for which you have to worry about spelling! You will have to write code that maps those integers to colors and vice versa. So, for example, 1 maps to "blue", 5 maps to "electric green", and "red" maps to 2, etc.

Now to create the index array. Declare another struct, call it something like "pants_of_size", that will contain two members:

  • an int for waist measurement

  • an array of shorts (no pun intended!) of a size equal to the number of colors you have.

You will make an array of MAX_WAIST - MIN_WAIST + 1 (currently that's 40 - 20 +_ 1 = 21) pants_of_size objects. Traverse your random inventory (that's the first array you built your pants in), for each pant you will note it's waist measurement and color, and then record its existence in the index array (the second array) by going to the proper waist measurement element of the array and adding 1 to the appropriate color cell of the color array. Thus, the idea here is that you have an array of entries that will tell you, for any given waist measurement, how many of those you have in what colors. For example, if you have 2 black and 1 rainbow pants with waist 25, then the color array in that cell of the array would be [2, 0, 0, 1, 0, 0, 0].

And, as usual, if you have any questions, be sure to wear your best high water pants when you go to your instructor's office to ask for help. As you can see, only the best C++ programmers wear high-water pants to work.

When you submit: In this case, the inventory is going to be random. So, we want you to look at the printed inventory and, when you are queried for a waist measurement, input one around 30 that is indeed in your inventory. Request one of the colors your program displays as available, and then buy one. Repeat. Then quit.

sold, record that fact in the inventory array by changing that pant's entry in the array as available = false, and in the pants_of_size array by changing the appropriate color array.Of course, you are expected to use functions fully for this program.

If the response is negative, ask for another customer (y/n) and start over or quit accordingly. If the response is positive (one of the colors appeals to them and they chose a valid input), then list for them all the pants in the inventory with that waist and color by looking into the first inventory array; print a list of inseam measures that they can choose from. Prompt them for the pant they want (enter the inseam from the listed inseams). Compute the price of the pants they chose, state that price, assume money is given, tell them thanks for their business, yadi yadi yadi, and ask if there is another customer. The price of the pants? Ummmmm, price in dollars is equal to waist measure + inseam measure + the high-water bonus charge of $40 IF inseam is at least 2 inches less than 0.9 * waist. Finally, if a pant was

The preceding process is just the set up. Now, your code is going to interact with the public. Loop on the following until there are no more customers. Inquire of the customer what their waist measurement is. If the input is out of range of the above limits, tell them to go somewhere else to shop. If the measure input is in [20, 40], output for them a list of the colors you have in that size by looking into the index array. Then ask if they want any of those pants. (You'll have to have them input a number to identify the color. I suggest something like this:

prompt for waist.....

cin>>customer_waist; // let's suppose they enter 26

for size 26 we have: black (enter 0), rainbow (enter 3), and polka dot (enter 6). Enter your choice (-1 for none): _

Once you have these arrays created, sort the inventory array by waist measurement. Output this array to the screen one pant per line, like this:

waist 23 inseam 35 polka dot

waist 23 inseam 24 blue

waist 24 inseam 40 black

etc ...