Assignment 06

Due: Friday, April 2, 2021 at noon 100 points

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.

Instructions: You know how to submit; do it in the usual way. You will submit multiple files for this programming project. Background: Milhouse Van Houten is Bart's best buddy. He is well known for his blue hair, thick glasses, and high-water pants. If you don't know, high-water pants are those pants that you've out grown and the inseams are just too short. Well, high-water pants have become very popular in U.S. culture lately (no, really!! get some and wear them around and see how people flock to you!!) and Bart wants a piece of the action. So, he's going to try retailing them (when he really ought to be re-tailoring them). So, he's 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 a 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 Simpson High-Water 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 - 1), available(bool). You will declare an array of 100 pants. Now, since there really isn't a distributor for Bart to order from (never mind that there really isn't a Bart!), you are going to randomly generate data for this array of pants. Walk down the array assigning random values for the members: waist values from 20 to 40, inclusive, and colors from 0 to MAX_NUM_COLORS - 1. Availability is to be set true for all. Now, for the inseam for each pant, you will have to randomly choose an inseam value from a file of inseam values that we will supply for you. Below we will describe how you can download from my file system the data file. In any case, it will be just a file of ints, one per line, and NO indication as to how many there are in the file. You are NOT allowed to open the file and count them and use that number in the program. You can have your program do that, if you like, but not you. And, no, you should not read in the entire file into an array and store it internally.

waist 23 inseam 35 polkadot

inseam 24 blue

inseam 22 green

waist 24 inseam 40 black

etc ...

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 polkadot (enter 6). Enter your choice (-1 for none): _

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 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.

In order to get the data file of inseams, all you have to do is issue this command from the directory in which you want the file to reside:

wget http://web.mst.edu/~price/1570/inseams.dat

This will copy the file from my directory into yours. It is a file of inseams, one per line.

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 know, only the best C++ programmers wear high-water pants to work.

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:

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].