hw7.h

/* Programmer: Jennifer Leopold Date: October 17, 2015

File: hw7_functs.h

Purpose: Function prototypes used for building a database

of cars, and querying the database by license plate

number and car color.

*/

#ifndef HW7_FUNCTS_H

#define HW7_FUNCTS_H

#include <iostream>

#include <cmath>

#include <string.h>

#include <cstdlib>

using namespace std;

// ******************************************************

// Constants

const short

NUM_CHARS_TO_IGNORE_UNTIL_NEWLINE = 500; // for getline.ignore

const short TAB_SPACES = 8; // # spaces for tab

const short ASCII_A = 65; // ASCII value of 'A'

const short ASCII_0 = 48; // ASCII value of '0'

const char WILDCARD_MATCH = '*'; // match any character

const short LICENSE_PLATE_LENGTH = 6; // length of license

// plate number

const short NUM_CARS = 20; // # car registrations

const short NUM_COLORS = 6; // # car colors

const string CAR_COLORS[NUM_COLORS] = // colors of cars

{"black", "dark blue", "blue",

"grey", "silver", "white"};

const short NUM_NAMES = 25; // # possible names

const string OWNER_NAMES[NUM_NAMES] = // possible car

{"Homer", "Marge", "Bart", "Lisa", // owner names

"Maggie", "Krusty", "Ralph", "Apu",

"Ned", "Nelson", "Fat Tony", "Abraham",

"Sideshow Bob", "Nick", "Willie", "Moe",

"Milhouse", "Smithers", "Sideshow Mel",

"Radioactive Man", "Santa's Little Helper",

"Jimbo Jones", "Itchy", "Scratchy",

"Dr. Hibbert"};

// ******************************************************

// Type declarations

struct carInfo

{

char license[LICENSE_PLATE_LENGTH+1]; // license number

string color; // car color

string owner; // owner's name

};

// ******************************************************

// Function prototypes

// Prompt for and get 'Y' or 'N' input from the user.

// Preconditions: Parameter 'prompt' contains a string

// question the user is answering 'Y' or 'N' to.

// Postconditions: Either 'Y' or 'N' is returned.

char getYNInput(const string prompt);

// Randomly assign data to populate an array of car

// information.

// Preconditions: Parameter 'n' is the size of the array

// and should be > 0.

// Postconditions: Positions 0..n-1 of the cars array contain

// data.

void buildCarDatabase(carInfo cars[], const short n);

// Output the contents of the cars array from a specified

// range of indices.

// Preconditions: Parameters 'start' and 'stop' specify the

// range of indices over which to output (i.e., cars[start]..

// cars[stop-1] will be output, therefore it should be the

// case that 0 <= start <= stop <= n, where n is the size of

// the cars array).

// Postconditions: The information for cars[start]..cars[stop-1]

// have been output to the screen.

void printCarDatabase(const carInfo cars[],

const short start = 0,

const short stop = NUM_CARS);

// Output the contents of a cars.

// Preconditions: Parameter 'car' contains data.

// Postconditions: The information for the specified car

// has been output to the screen.

void printCar(const carInfo car);

// Prompt the user to enter a license plate number (pattern),

// a car color, and a minimum score for reporting car matches.

// Preconditions: Array 'cars' contains data in positions

// cars[0]..cars[n-1]. Hence, parameter 'n' should be >= 0.

// Postconditions: The information for a query has been output

// to the screen.

void queryCarDatabase(const carInfo cars[], const short n);

// Prompt for and get input from the user for the minimum score

// for reporting car query matches.

// Preconditions: None.

// Postconditions: An uppercase letter, period, or underscore

// is returned.

void getMinimumScoreForReporting(short& minScore);

// Calculate the similarity score between the pattern for a

// a license plate and an exact license plate.

// Preconditions: Parameter 'pattern' contains uppercase alpha-

// betic chars in the 1st 3 positions (or the WILDCARD_MATCH)

// and digits in the last 3 positions (or the WILDCARD_MATCH).

// Parameter 'license' is the same, but does not contain the

// WILDCARD_MATCH char.

// Postconditions: A total score is returned, where each exact

// char match earns 2 pts. and each wildcard match earns 1 pt.

short licenseScore(const char pattern[], const char license[]);

// Calculate the similarity score between two car colors.

// Preconditions: Parameters 'color1' and 'color2' are colors

// from CAR_COLORS.

// Postconditions: If the colors are an exact match, 2 is

// returned. If the colors are "neighbors" is CAR_COLORS, 1

// is returned. Otherwise, 0 is returned.

short colorScore(const string color1, const string color2);

// Determine the "code" associated with a color.

// Preconditions: Parameter 'color' is an entry from CAR_COLORS.

// Postconditions: The index of the specified color in

// CAR_COLORS, is returned.

short colorCode(const string color);

// Prompt for and get input from the user for a car color.

// Preconditions: None.

// Postconditions: A color from CAR_COLORS is returned via

// the pass-by-reference parameter 'color'.

void getColorInput(string& color);

// Prompt for and get input from the user for a license plate

// pattern.

// Preconditions: None.

// Postconditions: A license plate pattern is returned via

// the pass-by-reference parameter 'license'. The 1st 3

// chars will contain uppercase alphabetic chars or the

// WILDCARD_MATCH char, and the last 3 positions will contain

// digits or the WILDCARD_MATCH char.

void getLicenseInput(char license[]);

// Search for a license plate number in the cars database.

// Preconditions: Parameter 'cars' contains data in positions

// cars[0]..cars[n-1]. Hence, parameter 'n' should be >= 0.

// Parameter 'license' contains uppercase alphabetic chars in

// the 1st 3 positions and digits in the last 3 positions.

// Postconditions: True is returned if the specified license

// plate number is found; otherwise, false is returned.

bool findCarByLicense(const carInfo cars[],

const short n,

const char license[]);

#endif