Question
************Animal.h************ #pragma once #ifndef Animal_h #define Animal_h #endif // !Animal_h class Animal { private: char* name; int age; public: void getName(char * name) const; void
************Animal.h************
#pragma once #ifndef Animal_h #define Animal_h #endif // !Animal_h
class Animal { private: char* name; int age; public: void getName(char * name) const; void setName(char * name); void setAge(int a); int getAge()const; };
*******animals.cpp*******
#include "Animal.h"
#include
#include
using namespace std;
void Animal::setName(char * name)
{
//release the exisisting memory if there is any
if(this->name)
delete [] this->name;
//set new name
this->name = new char[strlen(name)+1];
strcpy(this->name, name);
}
void Animal::getName(char * name) const
{
//returns name
strcpy(name, this->name);
}
void Animal::setAge(int a)
{
age = a;
};
int Animal::getAge()const
{
return age;
};
Create a program which uses the class Animal to Implement the following a. The program will allow the user to 1. Add Animals 2. Delete Animals 3. Display Animals searching by name 4. Display a list of all Animals
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started