Please submit at least the following files:
Animal.h, Mammal.h, Cat.h, Owner.h, main.cpp.
If you created method definition files, please submit them as well, such as:
Animal.cpp, Mammal.cpp, Cat.cpp, and Owner.cpp (if there are not any complex member method, you may use inline definition and may not need to create the definition file.)
_____________________________________________________________________________________________________________________________________________________
Based on your previous assignment code, you will be adding an additional class Owner.
*Previous code is on the bottom*
private member variables --
string name;
string address;
//we can have more attributes…but let’s keep things simple
public member methods --
constructors (default, parameterized)
setters and getters
//You many create any additional member method(s) to your design need.
private member variables --
//add the following data member to Cat class
Owner master;
public member methods --
//update or add the following related methods to the class
constructors
setters and getters
Cat orderCat(Owner master); // in this function, you should ask the owner, the input her criteria to choose a pet cat such as name, type, hair_type. The domesticated attribute should be set to true. Then return the Cat object.
Do whatever you feel suitable in testing and illustrating your program, such as create an Owner object and then create a Cat object via orderCat() function.
_____________________________________________________________________________________________________________________________________________________
Previous Code:
/*C++ test program to test the classes, Animal, Mammal and Cat
and print the results on console window.*/
//Main.cpp
//include header files
#include<iostream>
//include Animal, Mammal and Cat header files
#include "Animal.h"
#include "Mammal.h"
#include "Cat.h"
using namespace std;
int main()
{
//create Animal object
Animal animal("Dog","Mammal",4);
cout<<"Animal object details"<<endl;
cout<<"Name:
"<<animal.getName()<<endl;
cout<<"Type:
"<<animal.getType()<<endl;
cout<<"# of Legs:
"<<animal.getLegs()<<endl;
cout<<endl<<endl;
//create Cat object
Cat cat("byssinian cat","carnivorous mammal",4,"short
hair",true);
cout<<"Cat object details"<<endl;
cout<<"name:
"<<cat.getName()<<endl;
cout<<"type:
"<<cat.getType()<<endl;
cout<<"hair_type
"<<cat.getHairType()<<endl;
cout<<"domesticated:
"<<cat.getDomestic()<<endl;
cat.eat();
system("pause");
return 0;
}
--------------------------------------------------------------------------------------------------------------
//Animal.h
#ifndef ANIMAL_H
#define ANIMAL_H
#include<iostream>
#include<string>
using namespace std;
class Animal
{
private:
string name;
string type;
int m_legs;
public:
Animal(string,string,int);
void setName(string);
string getName();
void setType(string);
string getType();
void setLegs(int);
int getLegs();
virtual void eat();
};
#endif ANIMAL_H
--------------------------------------------------------------------------------------------------------------
//Animal.cpp
#include<iostream>
#include "Animal.h"
using namespace std;
Animal::Animal(string name ,string type ,int m_legs)
{
this->name=name;
this->type=type;
this->m_legs=m_legs;
}
void Animal::setName(string name)
{
this->name=name;
}
string Animal::getName()
{
return name;
}
void Animal::setType(string)
{
this->type=type;
}
string Animal::getType()
{
return type;
}
void Animal::setLegs(int m_legs)
{
this->m_legs=m_legs;
}
int Animal::getLegs()
{
return m_legs;
}
void Animal::eat()
{
cout<<"Eat food."<<endl;
}
--------------------------------------------------------------------------------------------------------------
//Mammal.h
#ifndef MAMMAL_H
#define MAMMAL_H
#include<iostream>
#include<string>
#include "Animal.h"
using namespace std;
class Mammal : public Animal
{
private:
string name;
string type;
int m_legs;
string hariType;
public:
Mammal(string,string,int, string hairType);
void setHairType(string);
string getHairType();
virtual void eat()=0;
};
#endif MAMMAL_H
--------------------------------------------------------------------------------------------------------------
//Mammal.cpp
#include<iostream>
#include "Mammal.h"
#include "Animal.h"
using namespace std;
Mammal::Mammal(string name ,string type ,int m_legs,
string hairType) :Animal(name,type,m_legs)
{
this->hariType=hairType;
}
void Mammal::setHairType(string hairType)
{
this->hariType=hairType;
}
string Mammal::getHairType()
{
return hariType;
}
void Mammal::eat()
{
cout<<"Eat wide range of
food."<<endl;
}
--------------------------------------------------------------------------------------------------------------
//Cat.h
#ifndef CAT_H
#define CAT_H
#include<iostream>
#include<string>
#include "Mammal.h"
using namespace std;
class Cat : public Mammal
{
private:
string name;
string type;
int m_legs;
bool domesticated;
public:
Cat(string,string,int, string, bool );
void setDemostic(bool);
bool getDomestic();
virtual void eat();
};
#endif CAT_H
--------------------------------------------------------------------------------------------------------------
//Cat.cpp
#include<iostream>
#include "Cat.h"
#include "Mammal.h"
using namespace std;
Cat::Cat(string name,string type, int legs, string hairType,
bool domesticated)
:Mammal(name,type,m_legs,hairType)
{
this->domesticated=domesticated;
}
void Cat::setDemostic(bool hairType)
{
this->domesticated=domesticated;
}
bool Cat::getDomestic()
{
return domesticated;
}
void Cat::eat()
{
cout<<"eat fish."<<endl;
}
--------------------------------------------------------------------------------------------------------------
_____________________________________________________________________________________________________________________________________________________
C++
using Microsoft Visual Studio
//Animal.h
#ifndef ANIMAL_H
#define ANIMAL_H
#include<iostream>
#include<string>
using namespace std;
class Animal
{
private:
string name;
string type;
int m_legs;
public:
Animal(string,string,int);
void setName(string);
string getName();
void setType(string);
string getType();
void setLegs(int);
int getLegs();
virtual void eat();
};
#endif ANIMAL_H
--------------------------------------------------------------------------------------------------------------
//Animal.cpp
#include<iostream>
#include "Animal.h"
using namespace std;
Animal::Animal(string name ,string type ,int m_legs)
{
this->name=name;
this->type=type;
this->m_legs=m_legs;
}
void Animal::setName(string name)
{
this->name=name;
}
string Animal::getName()
{
return name;
}
void Animal::setType(string)
{
this->type=type;
}
string Animal::getType()
{
return type;
}
void Animal::setLegs(int m_legs)
{
this->m_legs=m_legs;
}
int Animal::getLegs()
{
return m_legs;
}
void Animal::eat()
{
cout<<"Eat food."<<endl;
}
---------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
//Mammal.h
#ifndef MAMMAL_H
#define MAMMAL_H
#include<iostream>
#include<string>
#include "Animal.h"
using namespace std;
class Mammal : public Animal
{
private:
string name;
string type;
int m_legs;
string hariType;
public:
Mammal(string,string,int, string hairType);
void setHairType(string);
string getHairType();
virtual void eat()=0;
};
#endif MAMMAL_H
--------------------------------------------------------------------------------------------------------------
//Mammal.cpp
#include<iostream>
#include "Mammal.h"
#include "Animal.h"
using namespace std;
Mammal::Mammal(string name ,string type ,int m_legs,
string hairType) :Animal(name,type,m_legs)
{
this->hariType=hairType;
}
void Mammal::setHairType(string hairType)
{
this->hariType=hairType;
}
string Mammal::getHairType()
{
return hariType;
}
void Mammal::eat()
{
cout<<"Eat wide range of food."<<endl;
}
--------------------------------------------------------------------------------------------------------------
//Cat.h
#ifndef CAT_H
#define CAT_H
#include<iostream>
#include<string>
#include "Mammal.h"
#include "Owner.h"
using namespace std;
class Cat : public Mammal
{
private:
string name;
string type;
int m_legs;
bool domesticated;
Owner master;
public:
Cat(string,string,int, string, bool );
void setDemostic(bool);
bool getDomestic();
virtual void eat();
Cat orderCat(Owner master);
};
#endif CAT_H
--------------------------------------------------------------------------------------------------------------
//Cat.cpp
#include<iostream>
#include "Cat.h"
#include "Mammal.h"
#include "Owner.h"
using namespace std;
Cat::Cat(string name,string type, int legs, string hairType,
bool domesticated) :Mammal(name,type,m_legs,hairType)
{
this->domesticated=domesticated;
}
void Cat::setDemostic(bool hairType)
{
this->domesticated=domesticated;
}
bool Cat::getDomestic()
{
return domesticated;
}
void Cat::eat()
{
cout<<"eat fish."<<endl;
}
Cat Cat::orderCat(Owner master)
{
Cat cat("catty","small",4,"curly","true");
Owner master("Harry","Newyork");
this->domesticated=true;
master.addAnimal(cat);
return cat;
}
//Owner.h
#ifndef OWNER_H
#define OWNER_H
#include<iostream>
#include<string>
using namespace std;
class Owner
{
private:
string name;
string address;
Animal *animals;
public:
owner();
Owner(string,string);
void setName(string);
string getName();
void setAddress(string);
string getAddress();
void addAnimal();
};
#endif OWNER_H
--------------------------------------------------------------------------------------------------------------
//Owner.cpp
#include<iostream>
#include "Owner.h"
using namespace std;
Owner::Owner()
{
cout<<"Owner default constructor"<<endl;
animals = new Animal[3];
}
Owner::Owner(string name ,string address)
{
this->name=name;
this->address=address;
}
void Owner::setName(string name)
{
this->name=name;
}
string Owner::getName()
{
return name;
}
void Owner::setAddress(string address)
{
this->address=address;
}
string Owner::getAddress()
{
return address;
}
void Owner::addAnimal(Cat &c){
Animal animals=c;
}
void Owner::showAllAnimals()
{
for(int i=0;i<size;i++)
{
cout << animals[i].toString()
<< endl;
}
//prints out all items on the list.
}
------------------------------------------------------------------------------------
//include header files
#include<iostream>
//include Animal, Mammal and Cat header files
#include "Animal.h"
#include "Mammal.h"
#include "owner.h"
#include "Cat.h"
using namespace std;
int main()
{
//create Animal object
Animal animal("Dog","Mammal",4);
cout<<"Animal object details"<<endl;
cout<<"Name: "<<animal.getName()<<endl;
cout<<"Type: "<<animal.getType()<<endl;
cout<<"# of Legs:
"<<animal.getLegs()<<endl;
cout<<endl<<endl;
//create Cat object
Cat cat("byssinian cat","carnivorous mammal",4,"short
hair",true);
cout<<"Cat object details"<<endl;
cout<<"name: "<<cat.getName()<<endl;
cout<<"type: "<<cat.getType()<<endl;
cout<<"hair_type
"<<cat.getHairType()<<endl;
cout<<"domesticated:
"<<cat.getDomestic()<<endl;
Owner master("Harry","Newyork");
cout<<"order cat :"<<cat.orderCat(master)<<"
"<<"show All Animals that a owner have
:"<<cat.showAllAnimals()<<endl;
cat.eat();
system("pause");
return 0;
}
Please submit at least the following files: Animal.h, Mammal.h, Cat.h, Owner.h, main.cpp. If you created method...