CS 102 Assignment #6

Due: April 6

Sample Solution

A telemarketer has come to you with a problem. To get the best return on her efforts, she would prefer to target only those people in Poughkeepsie who are both rich and gullible. She attempted to buy a suitable list of names from other telemarketing firms but they wouldn't share. The best she could do was to purchase two separate databases: One having to do with where the rich folk are, the other describing where the gullible citizens live. You've been hired to combine them into a "map" of the city that identifies areas where people are both rich and gullible.

Each of the databases breaks the city down into rectangular regions and gives a percentage of the people within a particular region that are rich or gullible. You must combine these maps into a single map of regions and estimate the percentage of rich and gullible people within each new region. Since the problem involves lots of rectangular regions, you've decided to implement a Rectangle class to represent them.

The database maps can be represented by lists of rectangles. For this assignment we'll use the C++ Standard Template Library (STL) list class. This material will be introduced both in lecture and in lab. A brief overview can be found here.

Intuitively, combining the information from the maps is done by laying one map of rectangles over the other to create a more finely detailed map. One way to do this in C++ is to take one rectangle from the first map and look for intersections with all rectangles from the second map. If any are found, store the new rectangles in the output list and repeat the process for the remaining rectangles from the first map. (We'll talk more about how to do this in class.)

A description of the Rectangle class is in rectangle.H, which describes all of the member functions you must write. (Both rectangle.H and some sample input files are in the ~cs102/Overlay directory.) In addition, you must implement the following functions:

  1. A function FillFromFile that prompts the user for a file name, then reads data from the file and fills in a list of rectangles. The data in the file consists of four integers and a float for each rectangle: The rectangle's lowest X coordinate, its lowest Y coordinate, and its highest X and Y coordinates (in that order), and a percentage expressed as a floating-point value. You should prompt the user repeatedly for file names until the data file has been opened successfully.
  2. A function ComputeOverlay that takes two lists of rectangles as arguments and constructs a third list of rectangles as described above.
  3. A function Summarize that is passed a list of rectangles and its size and prints the following information: The number of rectangles in the list, their total area, and the number of rectangles whose value is above 50%.
  4. The main function, which calls FillFromFile twice --- once to fill each of the two arrays of input rectangles --- then calls ComputeOverlay, and finally calls Summarize on the combined rectangle information.

Submit your assignment and output from a sample run on map1 and map2 via the submit102 program. It's recommended that you create some small input files to test your program, but these need not be submitted.

Grading criteria: