Section 14.7. Exercises


14.7. Exercises



Exercise 14-1

Create an abstract Animal class that has private members weight and name , and abstract methods Speak( ) , Move( ) , and ToString( ) . Derive from Animal a Cat and Dog class that override the methods appropriately. Create an Animal array, populate it with Dogs and Cats , and then call each member's overridden virtual method.



Exercise 14-2

Replace the array in Exercise 14-1 with a List . Sort the animals by size . You can simplify by just calling ToString( ) before and after the sort. Remember that you'll need to implement IComparable .



Exercise 14-3

Replace the list from Exercise 14-2 with both a Stack and a Queue , and see the difference in the order in which the animals are returned.



Exercise 14-4

Rewrite Exercise 14-2 to allow Animals to be sorted either by weight or alphabetically by name.



Learning C# 2005
Learning C# 2005: Get Started with C# 2.0 and .NET Programming (2nd Edition)
ISBN: 0596102097
EAN: 2147483647
Year: 2004
Pages: 250

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net