Student Row. Help in structuring the code

3

My question is in case 1 , how to include elements in the queue, in this case, mat and media . Here is the code below:

#include <iostream>
#include <cstdlib>
#define tamanho 20
using namespace std;
struct Aluno{
    int mat;
    float media;
};
struct FILA{
      int inicio;
      int fim;
      int item [tamanho];
}; 
int main(){
    Aluno a;
    FILA f;
    int op;
    cout << "-------------------------------------" << endl;
    cout << "- 1 - Inserir Aluno              ----" << endl;
    cout << "- 2 - Exibir dados do Aluno      ----" << endl;
    cout << "- 3 - Aluno aprovados            ----" << endl;
    cout << "- 4 - Remover Aluno              ----" << endl;
    cout << "- 9 - Sair                       ----" << endl;
    cout << "-------------------------------------" << endl;

    cout << "Selecione a opção desejada: ";
    cin >> op;
    system("cls");
    switch(op){
        case 1:
            system("cls");
            cout<<"\nMatricula: "<<endl;
            cin>>a.mat;
            cout<<"\nMedia: "<<endl;
            a.media;
            enfileira(f, a.mat, a.media);

                break;
        case 9: 
            system("cls");
            cout<<"\nPROGRAMA FINALIZADO !!!"<<endl;
            return 0;


    }
}
void iniciaFila(FILA &f) {
     f.inicio = 0;
     f.fim=f.inicio;
}
bool filaVazia(FILA f){
     return f.fim==0;
}
bool filaCheia(FILA f){
     return f.fim==tamanho;
}
void enfileira(FILA &f, int x){
    if(!filaCheia(f))
       f.item[f.fim++]=x;
    else
       cout<<"fila cheia\n";   
}
void desenfileiraf(FILA &f){
     if(!filaVazia(f)){
        cout<<"desenfileirou "<<f.item[f.inicio]<<endl;
        for(int i=0;i<f.fim-1;i++)
            f.item[i]=f.item[i+1];               
        f.fim--;
     }
     else
        cout<<"fila vazia\n";
} 

int desenfileira(FILA &f){
     if(!filaVazia(f)){
        int n=f.item[f.inicio];
        for(int i=0;i<f.fim-1;i++)
            f.item[i]=f.item[i+1];               
        f.fim--;
        return n;
     }
     cout<<"fila vazia\n";
     return -1; 
} 
void mostra(FILA f){
     if(!filaVazia(f)){
        for(int i=f.inicio;i<f.fim;i++)
              cout<<f.item[i]<<' ';

        cout<<endl;        
     } 
     else
     cout<<"fila vazia\n";
} 

The exercise mainly consists of what the menu asks for.

    
asked by anonymous 13.05.2015 / 20:01

1 answer

1

In your case you would need to modify the structure of the queue to the next.

struct FILA{
  int inicio;
  int fim;
  Aluno aluno[tamanho];
}; 

So you have an array of students where you can add the data. In addition, the queuing function must receive a Student-type data to be inserted in the queue. If you modify the struct and functions correctly I think your code will work.

Another suggestion would be to use the queue data structure that is already present in the C ++ language by default. Take a look at referral and if possible try changing the code it will get much shorter and clearer.

    
13.05.2015 / 22:58