CaioCesar

Aula 5 - Análise de triângulos (funções)

Oct 5th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <conio.h>
  4. #include <string.h>
  5. #include <windows.h>
  6. using namespace std;
  7.  
  8. double a, b, c, p, ar, bs, alt, maior, menor;
  9.  
  10. float ler_a(){
  11.         cout << "\nDigite o valor do lado A: "; cin >> a;
  12.     return 0;
  13. }
  14.  
  15. float ler_b(){
  16.         cout << "Digite o valor do lado B: "; cin >> b;
  17.     return 0;
  18. }
  19.  
  20. float ler_c(){
  21.         cout << "Digite o valor do lado C: "; cin >> c;
  22.     return 0;
  23. }
  24.  
  25. int verifica_triangulo(){
  26.         if(a<(b+c) && b<(a+c) && c<(a+b)){
  27.             cout << "\nEh triangulo!" << endl;
  28.         }
  29.         else{
  30.             cout << "\nNao eh triangulo!" << endl;
  31.         }
  32.     return 0;
  33. }
  34.  
  35. int tipo_triangulo(){
  36.         if(a<(b+c) && b<(a+c) && c<(a+b)){
  37.             if(a==b && a==c && b==c)cout << "\nEquilatero!\n";
  38.             if(a==b || a==c || b==c)cout << "\nIsósceles!\n";
  39.             if(a!=b && a!=c && b!=c)cout << "\nEscaleno!\n";
  40.         }
  41.     return 0;
  42. }
  43.  
  44. float semiperimetro(){
  45.         p = (a+b+c)/2;
  46.         cout << "\nSemiperimetro: " << p << endl;
  47.     return 0;
  48. }
  49.  
  50. float area(){
  51.         ar = sqrt(p*(p-a)*(p-b)*(p-c));
  52.         cout << "\nArea: " << ar << endl;
  53.     return 0;
  54. }
  55.  
  56. float base(){
  57.         if(a==b==c)bs=a;
  58.         else{
  59.             maior = a;
  60.             menor = a;
  61.             if(b<menor)menor=b;
  62.             if(b>maior)maior=b;
  63.             if(c<menor)menor=c;
  64.             if(c>maior)maior=c;
  65.             bs = maior;
  66.         }
  67.         if(a==b)bs=c;
  68.         if(a==c)bs=b;
  69.         if(b==c)bs=a;
  70.  
  71.         cout << "\nBase: " << bs << endl;
  72.  
  73.     return 0;
  74. }
  75.  
  76. float altura(){
  77.         alt=(2*ar)/bs;
  78.         cout << "\nAltura " << alt << endl;
  79.     return 0;
  80. }
  81.  
  82. int main ()
  83. { setlocale(LC_ALL, "Portuguese");
  84.  
  85. char tecla = '0';
  86.  
  87. while (tecla != 27 )
  88. {   // tela de menu
  89.     system("cls");
  90.     cout <<   "\n***Menu de Controle***\n \
  91.              \n1-Ler os lados A,B e C: \
  92.              \n2-Verificar se eh triangulo: \
  93.              \n3-Verifica o tipo do triangulo: \
  94.              \n4-Calcular semiperimetro: \
  95.              \n5-Calcular a area: \
  96.              \n6-Identificar a base: \
  97.              \n7-Calcular a altura: \
  98.              \nESC - Finalizar programa: \
  99.              \n\n\nItem:";
  100.               tecla = getch();
  101.     // tratamento do menu
  102.     if (tecla == '1'){
  103.               ler_a();
  104.               ler_b();
  105.               ler_c();
  106.               system("pause");
  107.     }
  108.     else if (tecla =='2'){
  109.         verifica_triangulo();
  110.         system("pause");
  111.     }
  112.     else if (tecla == '3'){
  113.         tipo_triangulo();
  114.         system("pause");
  115.     }
  116.     else if (tecla == '4'){
  117.         semiperimetro();
  118.         system("pause");
  119.     }
  120.     else if (tecla == '5'){
  121.         area();
  122.         system("pause");
  123.     }
  124.     else if (tecla == '6'){
  125.         base();
  126.         system("pause");
  127.     }
  128.     else if (tecla == '7'){
  129.         altura();
  130.         system("pause");
  131.     }
  132. }// fim do menu
  133. return 0;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment