My professor assigned a lab with the following requirements: Requirements
Now, I thought simple enough Ill make several derived classes from one to show the inheritance of the private, public, and protected data. Apon asking for clarification that this is what I was supposed to do I was told to use only a single class.
I then wrote this, which he O-K as the solution but its been bugging me because this just uses the public to access all the variables with a string argument(the string streams are returned because of some lab rules):
class cls {
public:
stringstream ss;
int data[4] = { 1,2,3,4 };
void print(int d[]) {
for (int i = 0; i < 4; i++)
ss << i << ',';
}
string pass(string s) {
if (s == "A") {
print(data);
print(pdata);
print(prdata);
}
else if(s=="B"){
print(pdata);
print(prdata);
}else if(s=="C"){
print(prdata);
}
return ss.str();
}
protected:
int pdata[4] = { 10,20,30,40 };
private:
int prdata[4] = { 100,200,300,400 };
};
How is that the solution to the lab? With my understanding of access modifiers, it isn't using any?