vendredi 23 août 2019

Get a random Struct object from a vector of Struct objects

i am currently working on a school program. I have 3 structs, student, subject and teacher.

What i want to happen is if a student is taking a subject then a teacher who can teach that subject is randomly allocated to it (The subject has a Teacher data member)

But what i am having the most trouble with is getting a random teacher from the vector of teachers who can teacher the subject. I would like to use the default_random_engine if possible ?

vector<Teacher>canTeachArchery;
vector<Teacher>canTeachBasicBouncing;
vector<Teacher>canTeachCountingForAnimals;

default_random_engine randTeacher;

//read from list of students
for(auto &s : studentList)
    {
//loop nested vector of subjects they have to take(int)
        for(int sb : s.subjectList)
        {
            if(sb == 1)
            {
                //assign random teacher here
            }
        }
    }






Aucun commentaire:

Enregistrer un commentaire