Code Development Use the same code that you developed for the magical creatures in the previous assignment #9 and make t

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Code Development Use the same code that you developed for the magical creatures in the previous assignment #9 and make t

Post by answerhappygod »

Code Development Use The Same Code That You Developed For The Magical Creatures In The Previous Assignment 9 And Make T 1
Code Development Use The Same Code That You Developed For The Magical Creatures In The Previous Assignment 9 And Make T 1 (75.99 KiB) Viewed 62 times
Code Development Use The Same Code That You Developed For The Magical Creatures In The Previous Assignment 9 And Make T 2
Code Development Use The Same Code That You Developed For The Magical Creatures In The Previous Assignment 9 And Make T 2 (53.54 KiB) Viewed 62 times
Code Development Use The Same Code That You Developed For The Magical Creatures In The Previous Assignment 9 And Make T 3
Code Development Use The Same Code That You Developed For The Magical Creatures In The Previous Assignment 9 And Make T 3 (24.15 KiB) Viewed 62 times
Code Development Use The Same Code That You Developed For The Magical Creatures In The Previous Assignment 9 And Make T 4
Code Development Use The Same Code That You Developed For The Magical Creatures In The Previous Assignment 9 And Make T 4 (10.39 KiB) Viewed 62 times
Code Development Use The Same Code That You Developed For The Magical Creatures In The Previous Assignment 9 And Make T 5
Code Development Use The Same Code That You Developed For The Magical Creatures In The Previous Assignment 9 And Make T 5 (1.88 KiB) Viewed 62 times
Starter Code
Main.cpp
#include<memory>
#include "Dragon.h"
#include "Elf.h"
#include "Genie.h"
#include "Goblin.h"
//implement printCreature method for printing a creature
//as follows
/*
cout<<endl;
cout << "I am a : " <<
(m)->getType() << endl;
cout << "My name is : "
<< (m)->getName() << endl;
cout << "My color is : "
<< (m)->getColor() << endl;
cout<<"My speech :"<<(m)->talk()<<endl;
cout<<"My habitat:
"<<(m)->liveIn()<<endl;
cout << "I am " <<
(m)->getAge() <<" years of age." <<
endl<<endl;
cout<<"Displaying the "<<(m)->getType()<<"
Object"<<endl;
cout<<m->toString()<<endl;
*/
void
displayCreatures(vector<shared_ptr<MagicalCreatures>>
m){
for ( auto iter = m.begin(); iter < m.end(); iter++)

//printCreature(*iter);
;
}
void swap(vector<shared_ptr<MagicalCreatures>>
&m,int source, int destination){
// use to swap creatures in partition method
}
int partition(vector<shared_ptr<MagicalCreatures>>
&m, int start, int end){
// implement partition search space
}

void
recursiveQuickSort(vector<shared_ptr<MagicalCreatures>>
&m, int start, int end){
//implement recursive Quick sort by calling partition
method
}
int
recursiveBinarySearch(vector<shared_ptr<MagicalCreatures>>
m, int first, int last, string name){
//implement binary search method
}
void
searchCreature(vector<shared_ptr<MagicalCreatures>>
m){
string name;
cout<<"Please enter the name of the
Creature"<<endl;
cin>>name;
int index= recursiveBinarySearch(m,0,m.size()-1,name);
if (index <0)
cout<<"Creature Not Found "<<endl;
else {
cout<<"Creature found at index "<<index
<<endl;
cout<<"Here it is
"<<m[index]->toString()<<endl;
}

}
int main()
{
//create a vector of pointer to MagicalCreatures
vector<shared_ptr<MagicalCreatures>>
creatures;
//create the individual creatures of type pointer
of MagicalCreatures
shared_ptr<Dragon> dragon = make_shared<
Dragon>("Jack","black","Dragon", 200, 500, true);
shared_ptr<Elf> elf =
make_shared<Elf>("Doug", "green", "Elf", 80);
shared_ptr<Genie> genie = make_shared<
Genie>("Cosmo", "blue", "Genie", 1000, 40, true);
shared_ptr<Goblin> goblin =
make_shared<Goblin>("Harry", "red", "Goblin", 150);
//push back each specific creature to the vector of
MagicalCreatures

creatures.push_back(dragon);
creatures.push_back(elf);
creatures.push_back(genie);
creatures.push_back(goblin);
displayCreatures(creatures);
std::cout<<"*****AFTER SORTING
*******"<<std::endl;
recursiveQuickSort(creatures,0,creatures.size()-1);
displayCreatures(creatures);
searchCreature(creatures);
}
Dragon.cpp
#include "Dragon.h"
#include "MagicalCreatures.h"
Dragon::Dragon()
{
size = 0;
hasSpike = true;
}
//constructor using member initializtion list
Dragon::Dragon(string name, string color, string type, int age, int
size, bool hasSpike) : MagicalCreatures(name, color, type,
age)
{
this->size = size;
this->hasSpike = hasSpike;
}
int Dragon::getSize()
{
return size;
}
void Dragon::changeSize(int newSize)
{
this->size = newSize;
}
bool Dragon::getHasSpike()
{
return hasSpike;
}
void Dragon::setHasSpike(bool hasSpike)
{
this->hasSpike = hasSpike;
}
string Dragon::toString()
{
return "I am a Dragon! I breathe fire";
}
Dragon.h
#ifndef Dragon_h
#define Dragon_h
#include "MagicalCreatures.h"
class Dragon : public MagicalCreatures
{
private:
int size;
bool hasSpike;
public:
Dragon();
Dragon(string name,string color,string type, int age,
int size, bool hasSpike);

int getSize();
void changeSize(int newSize);
bool getHasSpike();
void setHasSpike(bool hasSpike);
string toString();
};
#endif
Elf.cpp
#include "Elf.h"
#include "MagicalCreatures.h"
Elf::Elf()
{}
//constructor using member initializtion list
Elf::Elf(string name, string color, string type, int age) :
MagicalCreatures(name, color, type, age)
{}
string Elf::toString(){
return "I am an Elf.... I can spell";
}
Elf.h
#ifndef Elf_h
#define Elf_h
#include "MagicalCreatures.h"
//Elf Class
class Elf : public MagicalCreatures
{
public:
Elf();
Elf(string name, string color, string type, int
age);
string toString();
};
#endif
Genie.cpp
#include "Genie.h"
#include "MagicalCreatures.h"
Genie::Genie()
{
size = 0;
hasWand = true;
}
//constructor using member initializtion list
Genie::Genie(string name, string color, string type, int age, int
size, bool hasWand) : MagicalCreatures(name, color, type,
age)
{
this->size = size;
this->hasWand = hasWand;
}
string Genie::liveIn(){
return "I live in a bottle ";
}
int Genie::getSize()
{
return size;
}
void Genie::changeSize(int newSize)
{
this->size = newSize;
}
bool Genie::getHasWand()
{
return hasWand;
}
void Genie::setHasWand(bool hasWand)
{
this->hasWand = hasWand;
}
Genie.h
#ifndef Genie_h
#define Genie_h
#include "MagicalCreatures.h"
//Genie Class
class Genie : public MagicalCreatures
{
private:
int size;
bool hasWand;
public:
Genie();
Genie(string name, string color, string type, int age,
int size, bool hasWand);
int getSize();
void changeSize(int newSize);
bool getHasWand();
void setHasWand(bool hasWand);
string liveIn();
//void toString();
};
#endif
Goblin.cpp
#include "Goblin.h"
#include "MagicalCreatures.h"
Goblin::Goblin()
{}
//constructor using member initializtion list
Goblin::Goblin(string name, string color, string type, int age) :
MagicalCreatures(name, color, type, age)
{}
string Goblin::talk(){
return "I speak Gibberish";
}
Goblin.h
#ifndef Goblin_h
#define Goblin_h
#include "MagicalCreatures.h"
//Goblin Class
class Goblin : public MagicalCreatures
{
public:
Goblin();
Goblin(string name, string color, string type, int
age);
string talk();
//void toString();

};
#endif
MagicalCreatures.cpp
#include "MagicalCreatures.h"
MagicalCreatures::MagicalCreatures()
{
name = "null";
color = "null";
type = "null";
age = 0;
}
MagicalCreatures::MagicalCreatures(string name, string color,
string type, int age)
{
this->name = name;
this->color = color;
this->type = type;
this->age = age;
}
string MagicalCreatures::talk()
{
return "Magical Creature is talking.";
}
string MagicalCreatures::liveIn()
{
return "Magical Creature lives anywhere.";
}
string MagicalCreatures::getName()
{
return name;
}
void MagicalCreatures::setName(string name)
{
this->name = name;
}
string MagicalCreatures::getColor()
{
return color;
}
void MagicalCreatures::setColor(string color)
{
this->color = color;
}
int MagicalCreatures::getAge()
{
return age;
}
void MagicalCreatures::setAge(int age)
{
this->age = age;
}
string MagicalCreatures::getType()
{
return type;
}
void MagicalCreatures::setType(string type)
{
this->type = type;
}
string MagicalCreatures::toString()
{
string value = "I am a Magical creature ";
value=value.append("\nName : ");
value=value.append(name);
value=value.append("\nType : ");
value=value.append(type);
value=value.append("\nColor : ");
value=value.append(color);
value=value.append("\nAge : ");
value=value.append(to_string(age));
return value;


}
MagicalCreatures.h
#ifndef MagicalCreatures_h
#define MagicalCreatures_h
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//MagicalCreatures Class
class MagicalCreatures
{
private:
string name, color, type;
int age;
public:
MagicalCreatures();
MagicalCreatures(string name, string color, string
type, int age);
virtual string talk();
virtual string liveIn();
virtual string getName();
virtual void setName(string name);
virtual string getColor();
virtual void setColor(string color);
virtual int getAge();
virtual void setAge(int age);
virtual string getType();
virtual void setType(string type);
virtual string toString();
};
#endif
Code Development Use the same code that you developed for the magical creatures in the previous assignment #9 and make the updates that are marked. MagicalCreatureHeader.h // given to you MagicalCreature.cpp // Overload the > and the == operator and use this for the recursive sort and binary search. Upgrade your driver program with two new methods. One for recursive quicksort called recursiveQuickSort() and the other for recursive binary search called recursiveBinarySearch(). Both these methods input a vector of Magical Creatures. You do not need to make any changes to the Classes: They will be given to you in the template and have been designed around the UML's below: Specifications: The template contains comments and notation as to where you need to fill in the code; Magical Creature (Base Class) -string name // name of the creature -string type // type of the creature -string color // color of the creature -int age // age of the creature

+ MagicalCreature) //default constructor that sets name, type.color to "null and age to O +MagicalCreature(string name, string type, string color, int age) // regular constructor +getName(): string // returns the name - can be any fun name +getType: string // returns type (Can be "Dragon", "Genie", "Goblin", "Elf") +getAge: int // returns age. This should be a positive number +setAge(int age): void // can grow older or younger magically! +getColor(): string // returns any color +setColor(string color): void // can change color magically! +talk():string // returns creature speak +liveln():string // return its natural habitat +operator>(MagicalCreature other): bool // returns true if this creature is greater //in age than other // used for recursive sort +operator==(MagicalCreature other): bool // returns true if the name of this is the same as other // used for binary search +toString(): String // return the object description as "Name:" name "Age:" age "Type:" type "Color:" balance

Dragon derived from Magical Creatures -bool hasSpikes // color of the dragon -int size // weight in pounds of the dragon + Dragon() //default constructor that sets name, type,color to "null and age to O + Dragon(string name,string color,string type, int age, int size, bool has Spike); (string name, string type, string color, int age) // regular constructor getSize(): int // get size change Size(int newSize): void // grows big or small! getHasSpike(): bool // set to true setHasSpike(bool hasSpike) // set to true toString():string // returns "I am a Dragon, I breathe fire!" Elf derived from Magical Creatures -int size // weight in pounds of the dragon

+ Elf() //default constructor that sets name, type,color to "null and age to O + Elf(string name,string color,string type, int age); (string name, string type, string color, int age) // regular constructor +toString():string // returns "I am an Elf..I can spell" Goblin derived from Magical Creatures + Goblin () //default constructor that sets name, type.color to "null and age to O + Goblin(string name, string color, string type, int age) // regular +talk():string // returns "I speak Gibberish Genie derived from Magical Creatures -bool hasWand // set to true -int size // weight in pounds of the genie + Geniet) //default constructor that sets name, type.color to "null and age to O +Genie(string name, string color, string type, int age, int size, bool +liveln():string// return "I live in a bottle" getSize(): int;

change Size(int newSize): int getHasWand(): bool setHasWand(bool hasWand):void

I am a : Dragon My name is : Jack My color is : black My speech :Magical Creature is talking. My habitat: Magical Creature lives anywhere. I am 200 years of age. Displaying the Dragon Object I am a Dragon! I breathe fire I am a : Elf My name is : Doug My color is : green My speech :Magical Creature is talking. My habitat: Magical Creature lives anywhere. I am 80 years of age. Displaying the Elf Object I am an Elf.... I can spell I am a : Genie My name is : Cosmo My color is : blue My speech :Magical Creature is talking. My habitat: I live in a bottle I am 1000 years of age. Displaying the Genie Object I am a Magical creature Name : Cosmo Type : Genie Color : blue Age : 1000 I am a : Goblin My name is : Harry My color is : red My speech :I speak Gibberish My habitat: Magical Creature lives anywhere. I am 150 years of age.

Displaying the Goblin Object I am a Magical creature Name : Harry Type : Goblin Color Age : 150 *****AFTER SORTING : red I am a : Genie My name is : Cosmo My color is : blue My speech :Magical Creature is talking. My habitat: I live in a bottle I am 1000 years of age. Displaying the Genie Object I am a Magical creature Name : Cosmo Type : Genie Color : blue Age : 1000 I am a : Elf My name is : Doug My color is : green My speech :Magical Creature is talking. My habitat: Magical Creature lives anywhere. I am 80 years of age. Displaying the Elf Object I am an Elf.... I can spell I am a : Goblin My name is : Harry My color is : red My speech :I speak Gibberish My habitat: Magical Creature lives anywhere. I am 150 years of age. Displaying the Goblin Object I am a Magical creature Name : Harry Type : Goblin Color : red Age : 150

I am a : Dragon My name is : Jack My color is : black My speech :Magical Creature is talking. My habitat: Magical Creature lives anywhere. I am 200 years of age. Displaying the Dragon Object I am a Dragon! I breathe fire Please enter the name of the Creature Harry Creature found at index 2 Here it is I am a Magical creature Name : Harry Type : Goblin Color : red Age : 150 >

Please enter the name of the Creature Frodo Creature Not Found
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply