Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Aluno *AdicionarTeste(Disciplina *D, Aluno *A, int dif, int np, int nr, int *vp)
- {
- A->teste = CNP();
- NPerguntas *N, *T = A->teste;
- A->teste->Info->LRespostas->Nel = nr;
- A->teste->Info->LRespostas->Inicio = CNR();
- NRespostas *NR, *R = A->teste->Info->LRespostas->Inicio;
- int *vr = (int *)malloc(sizeof(int)*nr), numres;
- for(int n=0; n<np; n++) // cilco para percorrer o vetor
- {
- N = D->lp->Hash[dif-1]; // reinicia o no
- for(int i=1; i<=D->lp->Nel[dif-1]; i++) //ciclo para percorrer a lista
- {
- if(vp[n] == i) // Se esta pergunta estiver na posicção n adiciona-se à lista do aluno e para-se o ciclo
- {
- sprintf(T->Info->Codigo, "%s", N->Info->Codigo);
- sprintf(T->Info->Enunciado, "%s", N->Info->Enunciado);
- numres = BuscarRespostasTeste(N->Info->LRespostas, nr, vr);
- for(int r=0; r<numres; r++) // cilco para percorrer o vetor
- {
- NR = N->Info->LRespostas->Inicio; // reinicia o no
- for(int ir=1; ir <= N->Info->LRespostas->Nel; ir++) // ciclo para percorrer a lista
- {
- if(vr[r] == ir) //se for esta a resposta na posiçao r adiciona-se e pára-se o ciclo
- {
- if(r != 0)
- {
- R->prox = CNR();
- R=R->prox;
- }
- sprintf(R->Info->Codigo, "%s", NR->Info->Codigo);
- sprintf(R->Info->Resp, "%s", NR->Info->Resp);
- break;
- }
- NR = NR->prox;
- }
- }
- T->prox = CNP();
- T = T->prox;
- break;
- }
- N=N->prox;
- }
- }
- return A;
- }
- void FazerTeste(Aluno *A, int np)
- {
- system("cls");
- NPerguntas *N = A->teste;
- NRespostas *R;
- A->resp = (int *)malloc(sizeof(int)*np);
- printf("=========================================================\n");
- for(int i=0; i < np; i++)
- {
- printf("%d. %s\n", i+1, N->Info->Enunciado);
- R = N->Info->LRespostas->Inicio;
- for(int n=0; n < N->Info->LRespostas->Nel; n++)
- {
- if(!R)
- break;
- printf("\t%c) %s\n", n+97, R->Info->Resp);
- R = R->prox;
- }
- printf("\nSua Resposta: ");
- while(1)
- {
- A->resp[i] = getchar();
- if(A->resp[i] < 97 || A->resp[i] > N->Info->LRespostas->Nel+98)
- {
- printf("\nIntroduziu um caracter que não pertence às respostas!\n");
- printf("\nSua Resposta: ");
- }
- else break;
- }
- }
- //guardar no ficheiro
- }
- int *BuscarPerguntasTeste(LPerguntas *LP, int np, int dif)
- {
- int i=0, r;
- bool test = true;
- if(np > LP->Nel[dif-1])
- np = LP->Nel[dif-1];
- int *vp = (int *)malloc(sizeof(int)*np);
- while(i < np)
- {
- r = rand()%LP->Nel[dif-1] + 1;
- for(int n=0; n<i; n++)
- {
- if(r == vp[n])
- {
- test = false;
- break;
- }
- }
- if(test == true)
- {
- vp[i] = r;
- i++;
- }
- else test = true;
- }
- return vp;
- }
- int BuscarRespostasTeste(ListaRespostas *LR, int nr, int *vr)
- {
- int i=0, r, n;
- bool test = true, test2 = false;
- if(nr > LR->Nel) // caso o "default" de numero de respostas seja maior do que as houver...
- {
- nr = LR->Nel; // o nr será esse maximo
- vr = (int *)realloc(vr, sizeof(int)*nr);
- }
- while(i < nr) // escolhe a posição onde colocar o valor no vetor
- {
- if(i == nr-1) // se estivermos na ultima posição
- test2 = true; // ativa a "flag"
- r = rand()%nr + 1;
- if(r == 1 && test2) // se o r for 1 E a flag estiver ativa remove-se-a
- test2 = false;
- n=0;
- while(n<i) // pesquisa o vetor
- {
- if(!test2) // caso nao seja o ultimo ou o r é 1
- {
- if(r == vr[n])
- {
- test = false;
- break;
- }
- }
- else // verifica se a resposta 1 está incluida
- {
- if(1 == vr[n])
- {
- test2 = false; //se estiver remove-se a "flag"
- n = -1; // n fica a -1 para poder passar de novo no ciclo a começar em 0 para verificar se o r existe
- }
- }
- n++;
- }
- if(test2) // caso a flag esteja ativa então a ultima fica com o valor 1
- {
- vr[n-1] = 1;
- }
- else
- {
- if(test)
- {
- vr[i] = r;
- i++;
- }
- else test = true;
- }
- }
- return nr;
- }
- void RandomTest(Aluno *A, Disciplina *D)
- {
- if(!D->lp)
- {
- printf("Lista de Perguntas inexistente!");
- return;
- }
- for(int i=0; i<4; i++)
- {
- if(D->lp->Hash[i])
- break;
- if(i == 3)
- {
- printf("Perguntas inexistentes!");
- return;
- }
- }
- int np, nr, dif;
- do
- {
- dif = rand() % 4 + 1; // 1-4
- }while(D->lp->Nel[dif-1] == 0);
- np = rand()%(D->lp->Nel[dif-1]) + 1; // 1 - NEL
- nr = rand()%12 + 4; // 4 - 15
- NPerguntas *N = D->lp->Hash[dif-1];
- int *vp = BuscarPerguntasTeste(D->lp, np, dif);
- A = AdicionarTeste(D, A, dif, np, nr, vp);
- FazerTeste(A, np);
- }
Advertisement
Add Comment
Please, Sign In to add comment