nikolas_serafini

Lista 7 - Exercício 9

Aug 10th, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAXBRAND 31
  3. #define MAXMODEL 40
  4. #define MAXAUTO 500
  5.  
  6. struct techInfo {
  7.     int cv,cili,val;
  8. };
  9.  
  10. typedef struct car {
  11.     char brand[MAXBRAND],model[MAXMODEL];
  12.     int fabYear;
  13.     struct techInfo techData;
  14. }car;
  15.  
  16. void inputCars(car autos[]);
  17. float performCheck(car autos);
  18. void showAll(car autos[]);
  19. int shitCarsCounter(car autos[]);
  20.  
  21. int main() {
  22.  
  23.     struct car autos[MAXAUTO];
  24.  
  25.     inputCars(autos);
  26.     printf("LISTAGEM DE VEICULOS:\n");
  27.     showAll(autos);
  28.     printf("Quantidade de carros com performance abaixo de 150 : %d\n",shitCarsCounter(autos));
  29.  
  30.     return 0;
  31. }
  32.  
  33. void inputCars(car autos[]) {
  34.     int i;
  35.  
  36.     for (i = 0; i < MAXAUTO; i++) {
  37.         printf("Entre com a marca do carro :\n");
  38.         gets(autos[i].brand);
  39.         printf("Entre com o modelo do carro :\n");
  40.         gets(autos[i].model);
  41.         printf("Entre com o ano de fabricacao :\n");
  42.         scanf("%d",&autos[i].fabYear);
  43.         printf("Entre com os CV :\n");
  44.         scanf("%d",&autos[i].techData.cv);
  45.         printf("Entre com as cilindradas :\n");
  46.         scanf("%d",&autos[i].techData.cili);
  47.         printf("Entre com a quantidade de valvulas :\n");
  48.         scanf("%d",&autos[i].techData.val);
  49.         fflush(stdin);
  50.     }
  51. }
  52.  
  53. float performCheck(car autos) {
  54.     if (autos.techData.val >= 16)
  55.         return (3*autos.techData.cv + autos.techData.cili)/(float)autos.techData.val;
  56.     else
  57.         return (2*autos.techData.cv + autos.techData.cili)/(float)autos.techData.val;
  58. }
  59.  
  60. void showAll(car autos[]) {
  61.     int i;
  62.  
  63.     for (i = 0; i < MAXAUTO; i++) {
  64.         printf("Marca : %s\nModelo : %s\nAno de fabricacao : %d",autos[i].brand,autos[i].model,autos[i].fabYear);
  65.         printf("\nCV : %d\nCilindradas : %d\nValvulas : %d\n",autos[i].techData.cv,autos[i].techData.cili,autos[i].techData.val);
  66.         printf("Performance estrutural : %f\n\n\n",performCheck(autos[i]));
  67.     }
  68. }
  69.  
  70. int shitCarsCounter(car autos[]) {
  71.     int i,counter = 0;
  72.  
  73.     for (i = 0; i < MAXAUTO; i++)
  74.         if (performCheck(autos[i]) < 150)
  75.             counter++;
  76.    
  77.     return counter;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment