Question: #include #include #include #include #include using namespace std; class Animal { public: Animal() { } ~Animal() { } virtual void read(vector ) = 0; virtual

#include

#include

#include

#include

#include

using namespace std;

class Animal

{

public:

Animal()

{

}

~Animal()

{

}

virtual void read(vector) = 0;

virtual void write() = 0;

string getName()

{

return name;

}

string getColor()

{

return color;

}

void setName(string name)

{

this->name = name;

}

void setColor(string color)

{

this->color = color;

}

private:

string name;

string color;

};

class Dog : public Animal

{

private:

string breed;

int age;

double weight;

public:

double subtract10(double weight)

{

if (weight > 10)

return weight - 10;

else

throw exception("Weight can not be negative");

}

void read(vector in)

{

//string name,string color,string breed,int age,double weight

this->setName(in[0]);

this->breed = in[1];

this->age = atoi(in[2].c_str());

this->setColor(in[3]);

this->weight = strtod(in[4].c_str(), NULL);

}

void write()

{

cout << this->getName() << " " << this->breed << " " << this->age << " " << this->getColor() << " " << subtract10(this->weight) << endl;

}

};

class Fish : public Animal

{

private:

string freshwater;

string habitat;

string predator;

public:

void read(vector in)

{

this->setName(in[0]);

this->setColor(in[1]);

this->freshwater = in[2];

this->habitat = in[3];

this->predator = in[4];

}

void write()

{

cout << this->getName() << " " << this->getColor() << " " << this->freshwater << " " << this->habitat << " " << this->predator << endl;

}

};

class Horse : public Animal

{

private:

string maneColor;

int age;

double height;

public:

int add1(double h)

{

height = height + 1;

return height;

}

void read(vector in)

{

this->setName(in[0]);

this->setColor(in[1]);

this->maneColor = in[2];

this->age = atoi(in[3].c_str());

this->height = strtod(in[4].c_str(), NULL);

}

void write()

{

cout << this->getName() << " " << this->getColor() << " " << this->maneColor << " " << this->age << " " << add1(this->height) << endl;

}

};

class Monkey : public Animal

{

private:

int age;

string wild;

string home;

string endangered;

public:

string changeEndangered()

{

if (endangered == "yes")

endangered = "no";

else

endangered = "yes";

return endangered;

}

void read(vector in)

{

this->setName(in[0]);

this->setColor(in[1]);

this->wild = in[3];

this->age = atoi(in[2].c_str());

this->home = in[4];

this->endangered = in[5];

}

void write()

{

cout << this->getName() << " " << this->getColor() << " " << this->age << " " << this->wild << " " << this->home << " " << changeEndangered() << endl;

}

};

class Lizard : public Animal

{

private:

string habitat;

string Isprotected;

double weight;

public:

void read(vector in)

{

this->setName(in[0]);

this->setColor(in[1]);

this->habitat = in[2];

this->Isprotected = in[3];

this->weight = strtod(in[4].c_str(), NULL);

}

void write()

{

cout << this->getName() << " " << this->getColor() << " " << this->habitat << " " << this->Isprotected << " " << this->weight << endl;

}

};

//tokenizer

vector split(const string &s, char delim) {

stringstream ss(s);

string item;

vector tokens;

while (getline(ss, item, delim)) {

tokens.push_back(item);

}

return tokens;

}

int main()

{

string line;

ifstream dog("Dog.txt");

if (dog.is_open())

{

while (getline(dog, line))

{

//cout << line << ' ';

vector tokens = split(line, ', ');

Dog g;

g.read(tokens);

g.write();

}

dog.close();

}

else cout << "Unable to open file";

system("pause");

return 0;

}

Dog.txt: Max, Bulldog, 10, Brindle, 50

This is c++ program, I got some errors on Xcode, Is there someone to help me on this problem?

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!