Advertisement
CaioCesar

Fatec - Struct - Cálculo IMC

Nov 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <string>
  4. #include <math.h>
  5. #define n 3
  6. using namespace std;
  7. typedef struct pessoa pes;
  8.  
  9. struct pessoa{
  10. string nome[n];
  11. double peso[n];
  12. double altura[n];
  13. string clas[n];
  14. double imc[n];};
  15. pes TB1;
  16.  
  17. //Inicia funções de leitura
  18. string lernome(){
  19. system("cls");
  20. string N;
  21. cout << "Digite o Nome: ";
  22. cin >> N;
  23. return N;}
  24.  
  25. double lerpeso(){
  26. system("cls");
  27. double P;
  28. cout << "Digite o Peso: ";
  29. cin >> P;
  30. return P;}
  31.  
  32. double leraltura(){
  33. system("cls");
  34. double A;
  35. cout << "Digite a Altura: ";
  36. cin >> A;
  37. return A;}
  38. //Inicia funções de cálculo
  39. double getIMC(double P, double A){
  40. double I;
  41. I = P / pow(A,2);
  42. return I;}
  43.  
  44. string getClas(double imc){
  45. if(imc>=40) return "Obesidade grau 3 (mórbida)";
  46. else if(imc>=35) return "Obesidade grau 2 (severa)";
  47. else if(imc>=30) return "Obesidade grau 1";
  48. else if(imc>=25) return "Levemente acima do peso";
  49. else if(imc>=18.6) return "Peso ideal, Parabéns";
  50. else if(imc<=18.5) return "Abaixo do peso";}
  51.  
  52. void inserirstruct(int linha, string N, double P, double A){
  53. TB1.nome[linha] = N;
  54. TB1.peso[linha] = P;
  55. TB1.altura[linha] = A;
  56. cout << "\n*** Dados inseridos no struct com sucesso ***!\n\n";
  57. system("pause");}
  58.  
  59. void processarstruct(int linha){
  60.     for(int i=0; i<=linha;i++){
  61.     TB1.imc[linha] = getIMC(TB1.peso[i], TB1.altura[i]);
  62.     TB1.clas[linha] = getClas(TB1.imc[i]);
  63.     }
  64.     cout << "\n*** Struct processado com sucesso! ***\n\n" << endl;
  65.     system("pause");
  66.     }
  67.  
  68. void exibir(int UL){
  69.     system("cls");
  70.     for(int i=0;i<=UL;i++){
  71.         cout << "\nNome: " << TB1.nome[i];
  72.         cout << "\nPeso: " << TB1.peso[i];
  73.         cout << "\nAltura: " << TB1.altura[i];
  74.         cout << "\nIMC: " << TB1.imc[i];
  75.         cout << "\nClassificação: " << TB1.clas[i];
  76.         cout << "\n" << endl;}
  77.     system("pause");}
  78.  
  79. int tela(){
  80. system("cls");
  81. int T;
  82. cout << "\n *** Calculadora IMC ***\n" << endl;
  83. cout << "\n1 - Ler \
  84.         \n2 - Calcular \
  85.         \n3 - Exibir \
  86.         \n4 - Sair \
  87.         \n\nItem: ";
  88. cin >> T;
  89. return T;}
  90.  
  91. void menu(){
  92. double pes, alt;
  93. string cla, nom;
  94. int tecla = -1, linh = -1;
  95.     while(tecla!=4){//Inicio Menu
  96.         tecla = tela();
  97.             if(tecla==1){
  98.                 nom = lernome();
  99.                 pes = lerpeso();
  100.                 alt = leraltura();
  101.                 linh ++;
  102.                 inserirstruct(linh, nom, pes, alt);
  103.                 }
  104.             else if(tecla==2){
  105.             system("cls");
  106.             cout << "\nCalculando o IMC..." << endl;
  107.             processarstruct(linh);
  108.             }
  109.             else if(tecla==3){
  110.             system("cls");
  111.             exibir(linh);
  112.             }
  113.             else if(tecla==4){
  114.             system("cls");
  115.             cout << "\n\n *** Obrigado por utilizar a calculadora de IMC ***\n\n" << endl;
  116.             }
  117.             }//Fim Menu
  118.     }
  119.  
  120. int main(){
  121.     setlocale(LC_ALL, "Portuguese");
  122.     system("cls");
  123.     cout << "\n *** Calculadora IMC ***\n" << endl;
  124.     menu();
  125.     system("pause");
  126.     return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement