Question
4-1 Define and implement a class named sort_by_animalID that has a single public static function but no constructors: static void sort(animal **animals,int n) // sorts
4-1
Define and implement a class named sort_by_animalID that has a single public static function but no constructors:
static void sort(animal **animals,int n) // sorts the array of n animals into ascending order using their animalIDs
You may use your favourite sorting algorithm.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
animal.h file:
#ifndef ANIMAL_H
#define ANIMAL_H
#include
class animal {
protected:
std::string name ; // the animal's name
static int count;
int animalID ; // the animal's unique ID
int volume ; // the volume of the animal's body
public:
animal();
animal(std::string n, int v) ; // creates an animal with name n and body volume v.
// animals are allocated a unique ID on creation
void set_name(std::string n);
void set_volume(int v);
virtual std::string get_name() = 0;
int get_animalID();
int get_volume();
};
#endif
/////////////////////////////////////////////////////////////////
use this animal.h file to solve the question above.
I would like you to display the code for the sort_by_animalID.h file, sort_by_animalID.cpp file, and the main.cpp file.
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