Skip to content

Instantly share code, notes, and snippets.

@someshinyobject
Created July 17, 2014 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save someshinyobject/ef32bffdb5edc1fe5af5 to your computer and use it in GitHub Desktop.
Save someshinyobject/ef32bffdb5edc1fe5af5 to your computer and use it in GitHub Desktop.
Discussion 7 for CMIS315
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Animal {
public:
Animal() {};
Animal(string n) : name(n) {};
~Animal() {};
string getName() {
return name;
}
private:
string name;
};
class Bird : public Animal{
public:
Bird() {};
Bird(string n, string t, string l, bool cf) : Animal(n), type (t), livesIn (l), canFly (cf) {};
string getType() {
return type;
}
string whereDoILive() {
return livesIn;
}
bool canIFly() {
return canFly;
}
private:
bool canFly;
string livesIn;
string type;
static bool const hasFeathers = true;
};
class Penguin : public Bird {
public:
Penguin(string n) : Bird(n, "penguin", "arctic regions", false) {};
~Penguin();
};
class Toucan : public Bird {
public:
Toucan(string n) : Bird(n, "toucan", "tropical regions", true) {};
~Toucan();
};
int main() {
vector<Bird *> birds;
vector<Bird *>::iterator bIT;
birds.push_back(new Toucan("Betty"));
birds.push_back(new Penguin("Carl"));
for ( bIT = birds.begin(); bIT != birds.end(); bIT++ ) {
Bird *b = (*bIT);
cout << "In our bird habitat we see " << b->getName() << endl;
cout << b->getName() << " is a " << b->getType() << endl;
cout << b->getType() << "s come from " << b->whereDoILive() << endl;
if ( b->canIFly() ) {
cout << b->getName() << " is capable of flying." << endl;
} else {
cout << b->getName() << " cannot fly." << endl;
}
}
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment