Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c++ 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

In c++

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

animal.cpp file:

#include "animal.h"

#include

int animal::count =1;

animal::animal(){

name ="?";

volume = 0;

}

animal::animal(std::string n, int v) {

name=n;

animalID=count;

count++;

volume=v;

}

void animal::set_name(std::string n){

name=n;

}

void animal::set_volume(int v){

volume=v;

}

// virtual std::string get_name() = 0;

int animal::get_animalID(){

return animalID;

}

int animal::get_volume(){

return volume;

}

image text in transcribed

4-2 Define and implement a class named sort by_name that has a single public static function but no constructors static void sort(animal **animals,int n) using their names // sorts the array of n animals into ascending order You may use your favourite sorting algorithm

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

2. What are some concerns that you need to address?

Answered: 1 week ago