Advertisement
Hayjerin

lista7 strings

May 5th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. #define resp 11     //Define da questão 6
  7. int main(){
  8.    
  9.     char gabarito[resp];                //Questão 6
  10.     int qntaluno;
  11.     printf("\t\tDigite o gabarito da prova(A, B, C ou D)");
  12.     for(int i=0;i<resp-1;i++){                  //laço de leitura dos caracteres do gabarito
  13.         printf("\nResposta questao %d: ", i+1);
  14.         scanf("%c", &gabarito[i]);
  15.         setbuf(stdin, NULL);
  16.     }
  17.     system("cls");          //desabilite caso queira fazer teste de mesa
  18.     printf("Informe a quantidade de alunos: ");
  19.     scanf("%d", &qntaluno);
  20.     setbuf(stdin, NULL);
  21.    
  22.     char nomealuno[qntaluno][129], resposta;            //somente após leitura da quantidade de alunos pode-se declarar as variáveis
  23.     int nota[qntaluno][1]={0};
  24.    
  25.     system("cls");             
  26.     for(int i=0;i<qntaluno;i++){
  27.         printf("Informe o nome do aluno: ");
  28.         gets(nomealuno[i]);
  29.         for(int j=0;j<resp-1;j++){
  30.             printf("Informe a resposta de %s para a questão %d: ", nomealuno[i], j+1); //algoritmo da bolha para leitura das notas
  31.             resposta=getchar();
  32.             setbuf(stdin, NULL);            //sempre limpe o buffer
  33.             if(resposta==gabarito[j]){
  34.                 nota[i][0]++;
  35.             }
  36.             system("cls");
  37.         }
  38.        
  39.     }
  40.     printf("\t\tNotas dos alunos\n");
  41.     for(int i=0;i<qntaluno;i++){
  42.         printf("\n|%s\t|%d|", nomealuno[i], nota[i][0]);        //impressão dos nomes e notas
  43.     }
  44.     printf("\n");
  45.    
  46.     /*
  47.     int tam, flag=1;                                //Questão 5
  48.     printf("Quantidade strings: ");
  49.     scanf("%d", &tam);
  50.     setbuf(stdin, NULL);
  51.     char string[tam][129], stringaux[129];          //matriz de string(trabalha usando apenas o 1 índice)
  52.     for(int i=0;i<tam;i++){
  53.         printf("Digite um nome qualquer: ");
  54.         gets(string[i]);
  55.     }
  56.     //for(int i=0;i<tam;i++){
  57.     //  printf("%s", string[i]);
  58.     //}
  59.     for(;flag==1;){
  60.         flag=0;                                     //algoritmo da bolha, controlado por uma flag
  61.         for(int j=0;j<tam-1;j++){
  62.             //printf("(%d) ", strcasecmp(string[j], string[j+1]));
  63.             if(strcasecmp(string[j], string[j+1])>0){       //se a subtração de uma string por outra for acima de 0
  64.                 strcpy(stringaux, string[j]);       //função strcpy, para atribuir uma string a outra string
  65.                 strcpy(string[j], string[j+1]);
  66.                 strcpy(string[j+1], stringaux);
  67.                 flag=1;         //caso tenha atendido a condição a flag faz com que o algoritmo continue
  68.             }
  69.         }
  70.     }
  71.     printf("\t\tStrings em ordem alfabetica\n");
  72.     for(int i=0; i<tam;i++){                        //imprime as strings
  73.         printf("%s\n", string[i]); 
  74.     }
  75.     */
  76.    
  77.     /*
  78.     char string[100], carac, vogais[]={'A','E','I','O','U'};        //questão 4
  79.     int tam;
  80.     printf("Digite uma frase: ");
  81.     gets(string);
  82.     setbuf(stdin, NULL);
  83.     tam=strlen(string);
  84.     printf("Insira um caracter qualquer: ");
  85.     scanf("%c", &carac);                           
  86.     for(int i=0;i<tam;i++){         //rotina de verificação de vogais presentes na string e substituição
  87.         for(int j=0;j<5;j++){
  88.             if(toupper(string[i])==vogais[j]){
  89.                 string[i]=carac;
  90.             }
  91.            
  92.         }
  93.         //if(string[i]=='a' || string[i]=='A' || string[i]=='e' || string[i]=='E' || string[i]=='i' || string[i]=='I' || string[i]=='o' || string[i]=='O' || string[i]=='u' || string[i]=='U')
  94.         //  string[i]=carac;
  95.     }
  96.     printf("\n%s", string);
  97.     */
  98.     /*
  99.     char string[100];           //questão 3
  100.     int tam;
  101.     printf(">> ");
  102.     gets(string);
  103.     tam=strlen(string);         //função para identificar o tamnho da string/atribuição na variável tam
  104.     char stringaux[tam];            //stringaux para armazenar a string invertida
  105.     strcpy(stringaux, string);
  106.     for(int i=tam-1, j=0;i>-1;i--,j++){     //rotina de inversão de string
  107.         string[j]=stringaux[i];
  108.         //printf("%c", stringaux[j]);
  109.     }
  110.     printf("\n\n%s", string);
  111.     */
  112.     /*char string[100];             //Questão 2
  113.     int tam;
  114.     printf(">> ");
  115.     gets(string);
  116.     setbuf(stdin, NULL);        //limpa buffer teclado(stdin)
  117.     tam=strlen(string);         //função tamanho da string
  118.     for(int i=tam-1;i>=0;i--){
  119.         printf("%c", string[i]);    //mostra a string ao contrário
  120.     }*/
  121.     /*
  122.     char string[10];                //Questão 1
  123.     printf(">> ");
  124.     gets(string);                  
  125.     for(int i=0;i<4;i++){
  126.         printf("%c", string[i]);
  127.     }*/
  128.     return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement