#include #include #include #include "descartes.h" /* Global variables for storing the lines drawn */ int num_lines = 0; /* number of line segments in lines */ lineSeg_t lines[10]; /* distance at which points are too close */ const int NEARNESS = 5; /* Returns 1 if the two points are within dist of each other in both dimensions */ int Near(point_t p1, point_t p2, int dist) { /* BEGIN ANSWER (a) -- do not delete this line */ // ADD YOUR CODE HERE /* END ANSWER (a) -- do not delete this line */ } /* Draws a random line, whose end points are not too near to any existing line, and stores it in the lines array. */ void DrawNewLine(void) { /* BEGIN ANSWER (b) -- do not delete this line */ // ADD YOUR CODE HERE /* END ANSWER (b) -- do not delete this line */ } /* Returns the index of the shortest line in the lines array */ int FindShortest(void) { /* BEGIN ANSWER (c) -- do not delete this line */ // ADD YOUR CODE HERE /* END ANSWER (c) -- do not delete this line */ } /* Gets a point from the user identifying one of the lines */ int ClickedLine(void) { /* BEGIN ANSWER (d) -- do not delete this line */ // ADD YOUR CODE HERE /* END ANSWER (d) -- do not delete this line */ } int main(void) { OpenGraphics(); /* Initialize random number generator */ srandom(time(NULL)); int i; for (i=0; i < 10; i++) { DrawNewLine(); } int shortest = FindShortest(); printf("Please click on one end of the shortest line.\n"); int clicked; while ( (clicked = ClickedLine() ) != shortest ) { printf("Wrong - try a different line!\n"); } printf("Correct!\n"); CloseGraphics(); return EXIT_SUCCESS; }