I keep getting these errors when I run the code below
I keep getting these errors when I run the code below:
____animal.cpp_______
#include "animal.h"
Animal::Animal()
{
}
Animal::Animal(string name,string gender, string color, double weight)
{
this->name = name;
this->gender = gender;
this->color = color;
this->weight = weight;
}
void Animal::PrintInfo()
{
cout<<"Name : "<<name<<endl;
cout<<"Gender : "<<gender<<endl;
cout<<"Color : "<<color<<endl;
cout<<"Weight : "<<weight<<endl;
}
__animal.h___
#ifndef __ANIMAL_H
#define __ANIMAL_H
#include<iostream>
using namespace std;
class Animal
{
private:
double weight;
string name;
string gender;
string color;
public:
Animal();
Animal(string,string , string, double);
virtual void PrintInfo();
};
#endif
___horse.h___
#ifndef __HORSE_H
#define __HORSE_H
#include "animal.h"
class Horse : public Animal
{
private:
string breed;
int id;
string comments;
public:
Horse();
Horse(string,double,string,string,int,string,string);
void PrintInfo();
};
#endif
____horse.cpp____
#include "horse.h"
Horse::Horse()
{
}
Horse::Horse(string breed, double weight , string name ,string gender, int id, string color , string comments):Animal(name,gender,color,weight)
{
this->breed = breed;
this->id = id;
this->comments = comments;
}
void Horse::PrintInfo()
{
Animal::PrintInfo();
cout<<"Breed : "<<this->breed<<endl;
cout<<"Id : "<<this->id<<endl;
cout<<"Comments : "<<this->comments<<endl;
}
____ horsemain.cpp_____
#include "horse.h"
#include<limits>
#include<cstdlib>
void clearBuffer()
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
}
int main()
{
int size = 5;
Horse *snakes = new Horse[5];
string breed;
double weight;
string name;
string gender;
int id;
string color ;
string comments;
for(int i = 0;i<size;i++)
{
cout<<"\nEnter Breed : ";
getline(cin,breed);
cout<<"Enter Weight : ";
cin >> weight;
clearBuffer();
cout<<"Enter Name : ";
getline(cin,name);
cout<<"Enter Gender : ";
getline(cin,gender);
cout<<"Enter Id : ";
cin >> id;
clearBuffer();
cout<<"Enter Color : ";
getline(cin,color);
cout<<"Enter Comments : ";
getline(cin,comments);
snakes[i] = Horse(breed,weight,name,gender,id,color,comments);;
}
for(int i = 0;i<size;i++)
{
Animal *animal;
animal = &snakes[i];
cout<<"\n";
animal->PrintInfo();
}
delete[] snakes;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images