lecture33-apr21 - 4/21/10 Lecture 33 Announcements...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
4/21/10 1 Lecture 33 Announcements • Assignment 6 • Assignment 7 – out Friday, due the last day of classes • Topics of the day – More OO – Classes and objects – OO modeling/examples Classes: Dog Example • Suppose you are writing a dog tracking system for owner subscribers: Dog is a real-world class that can be modeled in your program as an ADT – Every class has common associated data, or attributes . • Attributes of interest for the Dog class are: breed, color, height, weight, gender, name, tag# – Every class has common associated actions or behaviors. • Actions of interest for the Dog class are: bark, sleep, eat, locate, . . . • Instances of the Dog class, or objects from the Dog class are specific dog entities: – my dog Bulldozer, your dog X, president Obama's dog Bo Dog as a C++ Class class Dog { public: string breed; string name; double height; double weight; char gender; int tagNumber; /* In order to be able to initialize speci±c Dog instances, or objects of type Dog, we need a constructor function that initially sets the attribute values on creation */ Dog (string theName, char theGender) { name = theName; gender = theGender; } ~Dog ( ) { } /* destructor */ void bark(int n) { cout << name <<‘:’; for (int i =1; i <=n; i++) cout << "rff ” << endl; } void sleep() { cout << name <<‘:’<< "zzzz, zzzz” << endl; } void eat() { cout << name <<‘:’<< "slurp” << endl; } } /* end of Dog class de±nition */ These are the attributes: called member variables or data members (the struct part of the data type) These are the actions: called member functions Here is a constructor Here is the destructor Creating and Using Dog Objects • Now if I'm writing a program, I can create Dog objects: Dog myDog (“Bulldozer”, ‘m’); Dog beckysDog (“Lady Bird”, ‘f’); Dog kelliesDog (“Izzy”, ‘f’); • I can call the public functions that were de±ned in the Dog class to operate on a speci±c Dog object: myDog.bark(2); // output -
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/30/2010 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas at Austin.

Page1 / 4

lecture33-apr21 - 4/21/10 Lecture 33 Announcements...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online