Here are my instructions:
Create an “Animal” base class. This class will have size, weight, and eyeColor as instance variables. It will have walk() and print() as methods.
Create a “Dog” class and a “Cat” class. Both these classes will inherit from “Animal”—i.e. “Dog” and “Cat” are subclasses of “Animal.” The “Dog” class will have a bool claws instance variable (the boolean value indicates whether the dog’s claws are clipped or not). The “Dog” class will also have bark() and print() methods. The “Cat” class will have a bool retractableClaws instance variable (the boolean value indicates whether the cat’s class are retracted or not). The “Cat” class will also have meow() and print() methods.
Create two subclasses of “Dog.” Create two subclasses of “Cat.” Each of these subclasses will have an instance variable of your choice. They will also each have a print() method.
Print methods will invoke the print method of their superclass (if any--the top superclass has no superclass), and they will output status information of the instance variables that belong to that particular class.
Constructors will explicitly invoke their superconstructors (if any), and will indicate the class name of that particular class. They will also invoke the print method of that particular class.
Destructors will indicate the class name of that particular class. They will also invoke the print method of that particular class.
This is my code, without the cat part added since it will be pretty much the same as the dog part:
Code:
**Animal.h**
#ifndef ANIMAL_H
#define ANIMAL_H
#include "stdafx.h"
#include <string>
using std::string;
class Animal
{
public:
Animal( const string &, const string &, const string & );
~Animal();
void setSize( const string &);
string getSize() const;
void setWeight( const string &);
string getWeight() const;
void setEyeColor( const string &);
string getEyeColor() const;
void print() const;
void walk() const;
private:
string Size;
string Weight;
string EyeColor;
};
#endif
Code:
**Animal.cpp**
#include <iostream>
using std::cout:
using std::endl;
#include "stdafx.h"
#include "Animal.h"
Animal::Animal( const string &size, const string &weight, const string &eyecolor)
: size( size ), weight( weight ), eyeColor( eyecolor )
{
cout << "Animal Constructor: "<< endl;
print();
cout <<"\n\n";
}
void Animal::setSize ( const string &size )
{
Size = size;
}
string Animal::getSize() const
{
return Size;
}
void Animal::setWeight( const string &weight)
{
Weight = weight;
}
string Animal::getWeight() const
{
return Weight;
}
void Animal::setEyeColor( const string &eyecolor)
{
EyeColor = eyecolor;
}
string Animal::getEyeColor() const
{
return EyeColor;
}
void Animal::print() const
{
cout << "Animal: "
<< "\nSize: " << getSize()
<< "\nWeight: " << getWeight()
<< "\nEye Color: " << get EyeColor();
}
Code:
**Dog.h**
#ifndef DOG_H
#define DOG_H
#include "stdafx.h"
#include <string>
using std::string;
#include "Animal.h"
class Dog : public Animal
{
public:
Dog ( const string &, const string &, const string &, const string & );
~Dog();
void setClaws( const string &);
string getClaws() const;
private:
string Claws;
void print() const;
void walk() const;
};
#endif
Code:
**Dog.cpp**
#include <iostream>
using std::cout:
using std::endl;
#include "stdafx.h"
#include "Dog.h"
Dog::Dog( const string &size, const string &weight, const string &eyecolor, const string &claws)
:Animal ( size, weight, eyecolor )
set Claws
Dog::~Dog()
{
cout << "Dog destructor: " << endl;
print();
cout << "\n\n";
}
Code:
**main.cpp**
#include <iostream>
using std::cout;
using std::endl;
using std::fixed;
#include <iomanip>
#include "Animal.h"
int main()
{
{
Dog dog1(
"Big", "140", "Brown", "0");
}
cout << endl;
{
Dog dog2(
"Small", "20", "Hazel", "1");
}
cout << endl;
return 0;
}
How do I make this work!?!?!?!
Thanks