09_Subclasses_Subtypes_and_Virtual_Functions

09_Subclasses_Subtypes_and_Virtual_Functions - Discussion...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: Discussion 9: Subclasses, Subtypes, and Virtual Functions EECS 280 Monday, November 7th, 2011 1 Classes Classes allow for functional abstraction and data encapsulation. They are made up of the following components: • Member Variables • Member Functions • Special Functions 1 int num_teams = 0; 2 3 class Team{ 4 protected: 5 int wins; 6 int losses; 7 string name; 8 void init(int w, int l, string n); 9 10 public: 11 Team(); 12 Team(int w, int l, string n); 13 ∼ Team(); 14 void print(); 15 void defeated(Team &other); 16 }; 17 18 void Team::init(int w, int l, string n){ 19 wins = w; 20 losses = l; 21 name = n; 22 num_teams ++; 1 23 } 24 25 Team::Team(){ 26 init(0, 0, "un-initialized"); 27 } 28 29 Team::Team(int w, int l, string n){ 30 init(w, l, n); 31 } 32 33 Team:: ∼ Team(){ 34 num_teams --; 35 } 36 37 void Team::print() { 38 cout << name << ": " << wins << "-" << losses << endl; 39 } 40 41 void Team:: defeated(Team &other) { 42 wins ++; 43 other.losses ++; 44 } 45 46 int main() { 47...
View Full Document

This note was uploaded on 04/07/2012 for the course EECS 280 taught by Professor Noble during the Fall '08 term at University of Michigan.

Page1 / 6

09_Subclasses_Subtypes_and_Virtual_Functions - Discussion...

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

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