Let's say there is a base class called Dog with the following attributes and methods.
#pragma once
#include <string>
class CDog
{
protected:
string name;
string breed;
int age;
public:
CDog();
virtual ~CDog();
CDog(string name, string breed, int age);
string getName();
string getBreed();
int getAge();
};
And two derived classes called Puppy and Old;
#pragma once
#include "CDog.h"
class CPuppy: public CDog
{
private:
bool playful;
public:
CPuppy();
~CPuppy();
CPuppy(string name, string breed, int age, bool playful);
bool getPlayful;
};
#pragma once
#include "CDog.h"
class COld: public CDog
{
private:
bool disease;
public:
COld();
~COld();
COld(string name, string breed, int age, bool disease);
bool getDisease;
};
Then, I create a dynamic vector of objects based on the Dog class, so that the user can register as many dogs as he wants. Later on, the user wants to know the average age of all the puppies and all the old dogs. And my question raises here, ¿ How can I get access to the attributes of the Puppey and Old class in the vector in order to generate those reports? I think that there must be an if statement, but I don't know the condition. I hope guys you can help me. I solved this problem using two different dynamic vectors, one for the Puppey class and other for the Old class, but I dont' know if it's possible only with one dynamic vector.