I am trying to write C++ code suitable for object oriented programming.
I have two classes, namely, Student and Course. In the Student class, I have quiz_scores which is a 1-D array of 4 integers. I need both set and get methods, both are used in natural common way.
In the following, I implement setQuizScores method:
void Student :: setQuizScores(int* quizscores){ for(int i = 0; i<4; i++){ quiz_scores[i] = quizscores[i]; } Where quizscores are my private members.
Now, next thing is that I want to return this quiz_scores array in the getQuizScores for each students of Student class.
However, the problem is that C++ does not allow us to return arrays directly. Instead, I want the structure of my code as following:
int Student :: getQuizScores(){ Do something; return the elements of quiz_scores; } How can I do that efficiently?
I prefer not to use the Standard Template Library (STL), so I need to create my own arrays and access them according to the explanation above.
std:::array<int, 4>, then all of those issues go away.struct. In opposition to arrays,structs can be returned by value. (Actually,std::arraydoes nothing else.)intand return the elements of quiz_scores; doesn't go well together.