Missing page.
Sorry. The page you requested does not exist on the Department of Computer Science website
[an error occurred while processing this directive]
File: index.shtml
Creator: George Ferguson
Created: Tue Nov 6 10:02:09 2012
Time-stamp: Sorry. The page you requested does not exist on the Department of Computer Science website
Edit 12 Nov 2012: A student has pointed out
the following to me:
Since
In a normal tree data structure, this sort of thing
doesn't matter, but for this particular example, it
isn't clear how we're supposed to implement this from
the prompt, so I was wondering how we were expected to
handle this.
Note: You may need some methods for printing the contents of the
arrays, if the defaults don't look good. Don't
forget
On to Part 2 when it is available...
Last update: Monday, 12-Nov-2012 09:22:40 EST
Page does not exist.
Missing page.
[an error occurred while processing this directive]
CSC170: Introduction to Programming and the Web
Fall 2012
[an error occurred while processing this directive]
Assignment 8: Objects: Part 1
Date object, but it really
doesn't have many useful methods. Let's build our own.
Demonstrate each of the aspects of your CalendarDate. It should take three
parameters: the day, month, and year of the date it
represents and store them in the constructed object
instance.
isChristmas() that tests whether
a CalendarDate is Christmas Day (December 25). A
test method like this always returns a boolean value (true or
false).
next() that increments
a CalendarDate instance to the next day. Note that
it is not enough to simply increment the day
field. Watch for special cases.
previous() that decrements
a CalendarDate instance.
increment(n) that increments
a CalendarDate by the given number of days. Note
that n can be positive, negative (in which case
it means decrement), or even zero.
CalendarDate
object with reasonable output to the page's document.
Demonstrate each of the aspects of your Person object.
It should take two parameters: the person's first and last
names and store them in the constructed object instance. It
should also setup additional properties
named mother, father, siblings,
and children. The first two will hold references
to other Person objects representing the person's
mother and father respectively. The latter two will be arrays
that contain references to other Person objects
that are in the corresponding relationship. In your constructor,
initialize these to an empty array.
setParents(mother, father) that
takes as arguments two Person objects and makes
them the parents of the Person object on which
the method is invoked.
addSibling(sibling) that
adds its argument (another Person object) to the
array of siblings of the Person object on which
the method is invoked.
addChild(child) that works similarly
but adds to the array of children of the Person
object on which the method is invoked.
Person
another Person's parent, you are also implicitly
adding to the first Person's (the
parent's) children. Similarly
for addSibling and addChild. Adjust
your methods to maintain these so-called reciprocal
relationships.
They are quite right.
Therefore you should only worry about maintaining the
reciprocal relationship for the parentof(child) is not a one-to-one function
(children have two parents), how are we to maintain a
reciprocal relationship when we add a child to person?
Without knowing whether that person is supposed to be the
mother or father (person doesn't have a "gender" or
similar in its constructor), we can't pick which of the
two to assign person to for the child we are adding to
person...
siblings
property. That's enough to make the point that this part
of the question was making anyway.
Person
object with reasonable output to the page's document.
Array.join in this context.
Things to think about
undefined).
optional
parameters, which will have value
undefined if they weren't given in the invocation of
the constructor, but Javascript is not as flexible about this as
some other programming languages.