Glaas2

Triangulo__plano

Sep 13th, 2012
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct Triangulo{
  5.        int X[3];
  6.        int Y[3];
  7.        }Triang;
  8.        
  9. void escribir(Triang *);
  10. void mostrar(Triang *);
  11. void cambiar(Triang *);
  12. void distancia(Triang *, int , float *);
  13.        
  14. int main(int argc, char *argv[])
  15. {  
  16.     int fin = 0;
  17.     int opcion=0, opcion2;
  18.     float dis;
  19.     Triang T;
  20.    
  21.     while (fin == 0)
  22.         {
  23.         system("cls");
  24.         printf("Menú simple\n\n");
  25.    
  26.         printf("\t1] Escribir Triangulo.\n");
  27.         printf("\t2] Mostrar Coordenadas.\n");
  28.         printf("\t3] Cambiar Coordenadas.\n");
  29.         printf("\t4] Distancia Entre Puntos.\n");
  30.         printf("\t5] Salir.\n");
  31.    
  32.         printf("\n\nOpcion: ");
  33.         scanf("%i", &opcion);
  34.            
  35.         switch(opcion)
  36.             {
  37.                 case 1:
  38.                      system("cls");
  39.                      escribir(&T);
  40.                      system("pause");
  41.                     break;
  42.                 case 2:
  43.                      system("cls");
  44.                      mostrar(&T);
  45.                      system("pause");              
  46.                      break;
  47.                 case 3:
  48.                      system("cls");
  49.                      cambiar(&T);
  50.                      system("pause");
  51.                     break;
  52.                 case 4:
  53.                      system("cls");
  54.                      printf("Distancia\n\n");
  55.                      printf("\t1] Distancia AB.\n");
  56.                      printf("\t2] Distancia AC.\n");
  57.                      printf("\t3] Distancia BC.\n");
  58.                      printf("Seleccion: ");
  59.                      scanf("%d", &opcion2);
  60.                      distancia(&T, opcion2, &dis);
  61.                      system("pause");
  62.                     break;
  63.                 case 5:
  64.                     fin = 1;
  65.                     break;
  66.                 default:
  67.                     fin = 0;
  68.                     break;
  69.             }
  70.            
  71.         }
  72.  
  73.     return 0;
  74. }
  75.  
  76. void escribir(Triang *T)
  77. {
  78.  Triang *T1;
  79.  T1 = T;
  80.  printf("Ingrese las coordenadas, en formato X1,Y1 X2,Y2 X3,Y3: \n");
  81.  scanf("%d,%d %d,%d %d,%d)", &T1->X[0], &T1->Y[0], &T1->X[1], &T1->Y[1], &T1->X[2], &T1->Y[2]);  
  82. }
  83.  
  84. void mostrar(Triang *T)
  85. {
  86.  Triang *T1;
  87.  T1 = T;
  88.  printf("\nLas coordenadas son A(%d,%d) B(%d,%d) C(%d,%d)\n", T1->X[0], T1->Y[0], T1->X[1], T1->Y[1], T1->X[2], T1->Y[2]);    
  89. }
  90.  
  91. void cambiar(Triang *T)
  92. {
  93.  Triang *T1;
  94.  T1 = T;    
  95.  printf("\nCoordenadas anteriores: A(%d,%d) B(%d,%d) C(%d,%d)\n", T1->X[0], T1->Y[0], T1->X[1], T1->Y[1], T1->X[2], T1->Y[2]);
  96.   printf("Ingrese las nuevas coordenadas, en formato X1,Y1 X2,Y2 X3,Y3: \n");
  97.  scanf("%d,%d %d,%d %d,%d)", &T1->X[0], &T1->Y[0], &T1->X[1], &T1->Y[1], &T1->X[2], &T1->Y[2]);
  98. }
  99.  
  100. void distancia(Triang *T, int opcion2, float *dis)
  101. {
  102.  Triang *T1;
  103.  T1 = T;
  104.  int A, B;
  105.  if(opcion2==1)
  106. {
  107.   A=T1->X[1]-T1->X[0];
  108.   B=T1->Y[1]-T1->Y[0];
  109.  *dis=sqrt(pow(A, 2)+ pow(B, 2));
  110.  printf("Distancia de AB :\t%.2f\n", *dis);
  111. }
  112.  
  113. if(opcion2==2)
  114. {
  115.  A=T1->X[2]-T1->X[0];
  116.  B=T1->Y[2]-T1->Y[0];
  117. *dis=sqrt(pow(A, 2)+ pow(B, 2));
  118.  printf("Distancia de AC :\t%.2f\n",*dis);
  119. }
  120.  
  121. if(opcion2==3)
  122. {
  123.  A=T1->X[2]-T1->X[1];
  124.  B=T1->Y[2]-T1->Y[1];
  125.  *dis=sqrt(pow(A, 2)+ pow(B, 2));
  126.  printf("Distancia de CB :\t%.2f\n",*dis);
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment