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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!