Faculty of Applied Science and Engineering, University of Toronto
CSC181: Introduction to Computer Programming
Due: Thursday, 12 October by the start of lecture
Marking Scheme: 50% Correctness, 25% Style, 25% Documentation
Announcements are available on the course Web site. It is your responsibility to keep up-to-date on these announcements.
The purpose of this assignment is to give you practice implementing data types: the structures holding the data and the functions manipulating the data. You will be working with three data types:
Point, which represents a point on a 2-D plane.Rectangle, which represents a rectangle on a 2-D plane.RectangleList, which represents an ordered collection of Rectangles.You must define the data structures for these types (with matching typedefs)
inside a file called a2.h:
typedef ?????? Point; typedef ?????? Rectangle; typedef ?????? RectangleList;
a2.h will also include the prototypes for the functions you write.
The actual definitions will be placed in a file called a2.c.
You must also add the following line to a2.h, since some of the
functions you'll be writing will return boolean values:
typedef enum {false, true} boolean;
Point FunctionsA Point represents a point on a 2-D plane. As such, it has x-
and y-coordinates, which are initially set through calls to pointInit,
and subsequently accessed through calls to pointX and pointY.
The complete set of functions you have to implement for Point
are as follows:
|
|
|
|
|
|
boolean pointAreEqual(const Point p1, const Point p2)Returns true if the two given points are equal (i.e. have the same
x- and y-coordinates), false otherwise. |
|
|
Rectangle FunctionsA Rectangle represents a rectangle on a 2-D plane. It has a centre
point, as well as a width and height, which are initially set through calls
to rectangleInit, and subsequently accessed through calls to rectangleCentre,
rectangleWidth and rectangleHeight.
The complete set of functions you have to implement for Rectangle
are as follows:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RectangleList FunctionsA RectangleList is an ordered collection of Rectangles.
They are indexed like a C array, with the first rectangle at index 0
and the last rectangle at index n-1, where n is the
number of rectangles in the list (returned by rectangleListSize).
The list should have a minimum capacity of 1024; that is, it must be able to
hold at least 1024 rectangles.
rectangleListInit is used to get an initially empty list. New
lists can be constructed through calls to rectangleListAdd (which
appends a rectangle) and rectangleListSet (which substitutes a
rectangle at a particular position). Rectangles in the list can be accessed
through calls to rectangleListGet.
The complete set of functions you have to implement for Rectangle
are as follows:
|
|
|
|
|
|
RectangleList rectangleListAdd(const RectangleList rl, const Rectangle
r)Returns a rectangle list that would be the result of appending the given rectangle to given rectangle list. |
|
|
RectangleList rectangleListSubList(const RectangleList rl, const
int a, const int b)Returns a rectangle list containing the portion of the list between a,
inclusive, and b, exclusive. (In the returned list, the rectangle
at index 0 will be the rectangle that is at index a
in rl.) |
|
|
|
|
|
|
1. All of the function parameters are marked const. Therefore,
your functions cannot change them.
2. You may assume that all Point, Rectangle and RectangleList
variables are initialized using their respective initialization functions before
they are used for any other purpose.
3. Use structs in your definitions of the Point,
Rectangle and RectangleList data structures, but do
not use pointers.
4. Your functions must stay silent unless there is an error. That is, they
cannot print anything (using printf, for example) unless an error
occurs.
5. You should test your functions thoroughly, but you do not have to hand in any testing.
6. Do not include a main function in a2.c.
7. Above all else, keep it simple. NO extra credit will be given for extra features.
This assignment must be done in C. Note that this means that assignments
done in C++ will not be accepted. We will use gcc to compile
your programs, and they must compile using gcc. It is your responsibility
to ensure that your source files compile on ECF.
As specified above, write your solution code in a2.h and a2.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>
Electronically submit your solution code and meta-file to your Assignment 2 subdirectory under the CSC181 submit directory on the ECF server:
submitcsc181f 2 a2.c a2.h 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 2
Last updated on 2000-10-02 by Ray Ortigas.