Assignment 07

Due: Wednesday, Oct. 26, 2016 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: Chief Wiggum, observing Lisa's aptitude for environ-mental activism, has enlisted her help in his politically-correct attempt1 to try cleaning up the town of Springfield. He (Wiggum) has a database of the piles of refuse scattered about the city. He has divided the city into 7 sectors, and has a record of the weight of each pile of trash and its associated sector. No one claims the piles, no one will take the piles, and certainly no one admits to creating the piles. But Lisa, the activist that she is, has also created her own database of "Offenders". She used your program #5 to sucker people into incriminating themselves with respect to bad social behavior (you know, how much food they wasted, how much public transit they don't use, how related to Burns they might be .... or not (old people are terrible) ), and how many whole pigs they ate for dinner. Thus, she has a list of people with their associated "guilt factor" recorded. Wiggum wants to do some good old fashion predictive police detective work. Clearly, the "guiltiest" people are the ones responsible for the largest piles of trash. Isn't that obvious? C'mon! If you didn't want to be blamed for a pile of trash, then you shouldn't have looked so guilty. Put that pig away and have some eggplant for dinner.

Wiggum and Lisa want your program to output information about the offenders, how trashy each city sector is, and to be able to search the databases in order to correlate particular trash pile with likely offenders - mostly they're guilty, let's admit it.

Specifications: In order to make this program fun and workable, you will generate data randomly. To begin with, you will have to create two (and only two) arrays representing Wiggum's database and Lisa's database. Both databases have 15 entries. Each element of Wiggums array will have two values:

  1. a sector number (1 -> 7)

  2. the weight of a trash pile (in lbs.) in that sector (25lbs -> 500lbs)

It should be obvious that, since there are more piles than sectors, each sector will possibly (remember, this data will be generated randomly) contain more than one pile....or even zero! Also, each element of Lisa's array will have two pieces of information:

  1. the offender's name

  2. the offender's guilt value (100 -> 10,000)

The names of the offenders will be chosen in order from this list: Homer, Maggie, Bart, Moe, Barney, Marge, Cletus, Snake, Mr. Burns, Dr. Nick, Krusty the Clown, Chief Wiggum, Ralph Wiggum, Skinner, Lenny. You should make a const string array to hold these names, and then assign from that array. Also, DO NOT do a copy/paste from this document for it will almost certainly lead to dire consequences for the workability of your program. Type the names individually into your editor. (If you copy/paste, hidden characters can be picked up and pasted which will ruin your program.)

The program will accomplish four main tasks:

  • Zeroth task: Output the two databases as follows: Wiggum's database in descending order of weight of piles, one per line using this format: Sector x: weight yyy lbs. Lisa's database in descending order of guilt, one per line using this format: Name, guilt = zzz.

  • First task: Output the names and guilt factors of the two guiltiest residents/offenders of Springfield (top two guilt factors).

  • Second task: Output the names of the least number of residents/offenders who contribute at least 50% of the total trash in Wiggum's database. Wiggum (justifiably) assumes that the resident with the highest guilt factor is responsible for the largest trash pile, the second guiltiest resident is responsible for the second largest pile, etc.So, for example, if Wiggum's database indicates that the four largest trash piles account for 50% of the total trash weight, your program will output the names of the four guiltiest residents.

  • Third task: For each sector, output a list of the weights of the individual piles of trash in that sector, and the total weight of the trash in that sector. Then, prompt for and read in from the user of the program information that identifies a particular pile of trash. Using this information, your program will identify the resident offender, by Wiggum's reckoning, most likely to have dumped the trash. And to make it clear: according to the chief, the guiltiest offender probably created the biggest pile, the next guiltiest offender likely dumped the second largest pile, etc. Allow the user to query the program as many times as they wish until they desire to quit the program.

Details: For this program, you will need to sort your data. You are required to use a templated sorting algorithm of your choice. In order for this to work, you are going to have to overload the comparison operator (either < or >) for both types of data (Lisa's and Wiggum's). The way to accomplish this will be presented in your lecture class. You must know then how to compare data in each database (array). So, for data in Wiggum's array, one entry is "less than" another entry if the weight of the trash in the one is less than that in the other. In other words, you compare two trash piles by comparing their respective weights. And for Lisa's database, an entry in the array is less than another if the guilt value of one is less than the guilt value in the other. In other words, you compare two offenders by comparing their guilt.

Your output needs to be readable and well organized. And, again (and forever more), you will range check user inputs if possible.

When you submit: As usual, the program will compile and run. At run-time,

  • Ask for a pile of trash that doesn't exist in the data to be explained, i.e. find the most likely perpetrator.

  • Ask for the fourth largest pile to be "explained" - find the perp!

As usual, if you have questions, don't hesitate to ask your instructor. You can ask chief Wiggum, but he might throw you in jail.

1Yeah, not really.