Dynamic arrays and pointers problem

If it's not pointer overwriting, then sorry for the incorrect title, but I think it is the case. The thing is: I am working on an exam program in C++ which is based on dynamic arrays (the reason is: I want to be able to enter new questions and answers to them additionaly if I want to). The problem is the following: Let's say we use 2 students and we enter 2 questions and then we start with exam. First student does the exam and the second one also does the exam. Now occurs the problem -> Second student's answers overwrote the first student's answers, so when I try to output the results, it takes last student's results as any other student's.

Since it reached the maximum numbers of characters I could not put it here so I pasted it here: https://paste.ofcode.org/wcfLSPHjDpz4ZVFB74Q2ZA
I can't quite find your problem, there's a lot of stuff there. However, I do have some comments.

Why is _answers a pointer? The single largest area of errors in C and C++ is in pointer management. Just avoid them when you can.
1
2
3
4
5
6
enum answers { CORRECT, INCORRECT };

struct Student {
    //...
    answers *_answers;
};


Similarly, Test::_answers is a pointer. There's no need for that. You have the same problem with Test::_questions. You really ought to use a collection of string for this, a vector, list or deque maybe? Actually, it seems the questions strings and answers enums go together. Why not put them in a struct together, then you can have a single collection of questions and answers.

Use a string class for strings. Again Student::_nameSurname is a character array. You really ought to use a string.

There's a common problem with error handling. Consider student_Recognize(). What happens when it cannot recognize a student? It returns an zero, which is not recognized an an error by its caller.

Similarly, in create_Login, you have exactly the same search, but this time you don't initialize the default, so anything can go wrong if it doesn't match.

I hope this helps.
Thanks for the answer :)

I think I've found the bug but I have no idea at this particular moment how to fix it:
- When I allocated memory in function add_Questions for objects's answers I did it the following way:

for (int i = 0; i < max; i++)
obj[i]._answers = temp_Answers;

which apparently set every object's answers to the same memory location and that's the problem.

Thanks for all other advices, I will try to fix those problems you noticed and I'll accept all your suggestions about using STLs :) The thing is we haven't learned about them yet at Uni at all, but now I see them as a huge advantage so I'll consider learning them on my own. :)
I finally fixed the bug, thanks to the guy kbw for advices :)

Problem was with allocating memory for object's answers
FIX:

for (int i = 0; i < max; i++)
obj[i]._answers = new answers[len];
Topic archived. No new replies allowed.