1) write a constructor function (not inline) for Square objects. It should take
ID: 3752191 • Letter: 1
Question
1) write a constructor function (not inline) for Square objects. It should take a vector of string tokens as its only parameter. If there are at least 2 tokens, the one at index 1 is the side dimension.
Do not write the prototype -- just the function as it would appear elsewhere in the CPP.
When you write code for an exercise like this, write in "preformatted" instead of the default "paragraph".
2) write a constructor function (not inline) for Square objects. It should take a vector of string tokens as its only parameter. If there are at least 2 tokens, the one at index 1 is the side dimension.
But apply the principle of least privilege. The parameter should be constant, and the side dimension should be a constant data member.
Do not use const_cast . Use an initializer list.
Do not write the prototype -- just the function as it would appear elsewhere in the CPP.
Explanation / Answer
1.
Square::Square(vector<string> token)
{
if(token.size()>=2)
{
dimention=atoi(token.at(1));
}
}
2.
Square::Square(const vector<string> token):dimention(atoi(token.at(1))){}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.