COSC 071: Computer Science I
Homework 1
Spring 2000
Due in 1st lecture of week Jan 17-21
2 points
This homework is designed to get you thinking about algorithms, object
hierarchies, and object decomposition.
- Hoya Pizza sells a 9" square pizza with one topping for
$9.99, and Saxa Pizza sells an 10" round pizza with one topping
for $8.99. Which is the better buy?
- An algorithm is just a step-by-step procedure for accomplishing
a task. The steps you took above constitutes an algorithm, albeit
a very specific algorithm. A limitation is that it only works
for 9" square pizzas that cost $9.99 and for 10" round pizzas that
cost $8.99. Instead of using the actual numbers provided, rewrite
your previous ``algorithm'' using variables or symbols that represent
the numbers. For example, instead of writing 9.99, write Round_Pizza_Cost,
and instead of writing 10, write Round_Pizza_Size.
For example, if we had a triangle pizza, we may write something like:
- Triangle_Pizza_Cost = 7.99
- Triangle_Pizza_Base = 6
- Triangle_Pizza_Height = 9
- Triangle_Pizza_Area = 0.5 x Triangle_Pizza_Base x Triangle_Pizza_Height
- Triangle_Price_Sq_In = Triangle_Pizza_Cost / Triangle_Pizza_Area
The advantage of doing this is that we've separated the procedure for
calculating the price per square inch of a pizza from any set of
specific numbers. To compute a new price per square inch, we simply
reassign the variables that correspond to the cost and the size of
the pizza.
- Assume that you are restricted to four actions: INPUT, CALCULATE,
DECISION, and OUTPUT. Express your algorithm for deciding which pizza
is the better buy in terms of these actions.
For our triangle pizza example, we may write something like:
- INPUT Triangle_Pizza_Cost
- INPUT Triangle_Pizza_Base
- INPUT Triangle_Pizza_Height
- CALCULATE Triangle_Pizza_Area = 0.5 x Triangle_Pizza_Base x Triangle_Pizza_Height
- CALCULATE Triangle_Price_Sq_In = Triangle_Pizza_Cost / Triangle_Pizza_Area
- OUTPUT Triangle_Price_Sq_In
- A bicycle consists of many different parts.
- List the parts of a bicycle that you can differentiate by movement
when watching someone ride the bike. For instance, this would imply that
the seat is not distinct from the body, since the seat always moves relative
to the body.
- Based on the above decomposition, further decompose the bicycle into
the rest of its parts. For example, the body -> seat, frame.
- In a university, there are many different types of people.
There are employees and students, but there are also different
types of employees and different types of students. All
of the people of a university have something in common: a name.
All employees have a salary. All students have something in
common also. Draw a hierarchy for people in a university.
(Draw nodes for as many different types of people as you can.)
At each node in the hierarchy, list at least one property
common to everyone who follows in the hierarchy. Here's
a start: