Kimossab

Testes blablabla

Jun 8th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.50 KB | None | 0 0
  1. Aluno *AdicionarTeste(Disciplina *D, Aluno *A, int dif, int np, int nr, int *vp)
  2. {
  3.     A->teste = CNP();
  4.     NPerguntas *N, *T = A->teste;
  5.     A->teste->Info->LRespostas->Nel = nr;
  6.     A->teste->Info->LRespostas->Inicio = CNR();
  7.     NRespostas *NR, *R = A->teste->Info->LRespostas->Inicio;
  8.     int *vr = (int *)malloc(sizeof(int)*nr), numres;
  9.  
  10.     for(int n=0; n<np; n++) // cilco para percorrer o vetor
  11.     {
  12.         N = D->lp->Hash[dif-1]; // reinicia o no
  13.         for(int i=1; i<=D->lp->Nel[dif-1]; i++) //ciclo para percorrer a lista
  14.         {
  15.             if(vp[n] == i) // Se esta pergunta estiver na posicção n adiciona-se à lista do aluno e para-se o ciclo
  16.             {
  17.                 sprintf(T->Info->Codigo, "%s", N->Info->Codigo);
  18.                 sprintf(T->Info->Enunciado, "%s", N->Info->Enunciado);
  19.                 numres = BuscarRespostasTeste(N->Info->LRespostas, nr, vr);
  20.                 for(int r=0; r<numres; r++) // cilco para percorrer o vetor
  21.                 {
  22.                     NR = N->Info->LRespostas->Inicio; // reinicia o no
  23.                     for(int ir=1; ir <= N->Info->LRespostas->Nel; ir++) // ciclo para percorrer a lista
  24.                     {
  25.                         if(vr[r] == ir) //se for esta a resposta na posiçao r adiciona-se e pára-se o ciclo
  26.                         {
  27.                             if(r != 0)
  28.                             {  
  29.                                 R->prox = CNR();
  30.                                 R=R->prox;
  31.                             }
  32.                             sprintf(R->Info->Codigo, "%s", NR->Info->Codigo);
  33.                             sprintf(R->Info->Resp, "%s", NR->Info->Resp);
  34.                             break;
  35.                         }
  36.                         NR = NR->prox;
  37.                     }
  38.                 }
  39.                 T->prox = CNP();
  40.                 T = T->prox;
  41.                 break;
  42.             }
  43.             N=N->prox;
  44.         }
  45.     }
  46.     return A;
  47. }
  48.  
  49.  
  50. void FazerTeste(Aluno *A, int np)
  51. {
  52.     system("cls");
  53.     NPerguntas *N = A->teste;
  54.     NRespostas *R;
  55.     A->resp = (int *)malloc(sizeof(int)*np);
  56.     printf("=========================================================\n");
  57.     for(int i=0; i < np; i++)
  58.     {
  59.         printf("%d. %s\n", i+1, N->Info->Enunciado);
  60.         R = N->Info->LRespostas->Inicio;
  61.         for(int n=0; n < N->Info->LRespostas->Nel; n++)
  62.         {
  63.             if(!R)
  64.                 break;
  65.             printf("\t%c) %s\n", n+97, R->Info->Resp);
  66.             R = R->prox;
  67.         }
  68.         printf("\nSua Resposta: ");
  69.         while(1)
  70.         {
  71.             A->resp[i] = getchar();
  72.             if(A->resp[i] < 97 || A->resp[i] > N->Info->LRespostas->Nel+98)
  73.             {
  74.                 printf("\nIntroduziu um caracter que não pertence às respostas!\n");
  75.                 printf("\nSua Resposta: ");
  76.             }
  77.             else break;
  78.         }
  79.     }
  80.  
  81.     //guardar no ficheiro
  82. }
  83.  
  84. int *BuscarPerguntasTeste(LPerguntas *LP, int np, int dif)
  85. {
  86.     int i=0, r;
  87.     bool test = true;
  88.    
  89.     if(np > LP->Nel[dif-1])
  90.         np = LP->Nel[dif-1];
  91.     int *vp = (int *)malloc(sizeof(int)*np);
  92.     while(i < np)
  93.     {
  94.         r = rand()%LP->Nel[dif-1] + 1;
  95.         for(int n=0; n<i; n++)
  96.         {
  97.             if(r == vp[n])
  98.             {
  99.                 test = false;
  100.                 break;
  101.             }
  102.         }
  103.         if(test == true)
  104.         {
  105.             vp[i] = r;
  106.             i++;
  107.         }
  108.         else test = true;
  109.     }
  110.     return vp;
  111. }
  112.  
  113. int BuscarRespostasTeste(ListaRespostas *LR, int nr, int *vr)
  114. {
  115.     int i=0, r, n;
  116.     bool test = true, test2 = false;
  117.  
  118.     if(nr > LR->Nel) // caso o "default" de numero de respostas seja maior do que as houver...
  119.     {
  120.         nr = LR->Nel; // o nr será esse maximo
  121.         vr = (int *)realloc(vr, sizeof(int)*nr);
  122.     }
  123.  
  124.     while(i < nr) // escolhe a posição onde colocar o valor no vetor
  125.     {
  126.         if(i == nr-1) // se estivermos na ultima posição
  127.             test2 = true; // ativa a "flag"
  128.         r = rand()%nr + 1;
  129.         if(r == 1 && test2) // se o r for 1 E a flag estiver ativa remove-se-a
  130.             test2 = false;
  131.         n=0;
  132.         while(n<i) // pesquisa o vetor
  133.         {
  134.             if(!test2) // caso nao seja o ultimo ou o r é 1
  135.             {
  136.                 if(r == vr[n])
  137.                 {
  138.                     test = false;
  139.                     break;
  140.                 }
  141.             }
  142.             else // verifica se a resposta 1 está incluida
  143.             {
  144.                 if(1 == vr[n])
  145.                 {
  146.                     test2 = false; //se estiver remove-se a "flag"
  147.                     n = -1; // n fica a -1 para poder passar de novo no ciclo a começar em 0 para verificar se o r existe
  148.                 }
  149.             }
  150.             n++;
  151.         }
  152.         if(test2) // caso a flag esteja ativa então a ultima fica com o valor 1
  153.         {
  154.             vr[n-1] = 1;
  155.         }
  156.         else
  157.         {
  158.             if(test)
  159.             {
  160.                 vr[i] = r;
  161.                 i++;
  162.             }
  163.             else test = true;
  164.         }
  165.     }
  166.     return nr;
  167. }
  168.  
  169. void RandomTest(Aluno *A, Disciplina *D)
  170. {
  171.     if(!D->lp)
  172.     {
  173.         printf("Lista de Perguntas inexistente!");
  174.         return;
  175.     }
  176.  
  177.     for(int i=0; i<4; i++)
  178.     {
  179.         if(D->lp->Hash[i])
  180.             break;
  181.         if(i == 3)
  182.         {
  183.             printf("Perguntas inexistentes!");
  184.             return;
  185.         }
  186.     }
  187.  
  188.     int np, nr, dif;
  189.     do
  190.     {
  191.         dif = rand() % 4 + 1; // 1-4
  192.     }while(D->lp->Nel[dif-1] == 0);
  193.     np = rand()%(D->lp->Nel[dif-1]) + 1; // 1 - NEL
  194.     nr = rand()%12 + 4; // 4 - 15
  195.    
  196.     NPerguntas *N = D->lp->Hash[dif-1];
  197.  
  198.     int *vp = BuscarPerguntasTeste(D->lp, np, dif);
  199.     A = AdicionarTeste(D, A, dif, np, nr, vp);
  200.     FazerTeste(A, np);
  201. }
Advertisement
Add Comment
Please, Sign In to add comment