Complete the lab13_ex2_starter.cpp by
1. show on the console the sum of all non-inherited data members of every instance in the program by Display() function.
2. the sum function needs to be a class method and having the same name for different classes, therefore only one external Display() fucntion is required
3. this Display() fucntion needs to be defined externally as a global function, void Display(Base &), that takes any instance of Base class or derived from Base class.
4. Should the sum can not be obtained, explain the reason in the comment.
Starter: lab13_ex2_starter.cpp
Submit: lab13_ex2.cpp
#include
class Base
{
public:
int mPublic;
private:
int mPrivate;
protected:
int mProtected;
public:
int get_mPrivate() {return mPrivate;}
int get_mProtected() {return mProtected;}
Base(int pub, int pri, int pro)
{ mPublic = pub; mPrivate = pri; mProtected = pro; }
};
class Pub: public Base
{
public:
int mPublic;
private:
int mPrivate;
protected:
int mProtected;
public:
int get_mPrivate() {return mPrivate;}
int get_mProtected() {return mProtected;}
Pub(int a, int b, int c, int pub, int pri, int pro) : Base(a, b, c)
{ mPublic = pub; mPrivate = pri; mProtected = pro; }
};
class Pri: private Base
{
public:
int mPublic;
private:
int mPrivate;
protected:
int mProtected;
public:
int get_mPrivate() {return mPrivate;}
int get_mProtected() {return mProtected;}
Pri(int a, int b, int c, int pub, int pri, int pro) : Base(a, b, c)
{ mPublic = pub; mPrivate = pri; mProtected = pro; }
};
class Pro: protected Base
{
public:
int mPublic;
private:
int mPrivate;
protected:
int mProtected;
public:
int get_mPrivate() {return mPrivate;}
int get_mProtected() {return mProtected;}
Pro(int a, int b, int c, int pub, int pri, int pro) : Base(a, b, c)
{ mPublic = pub; mPrivate = pri; mProtected = pro; }
};
int main()
{
Base cBase(1,2,3);
Pub cPub(1,2,3,4,5,6);
Display(cPub);
Display(cBase);
return 0;
}