Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <fstream>
- using namespace std;
- class Animal{
- //Attributes : height weitgh variablees
- //Capabilites : Run Eat function / methods
- private:
- int height;
- int weight;
- string name;
- static int numOfAnimals;
- public:
- int getHeigth(){ return heigth; }
- int getWeigth(){ return weight; }
- string getName(){ return name; }
- void setHeigth(int cm) { height = cm;}
- void setWeigth(int kg) { weight= kg;}
- void setName(string animalName) { name = animalName;}
- void setAll(int, int, string)
- //EXAMPLE OVERLOAD
- Animal(int, int, string);
- ~Animal(); //dESTRUCTOR
- Animal(); //Another constructor
- static int getNumOfAnimals() { return numOfAnimals; }
- void toString();
- };
- int Animal::numOfAnimals = 0;
- void Animal::setAll(int height, int weight, string name){
- this -> height = height;
- this -> weight = weight;
- this -> height = height;
- Animal::numOfAnimals++;
- }
- //Do the same thing from above
- Animal::Animal(int height, int weight, string name)
- {
- this -> height = height;
- this -> weight = weight;
- this -> name = name;
- Animal::numOfAnimals++;
- }
- //Desconstructor
- Animal::~Animal()
- {
- cout << "Animal" << this -> name << "Destroyed" << endl;
- }
- //OVERLOAD
- Animal::Animal()
- {
- Animal::numOfAnimals++;
- }
- void Animal::toString(){
- cout << this -> name << this -> height <<
- "cms tall and " << this -> weight << "kgs in weight" << endl;
- }
- class Dog : public Animal{
- private:
- string sound = "Woof";
- public:
- void getSound(){ cout << sound << endl; }
- Dog(int, int, string, string);
- Dog() : Animal(){};
- void toString();
- };
- Dog::Dog(int height, int weight, string name, string bark) :
- Animal(height, weightm name){
- this -> sound = bark;
- }
- void Dog::toString(){
- cout << this -> getName() << "is" << this -> getHeigth() << "cms tall and " << this -> getWeigth() << "kgs in weight and says " << this -> sound << endl;
- }
- int main(){
- Animal fred;
- fred.setHeigth(33);
- fred.setWeigth(10);
- fred.setName("Fred");
- cout << fred.getName() << " is " << fred.getHeigth() <<
- "cms tall and" << fred.getWeigth() << "kgs n weight" << endl;
- Animal tom(36, 15, "Tom");
- cout << tom.getName() << " is " << tom.getHeigth() <<
- "cms tall and" << tom.getWeigth() << "kgs n weight" << endl;
- Dog spot(38, 16, "Spot", "Woof");
- cout << "Number of Animals << Animal::getNumOfAnimals() << endl;
- spot.getSound();
- tom.toString();
- //Super class
- spot.Animal::toString();
- return 0;
- }
Add Comment
Please, Sign In to add comment