Development of a C++ canteen

Asked

Viewed 85 times

0

I have a university project that I was asked to create a canteen in which I was asked to create groups of students / staff to add to the queue. Groups can have 1 to 10 members . The problem here is to be able to generate these groups. Students are defined by their first name , last name, student number, group number, limit and course; The staff is defined by its first name, last name , department number, employee number and ceiling; Groups can only contain students or staff, not the two mixed.

I created the following structs:

struct identidade {
struct aluno {
    string primeironome;
    string ultimonome;
    int numero;
    string curso;
    float plafond;

};
struct staff {
    string primeironome;
    string ultimonome;
    int numero;
    float plafond;
};

}; struct group { int numerogroup; identity * persons; };

but here the problem is how to create groups, I developed the following function ( I did only for students , for now)

the names of the identities have to be chosen randomly and the courses also.

void criagrupo(grupo * listaespera, string * pNome, string * uNome, string * cursos) {
int i = rand() % 43; // serve para percorrer os arrays com primeiros nomes
int j = rand() % 96; // serve para percorrer os arrays com ultimos nomes
int k = rand() % 18; // server para percorrer os arrays com os cursos
int tamanho = rand() % 10 + 1;
int dinheiro = rand() % 100 + 1;
int numero = rand() % 20 + 1;
grupo * novogrupo = new grupo;
novogrupo->numerogrupo = numero;
identidade * quantidade = new identidade[tamanho];
for (int i = 0; i < tamanho; i++) {
    identidade::aluno * aluno = new identidade::aluno();
    aluno->primeironome = pNome[i];
    aluno->ultimonome = uNome[j];
    aluno->curso = cursos[k];
    aluno->plafond = dinheiro;
    quantidade[i] = aluno;

};

the function is not yet finished but it occurs to me an error in the amount[i] = student, which I am not able to solve. I would appreciate who could help.

1 answer

0

Come on, error is occurring because the types of the variables are different. Quantity is a variable of type identity* and student is a variable identity:student:*. Even though in the statement you have put one in the other, they are different variables.

you have several ways to correct this error. Change the quantity declaration to:

identidade::aluno * quantidade = new identidade::aluno[tamanho];

or change the struct to include the student variable:

struct identidade {
    struct aluno {
        string primeironome;
        string ultimonome;
        int numero;
        string curso;
        float plafond;

    };
    struct staff {
        string primeironome;
        string ultimonome;
        int numero;
        float plafond;
    };

    aluno *alunoExemplo;
}

this way you can access the student so:

quantidade[i].alunoExemplo = aluno

Thus each variable identity has a pointers, one for pupil.

Another way would be for you to implement inheritance using classes. But I don’t know what level of learning you are at. I don’t know if you need to necessarily use C ( I don’t believe it is because you used string, which is not in C.

http://www.cplusplus.com/doc/tutorial/classes/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.