Please submit the following files for this assignment:
**************************Animal.h, Animal.cpp, Mammal.h, Mammal.cpp, Cat.h, Cat.cpp, main.cpp********************************************************
Assignment 4 – OOP – inheritances
Member variables (private):
string name;
string type;
Member methods (public):
Constructor(s)
Setters
Getters
eat(); //display “Eat food.”
Member variables (private):
string hair_type; //eg: fur, hair,etc
Member methods (public):
Constructor(s)
Setters
Getters
Member variables:
bool domesticated (private):
Member methods (public):
Constructor(s)
Setters
Getters
Instantiate a Cat object.
Set the following values to each of the member variables
//function overriding
*****************************************************************************************************************************************
************************************************************************************************************************
Key point:
Animal(int m_legs) {legs = m_legs;} //parameterized constructor in the base class Animal
Cat(int m_size,int m_legs):Animal(m_legs) {size = m_size; } //parameterized constructor in the derived class Cat
*****************************************************************************************************************************************************
please use Microsoft Visual Studio
C++
Code To Copy:
Animal.cpp
#include "Animal.h"
#include <string>
#include<iostream>
Animal::Animal(int age, std::string name) : _name(name), _age(age) { }
Animal::~Animal() { }
void Animal::sleep(){ printf("Shhh! %s is sleeping...\n", this->name); }
// Operator overloading
bool Animal::operator==(const Animal &animal){
return (this->age == animal.age()) && (this->name == animal.name());
}
std::ostream &operator<<(std::ostream &o, const Animal &animal){
return o << "Name: " << animal.name() << " Age: " << animal.age();
}
Animal.h
#include <string>
class Animal
{
private:
int _age;
std::string _name;
public:
Animal(int age, std::string name);
~Animal();
void sleep();
int age(void) const { return _age; }
std::string name() const { return _name; }
bool operator==(const Animal &animal); // the other animal
is referenced by "this"
friend std::ostream &operator<<(std::ostream &o,
const Animal &animal)
};
Cat.cpp
#include "Cat.h"
#include <string>
#include <iostream>
Cat::Cat(int age, std::string name, int weight) : Animal::Animal(age, name), _weight(weight) {}
Cat::~Cat()
{
}
void Cat::climb(){
std::cout << this->name() + " is climbing...";
}
std::ostream &operator<<(std::ostream &o, const
Cat cat){
o << (Animal&)cat << " Weight: " <<
cat.weight();
return o;
}
bool Cat::operator==(const Cat &cat){
return (Animal)*this == (Animal)cat && this->weight() ==
cat.weight();
}
Cat.h
#include "Animal.h"
#include <string>
class Cat : public Animal
{
private:
int _weight;
public:
Cat(int age, std::string name, int weight);
~Cat();
int weight() const { return _weight; }
void climb();
bool operator==(const Cat &cat);
friend std::ostream &operator<<(std::ostream &o, const Cat &cat);
};
Dog.cpp
#include "Dog.h"
#include <iostream>
#include <string>
Dog::Dog(int age, std::string name, int numLifes) : Animal::Animal(age, name), _numLifes(numLifes) {}
Dog::~Dog() {};
void Dog::bark()
{ std::cout << ((Animal*)this)->name() + " says: \"ruff, ruff!\""; }
bool Dog::operator==(const Dog &dog){
return (Animal)*this == (Animal)dog && this->numLifes() == dog.numLifes();
}
std::ostream& operator<<(std::ostream &o, const Dog &dog){
o << (Animal)dog << " Number Of Lifes: " << dog.numLifes();
}
Dog.h
#include "Animal.h"
#include <string>
#include <iostream>
class Dog : public Animal{
private:
int _numLifes;
public:
Dog(int age, std::string name, int numLifes);
~Dog();
void bark();
int numLifes() const { return _numLifes; }
bool operator==(const Dog &dog);
friend std::ostream& operator==(std::ofstream& o, const Dog &dog);
};
Screenshots:






Please submit the following files for this assignment: **************************Animal.h, Animal.cpp, Mammal.h, Mammal.cpp, Cat.h, Cat.cpp, main.cpp******************************************************** Assignment...
Please submit the following files for this assignment: *****************Animal.h, Animal.cpp, Mammal.h, Mammal.cpp, Cat.h, Cat.cpp, main.cpp********* Assignment 4 – OOP – inheritances Create a base class Animal (Animal.h, Animal.cpp) Member variables (private): string name; string type; Member methods (public): Constructor(s) Setters Getters eat(); //display “Eat food.” Create a derived class Mammal from Animal (public) (Mammal.h, Mammal.cpp) Member variables (private): string hair_type; //eg: fur, hair,etc Member methods (public): Constructor(s) Setters Getters Create a derived class Cat from Mammal (public) (Cat.h, Cat.cpp) Member...
previous assignment 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...
C++ program to implement inheritance with following requirements, Classes :- Animal.cpp, bird.cpp, canine.cpp, main.cpp (to test it) :- -You may need getters and setters also. 1. Declare and define an animal base class: animal stores an age (int), a unique long ID (a boolean that is true if it is alive, and a location (a pair of double). animal requires a default constructor and a 3 parameter constructor. Both constructors should set the unique ID automatically. They should also set...
Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a new method called displayAll, that takes an ArrayList (of your base class) as a parameter, and doesn't return anything [25 pts] The displayAll method will loop through the ArrayList, and call the display (or toString) method on each object [25 pts] In the main method, create an ArrayList containing objects of both your base class and subclass. (You should have at least 4 objects) [25...
Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a new method called displayAll, that takes an ArrayList (of your base class) as a parameter, and doesn't return anything [25 pts] The displayAll method will loop through the ArrayList, and call the display (or toString) method on each object [25 pts] In the main method, create an ArrayList containing objects of both your base class and subclass. (You should have at least 4 objects) [25...
PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1. What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** * Program: PRG/421 Week 1 Analyze Assignment * Purpose: Analyze the coding for...
Hi, the language is Java.
Learning Outcomes and Introduction In this lab assignment you will practice: . applying access modifiers using getters and setters to mediate access using getters and setters to create derived attributes using static variables and methods testing code using a unit testing approach . For each of the tasks in this lab, you will create a new class or create an improved version of one of the classes from the previous lab. Remember to document all...
Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...
Create a C++ project with 2 classes, Person and Birthdate. The description for each class is shown below: Birthdate class: private members: year, month and day public members: copy constructor, 3 arguments constructor, destructor, setters, getters and age (this function should return the age) Person class: private members: firstName, lastName, dateOfBirth, SSN public members: 4 arguments constructor (firstName, lastName, datOfBirth and SNN), destructor and printout Implementation: - use the separated files approach - implement all the methods for the 2...