CS 4448 - Spring 1998
Object-Oriented Programming and Design
Homework #3
Due on Tuesday, February 3 at the start of class.
Print out this C++ assignment with a sample run of the assignment. Also tar
up the necessary files (.h .cc makefile etc.) for me to test your
program and email them to me.
C++ program - And you are?
For this assignment you need to create the classes below and they
must respond to the methods in the way specified. Your
implementation may respond to additional methods but the methods and
and responses should be appropriate for that class. First the
instantiation method is given and then examples of method responses follow.
Create the classes below and the constructor
- Dog - sasha = Dog(40,"Sasha","Shepard");
- Cat - romeo = Cat(20,"Romeo","Mix");
- Sprinter - carl = Sprinter(180,"Carl Lewis")
- Molecule - water = Molecule("Water")
- Hydrogen - h = Hyrdrogen()
- Krypton - kr = Krypton()
- Pine - pine = Pine(25,20)
Methods to implement and the result
- sasha.name() -> "Sasha"
- romeo.name() -> "Romeo"
- romeo.mass() -> 20
- romeo.mass(25) -> 25
- romeo.mass() -> 25
- sasha.speak() -> "Whof, Whoph"
- romeo.speak() -> "Meow"
- sasha.legs() -> 4
- sasha.hasLiveYoung() -> True
- carl.legs() -> 2
- carl.speak() -> "Sorry, gotta run"
- carl.mass() -> 180
- pine.name() -> "Pine"
- pine.height() -> 20
- pine.deciduous() -> False
- water.mass() -> 18.01528
- water.symbol() -> "H2O"
- water.name() -> "Water"
- h.name() -> "Hyrdrogen"
- h.mass() -> 1.00794
- kr.mass() -> 83.8
- kr.family() -> "Noble Gas"
- kr.symbol() -> "Kr"
Questions
Answer these questions after you have completed the preceding.
- Describe how your implementation does and does not conform to the
OO paradigm.
- How would you modify your design to better conform to the OO paradigm?
Adam Jonathan Griff,
computer@griffmonster.com
Copyright © University of Colorado. All rights reserved.
Revised: February 1, 1998