Assignment 07

Due: Thursday, Oct. 29, 2015 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: Now that you've done all this work for Homer, he and his company, "Homer-soft", have become very well known in Springfield as local heroes of security concerns. Seems everyone wants him to solve their "security" problems. Like Krusty the Clown, who has recently suffered a rash of "burger dash" offenses - order a Krusty-burger, pick it up, and then dash away in the car without paying. So he's gone to Homer to get him to get you to help solve the problem. Usually, Krusty can see a license plate number and the color of the car. Make and model and year of the car is of no use since they live in cartoonland where all cars are the same. So, if you can write a program that will search the Springfield municipal auto registration records for a license and car color match, then Homer's got something to offer Krusty. Krusty can then enter the info he has on the offending car and maybe catch the burger theif! Maybe.

One of the problems with Krusty's scheme is that usually he is unable to read the entire license plate, only getting some of the characters. Poor Krusty is also sorta color blind (the reason he wears ridiculously loud colors), so identifying the color of the car is a near miss sometimes. Your code will need to address these issues. And your program will help make Krusty a calmer business proprietor.

Specifications: Your program, since we really don't have access to the Springfield municipal auto registration records, will start by generating a database of registrants. You will use an array, and create 20 registrations. Each element of the array will represent a car/owner registration that will contain a license, a car color, and an owner's name. The license will be six characters long, the first three of which will be alphabetic, and the remaining three will be digits. The characters are chosen randomly from A, B, and C, and 0 - > 9.1 The color will be chosen randomly from this set of colors: black, dark blue, blue, grey, silver, white. Names will be chosen randomly from a list of names (first name only) you create; we suggest you think of at least 25 names. For both the colors and the names, create for each a constant array of strings sized appropriately that you will initialize to the colors given and the names you dream up. Here is the array colors in the order we require:

const string colors[6] = {"black", "dark blue", "blue", "grey", "silver", "white"};

Then the random assignment of colors and names can be done by randomly indexing into these arrays. As you create the registrations, be sure you do not duplicate the license plates! Note: when you create this database, have your code create the license first, then assign the color, then assign the owner. If you do that, then we can specify the seed for the random number generator and so ensure everyone's output will be the same.....I think. Also, be sure to seed before you create your database.

When the database has been created, output it with one entry (registration) per line. You can check your work this way.

Ok, now that you have a database to work with, your code is going to work with it. (How prophetic!). Your code is to prompt the user for the license plate and color of the offender's car and read in said information. Then your program will search the database of registrations for matches and report them. I'm sure you are now questioning how there can be more than one match! Here's the deal. As stated, Krusty can't always catch the entire license as the car speeds away. He can use a special symbol, '*', to indicate missing information. So, for example, he is allowed to report an offender's plate as ABC***, meaning that he saw the first three letters clearly as ABC, but that he was unable to catch the last three digits. Or, he might say the plate read A*B22* meaning the first letter was A, the third letter was B, and then the first two digits were 2, but he just couldn't see or remember the rest of it. Or, he might ask for ***113 meaning that he couldn't read the first three letters but he was sure the digits were 113. And, of course, he might report the license was something like A3B22A, which means he was just plain WRONG since digits aren't allowed in the first 3 positions and letters aren't allowed in the last 3 positions. In such an instance like this last example, have your code simply reject the input. And, finally, if he read the entire plate correctly and remembered it, that is certainly allowed; e.g. he reports AAB331. So, '*' acts as a wildcard that will match automatically, and Krusty can use it to indicate that he can't specify the character in that position.

Once the license plate number and color are entered, your program will compare this user input to the registrations in the database and 'score' how they match up. Scoring is simple: add the score for the license plate match to the score for the color match.

  • The license: for each position of the license characters, 0 is given if no match and 1 is given for matching a '*', and 2 is given for an exact match. The score is the sum of these. Here are some examples:

Krusty's input a database entry score

ABB*22 ABC122 2 + 2 + 0 + 1 + 2 + 2 = 9

BBB123 ABC333 0 + 2 + 0 + 0 + 0 + 2 = 4

A****1 ABC331 2 + 1 + 1 + 1 + 1 + 2 = 8

(It is worth noting from the examples that a high score can be gotten from a good 'solid' match or from having a lot of wildcards.)

  • The color: score 2 for an exact match; score 1 for a near match on the color; score 0 otherwise. So, what is a 'near match'? Well, black and dark blue can be confused for each other. So, if the reported color is black, but there is a registration with a color of dark blue, then it's a near match. Thus, according to the color scheme allowed (as indicated above), black is near dark blue, dark blue is near black or blue, blue is near dark blue or grey, grey is near blue or sliver, silver is near grey or white, white is near silver.2 In order for you to code this, we suggest you code an equivalence between the colors and integers and then compare the integers. Thus, for the 6 colors, you might make white = 1 ... black = 6. Then, if the difference is 0, score 2, and if the difference is 1 score 1, and any greater difference scores 0. There are many ways to code this scheme.

Your program will also have to query the user for a minimum score for reporting. That is, after your program searches the database for matches, it is to output the matches and their scores. But, it's not a good idea to output all scored matches - that would be the entire database! So, the user might only want to see matches that score 5 or above, for example. In this case, 5 would be the minimum score for the report. Of course, after inputting this value from the user, have your code report matches (car's owner, license, and color on one line) for each score. Here's an example of output of a database, and the output when the user (presumably Krusty) requests matches scoring 5 or better for a white car with license C*C*47:

Car Database:

License Color Owner

------------------------------

CAB098 white Itchy

AAB457 blue Scratchy

ABA149 white Marge

CBA877 grey Apu

BCC317 silver Smithers

BAC475 white Santa's Little Helper

CBB672 black Maggie

AAA008 white Sideshow Bob

ABC349 white Itchy

CBC641 white Nelson

CCA576 blue Willie

BBC630 black Moe

ACA100 dark blue Abraham

ACC235 dark blue Lisa

CCA852 black Nick

CAC037 white Nelson

CCA107 blue Maggie

CBB679 blue Santa's Little Helper

ABA489 blue Nelson

BCB248 silver Krusty

Score 10:

CBC641 white Nelson

CAC037 white Nelson

Score 9:

Score 8:

ABC349 white Itchy

Score 7:

BCC317 silver Smithers

Score 6:

CAB098 white Itchy

ABA149 white Marge

CBA877 grey Apu

BAC475 white Santa's Little Helper

CCA107 blue Maggie

Score 5:

BCB248 silver Krusty

Furthermore, your program is to continue prompting the user for inputs until they want to quit.

Coding thoughts: For this assignment, you will use functions, arrays, structs, n'stuff. Use functions properly and well! You do not have to write greet() and signoff() functions; just put those messages in main. If you haven't already noticed, we are no longer dictating how you are to do every little thing in your coding. You need to now start making vital decisions about the format, structure, efficiency, correctness, robustness and overall readability of your code.

When you submit: Seed the random number generator with 10. Then have Krusty report

  • AA***9 silver 5

  • *BB*03 dark blue 4

  • ABA707 blue 7

  • quit

And, as always, be sure to ask for help if you need it.

1It was Chief Wiggum's job to make license plate numbers. But he gave the job to his genius son, Ralphie. When he learned his ABCs, Ralphie learned just exactly that... A, B, and C. The rest of the alphabet is not to be included in license plate numbers.

2Ok, so this may seem ridiculous to you. But if we added in 50 more colors, then it wouldn't seem so ridiculous. But I'm guessing you really don't want us to make you do all that.