martes, 13 de agosto de 2013

dev c++: Calcular hipotenusa, perimetro, area y dibujar triangulo rectangulo

/*
  programa: Calcula hipotenusa, perimetro, area y dibuja triangulo rectangulo.
  Claudio Enrique Alpizar Romero
  13.08.2013
  Compilador: dev c++ portable
 Utiliza color, ubicación de texto y marco.
*/

#include <stdio.h>
#include <windows.h>
#include <math.h>


void ir_cr(int x, int y)//Emulador de ir_cr
{
    /*
       funcion: crea función para ubicar printf en columna y renglón especifico
    por lo esta funcion emula ir_cr para posicionar texto en coordenadas especificas
    se tiene que declarar <windows.h>
    */
    COORD coord;
    coord.X=x;
    coord.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}

void Set_Mrc(int c1,int r1,int c2,int r2) // construye marco
{
    /*   
    funcion: crea marco con codigo ascii
    c1-----------c2
    r1            |
    |             |
    |             |
    -------------r2
    */
   int i;
   ir_cr(c1,r1); printf("%c",201);      // esquinas
   ir_cr(c1,r2); printf("%c",200);
   ir_cr(c2,r1); printf("%c",187);
   ir_cr(c2,r2); printf("%c",188);
   for(i=c1+1;i<c2;i++)                 // controla columna
   {
         ir_cr(i,r1);printf("%c",205);  // LINEA ARRIBA HORIZONTAL
         ir_cr(i,r2);printf("%c",205);  // LINEA ABAJO HORIZONTAL
   }
   for(i=r1+1;i<r2;i++)                 // controla renglon
   {
         ir_cr(c1,i);printf("%c",186);  // LINEA IZQUIERDA VERTICAL
         ir_cr(c2,i);printf("%c",186);  // LINEA DERECHA VERTICAL
   }   
}



float Get_hipotenusa(float a, float b)
{
      float hipotenusa = 0;
      hipotenusa = sqrt(a*a + b*b);
      return hipotenusa;
}

float Get_perimetro(float lado1, float lado2, float lado3)
{
      return lado1 + lado2 + lado3;
}

float Get_area(float b, float h)
{
      float area = (b*h)/2;
      return area;
}


void Set_dibuja(int a,int b)                                                                    
{                                                                              
 
 int T = b;                                                                 
 int R,C;                                                                      
 R = 1;                                                                        
 while (R <= b)  // renglon .- cateto mayor                                                           
    {                                                                          
      C = 1;                                                                   
      while (C <= R) /* columna */                                                        
      {                                                                   
          ir_cr(3+C,2+R);printf("#");                                                       
          C++;
      }                                                                   
      printf("\n");                                                          
      R++;                                                             
    }
    return;
}


main()
{
    char respuesta = 'n';
    float  a, b, x;
   
   
    system("color 74"); 
    do
    {
          
        system("CLS");
        Set_Mrc(1,1,78,23);
        Set_Mrc(27,3,50,5);
       
        ir_cr(28,4);printf("TRIANGULOS RECTANGULOS");
       
        printf("\n");
       
        ir_cr(28,7);printf("Cateto Menor = ");
        scanf("%f", &a);
        getchar();
       
        ir_cr(28,8);printf("Cateto Mayor = ");
        scanf("%f", &b);
        getchar();
       
        if(a>b)
        {
                x = a;
                a = b;
                b = x;
                ir_cr(28,10);printf("Cateto Menor = %f \n", a);
                ir_cr(28,11);printf("Cateto Mayor = %f \n", b);           
        }
       
        ir_cr(28,13);printf("Hipotenusa = %f", Get_hipotenusa(a,b) );
        ir_cr(28,14);printf("Perimetro  = %f", Get_perimetro(a,b,Get_hipotenusa(a,b)) );
        ir_cr(28,15);printf("Area       = %f", Get_area(a,b) );
       
        if (b<=20)
        {
              Set_dibuja(a,b);
        }
        else
        {
              Set_dibuja(7,20);
           
        }    
       
        printf("\n");
        ir_cr(28,22);printf("continuar <s/n> ? ");
        respuesta = getch();
       
        
    }while(respuesta == 's'|| respuesta == 'S');
   
   
    system("color 17");
    system("CLS");
    Set_Mrc(1,1,78,23);
    ir_cr(20,10);printf("Gracias por su visita, hasta luego!!!");
    ir_cr(18,22);printf("Presione cualquier tecla para continuar... ");
    getch();
}

No hay comentarios:

Publicar un comentario