Q2: Continue with Animal class: a) Copy the previous program to a new file. b) Write Constructor with two parameter, and initialize species and age. c) Write default constructor, initialize species to "unknown", age to 0, Implen constructor delegation Use following main() to test your class. int main() { Animal a,b("Dog",10); cout<
help with c++...paste indented code plzz
#include <iostream>
using namespace std;
class Animal
{
private:
string species;
int age;
public:
//Default constructor
Animal()
{
species = "unknown";
age = 0;
}
Animal(string sp, int ag)
{
species = sp;
age = ag;
}
//Setter methods
void setSpecies(string x) { species = x; }
void setAge(int x) { age = x; }
//Setter methods
string getSpecies() { return species; }
int getAge() { return age; }
};
int main()
{
Animal a, b("Dog", 10);
cout<<a.getSpecies()<<endl;
cout<<a.getAge()<<endl;
cout<<b.getSpecies()<<endl;
cout<<b.getAge()<<endl;
return 0;
}
Step by step
Solved in 2 steps with 1 images