# f09final - EECS 280 Fall 2009 Final Exam This is a...

This preview shows pages 1–4. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Uniqname: ________________________ EECS 280 – Programming and Elementary Data Structures Page 2 of 15 Question 1 – Classes In this question, you will be asked to state properties about the following classes: class Pet { char name[50]; public: virtual int train(char * x, int y, char * z[]) = 0; }; class Dog : public Pet { protected: int bark; public: int train(char * x, int y, char * z[]); // REQUIRES: x is a valid C-String and y is a positive integer. // z points to an array of valid C-Strings // EFFECTS: returns how long it will take to train the dog named // x a total of y tricks. virtual int learn_trick(Pet & p); // EFFECTS: returns how long it takes p to learn a “trick” }; class BadDog {}; class Collie : public Dog { int big; public: int train(char * x, int y, char * z[]); // REQUIRES: y is a positive integer. // z points to an array of valid C-Strings // EFFECTS: throws BadDog if x is not a valid C-String or x // does not appear in array z. Otherwise, returns the // number of weeks it will take to train the dog named // x a total of y tricks char * longerName(char * x, char * y); // REQUIRES: x and y are both valid C-Strings // EFFECTS: Returns x if x contains more characters than // y, returns y otherwise. }; class Sheltie : public Dog { private: int small; public: int learn_trick(Pet & p) { return Dog::learn_trick(p); } };
Uniqname: ________________________ EECS 280 – Programming and Elementary Data Structures Page 3 of 15 1.a Subtypes Is Collie a subtype of Dog ? Why or why not? Put your answer in the box below: Is Sheltie a subtype of Dog ? Why or why not? Put your answer in the box below: 1.b Visibility Assume the following four statements are added to the method Sheltie::learn_trick() : a) big = 1337; b) small = 10; c) bark = small; d) cout << name << “ is a good dog!” << endl; For each statement, state whether or not the statement will produce a compiler error when the program is

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 12/14/2010 for the course EECS 280 taught by Professor Noble during the Fall '08 term at University of Michigan.

### Page1 / 15

f09final - EECS 280 Fall 2009 Final Exam This is a...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online