Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please edit the following C++ code so that the main can return the family, bloodtype and movement type for the animals. Below is my attempt,

Please edit the following C++ code so that the main can return the family, bloodtype and movement type for the animals. Below is my attempt, however I know that it is wrong. Requirements -- must keep the same amount of classes must use header guards in each .h file custom data types not allowed in main //Animals.cpp #include "./Animals.h" /* * Since "Animals" only has pure virtual functions, so this file is empty */ void Animals:: speak() const{ printf("%s the %s says %s ",bloodType.c_str(), movementType.c_str(), familyType.c_str();) } //Animals.h #ifndef CPP_ANIMALS #define CPP_ANIMALS #include  using namespace std; class Animals { string bloodType; // virtual string getBloodType() = 0; string movementType; // virtual string getMovementType() = 0; string familyType; // virtual string getConcreteType() = 0; //prevent construction of base class Animals(){} protected: Animals(const string & b, const string & m,const string & f): bloodType(b),movementType(m), familyType(f){} public: void speak() const; const string & blood() const { return bloodType; } const string & movement() const { return movementType; } const string & family() const { return familyType; } }; #endif //ColdBlooded.cpp #include "./ColdBlooded.h" string ColdBlooded::getBloodType() { return "ColdBlooded"; } //Cold Blooded.h #ifndef CPP_COLDBLOODED #define CPP_COLDBLOODED #include "./Animals.h" class ColdBlooded : public Animals { private: virtual string getBloodType(); }; #endif //Fish.cpp #include "./Fish.h" string Fish::getMovementType() { return "Fish"; } //Fish.h #ifndef CPP_REPTILES #define CPP_REPTILES #include "./ColdBlooded.h" class Fish : public ColdBlooded { private: virtual string getMovementType(); int _petted; public: Fish(string n) : Animal(); }; #endif //main.cpp #include  #include "./Animals.h" #include "Shark.h" #include "Salmon.h" #include "Rabbit.h" int main() { std::cout << "Hello, World!" << std::endl; // I am trying to print out the blood type / movement and family tpe or each object Shark f("Sam"); Fish.bloodType() Fish.movementType() Fish.familyType() Salmon s("George"); Rabbit r("Paul"); return 0; } //Mammals.cpp #include "./Mammals.h" string Mammals::getMovementType() { return "Mammals"; } //Mammals.h #ifndef CPP_MAMMALS #define CPP_MAMMALS #include "./WarmBlooded.h" class Mammals : public WarmBlooded { private: virtual string getMovementType(); }; #endif //Rabbit.cpp #include "./Rabbit.h" string Rabbit::getConcreteType() { return "Rabbit"; } //Rabbit.h #include "./Mammals.h" class Rabbit : public Animals:CPP_MAMMALS { int _jumped; public: Rabbit(string n) : Animal(n,"rabbit","hop"),_jumped(0){}; int jump() { return ++ _jumped} }; //Salmon.cpp #include "./Salmon.h" string Salmon::getConcreteType() { return "Salmon"; } //Salmon.h #include "./Fish.h" class Salmon : public Animals :: class Fish { int _swam; public: Salmon(string n):Animals(n,"salmon","splash"),_swam(0){}; int swim(){ return ++_swam; } }; //Shark.cpp #include "./Shark.h" string Shark::getConcreteType() { return "Sharks"; } //Shark.h class Shark : public Fish { int _swam; public: Shark(string n):Animals(n,"salmon","splash"),_swam(0){}; int swim(){ return ++_swam; } }; //WarmBloooded.cpp string WarmBlooded::getBloodType() { return "WarmBlooded"; } //WarmBlooded.h #include "./Animals.h" class WarmBlooded : public Animals { private: virtual string getBloodType(); }; 

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

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions