Faculty of Applied Science and Engineering, University of Toronto
CSC181: Introduction to Computer Programming
Due: Tuesday, 26 September by the start of lecture.
You will write a couple of small programs that perform the tasks described below. The input to the programs must be read from the standard input and the output from the programs must be printed to the standard output.
1. Given an initial point P0 on a 2-D plane, and a list L of N points <P1, P2, ..., PN> on the same plane, find and output the two points from L which are nearest to P0 (using Euclidean distance).
The input to the program is as follows:
<x-coordinate of P0> <y-coordinate of P0> <N = length of list L> <x-coordinate of P1> <y-coordinate of P1> <x-coordinate of P2> <y-coordinate of P2> ... <x-coordinate of PN> <y-coordinate of PN>
Suppose A1 and A2 are the points in L that are the nearest and second-nearest points to P0, respectively. Then, the output of the program should be as follows:
<x-coordinate of A1> <y-coordinate of A1> <x-coordinate of A2> <y-coordinate of A2>
Code your solution with the following assumptions in mind:
2. Given a list L of N squares <S1, S2, ..., SN> on a 2-D plane, compute and output the bounding rectangle for those squares, i.e. the smallest possible rectangle which encompasses all the squares.
The input to the program is as follows:
<N = length of list L> <x-coordinate of S1> <y-coordinate of S1> <side length of S1> <x-coordinate of S2> <y-coordinate of S2> <side length of S2> ... <x-coordinate of SN> <y-coordinate of SN> <side length of SN>
Suppose R is the bounding rectangle. Then the output of the program should be as follows:
<x-coordinate of R> <y-coordinate of R> <width of R> <height of R>
Code your solution with the following assumptions in mind:
Write your solution code for task 1 in a file called p1.c, and
your solution code for task 2 in a file called p2.c. You should
also put together a meta-file (called info) containing other information
about your assignment. The format of the meta-file is as follows:
Name:<your name> StudentNo:<your student #> Files:<comma-separated list of files submitted> Compiler:<compiler used to compile p1.c and p2.c>
Electronically submit your solution code and meta-file to your Assignment 1 subdirectory under the CSC181 submit directory on the ECF server:
submitcsc181f 1 p1.c p2.c info
Note that if you run this command again, it will overwrite your previous submission.
You can check your submission using the following command:
submitcsc181f -l 1
Last updated on 2000-09-14 by Ray Ortigas.