CS-211 Fall 2015 Lab 10 Lists of Lists


Back in Lab 4, we coded a functions to determine if a point fell inside the bounding box of a polygon. In lab 5, we extended that code to determine if a points was actually inside a polygon. In lab 4 and lab 5, we treated a polygon as a list of x coordinates and a list of y coordinates. For this lab, we are going to treat a polygon as a list of floating point numbers. In that list, the first element will be the number of verteces in the polygon (e.g. 3.0 for a triange, 4.0 for a rectangle, and so on). The remaining floating point numbers will be alternating x and y coordinates - a pair for each vertex.

However, in this lab, we are going one step further. We are actually going to look at a list of polygons - so utlimately, we are looking at a list of lists.

Getting Started

After you have logged on to one of the Linux Lab machines, open a terminal window, download lab10.tar.gz and move it into you home directory. Use the command tar -xvzf lab10.tar.gz. This will unpack the tar file and make a new lab10 subdirectory. Make the lab10 directory your current directory, and list the files in the lab4 directory. There should be 5 files... one called Makefile, three program files called contains.c, poly.c and poly.h, and one example polygon files called shapes.txt

The Polygon and Polygon List Functions

The two C files called poly.h and poly.c contain the declarations and definitions for the functions to handle polygons and lists of polygons. Look over this code and make sure you get a feel for how things work in these files.

The poly.h file contains everything you need to invoke the polygon functions. Therefore, we #include "poly.h" in our main C file. The function definitions for these files is in the poly.c file. But the important thing is how these functions work.

The poly.h file contains the following definitions:

All of the definitions for all of the functions declared in poly.h are in the poly.c file.

The contains.c File

As in lab4 and lab, the main function for the command we will be building is included in the main.c file, along with a couple of extra functions, as follows:

Using The Makefile

The Makefile file in the lab10 directory contains the recipes to build the C program associated with whose "main" function is in contains.c. To build the contains executable, use the make contains.

The Makefile file contains several other "targets" which allow you to do other things using the make command. The following targets are supported:

Hints on Making Everything Work

Notice that if you uncomment the code, it calls a new function that has not yet been defined called getPolyList. The real job in this lab is to write the getPolyList function. Clearly, based on how it is used, this function is going to take a variable called "pl" as its first argument. "pl" is a polylist variable - a pointer to an instance of the poly_list structure... in fact, the one that makePolyList has created for you. The second argument is just an integer - the index of the polygon you want to extract from the polylist variable. The return value is the polygon itself.

You may decide how to write this function, and where to put it, but I would recommend putting this in the poly.c (and poly.h) files to be consistent with the rest of the polylist functions.

Lab Report

Download and edit the following file: lab10_report.txt. Then submit your editted file on Blackboard in the Lab_10 report area.