Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <string>
- #include <math.h>
- #define n 3
- using namespace std;
- typedef struct pessoa pes;
- struct pessoa{
- string nome[n];
- double peso[n];
- double altura[n];
- string clas[n];
- double imc[n];};
- pes TB1;
- //Inicia funções de leitura
- string lernome(){
- system("cls");
- string N;
- cout << "Digite o Nome: ";
- cin >> N;
- return N;}
- double lerpeso(){
- system("cls");
- double P;
- cout << "Digite o Peso: ";
- cin >> P;
- return P;}
- double leraltura(){
- system("cls");
- double A;
- cout << "Digite a Altura: ";
- cin >> A;
- return A;}
- //Inicia funções de cálculo
- double getIMC(double P, double A){
- double I;
- I = P / pow(A,2);
- return I;}
- string getClas(double imc){
- if(imc>=40) return "Obesidade grau 3 (mórbida)";
- else if(imc>=35) return "Obesidade grau 2 (severa)";
- else if(imc>=30) return "Obesidade grau 1";
- else if(imc>=25) return "Levemente acima do peso";
- else if(imc>=18.6) return "Peso ideal, Parabéns";
- else if(imc<=18.5) return "Abaixo do peso";}
- void inserirstruct(int linha, string N, double P, double A){
- TB1.nome[linha] = N;
- TB1.peso[linha] = P;
- TB1.altura[linha] = A;
- cout << "\n*** Dados inseridos no struct com sucesso ***!\n\n";
- system("pause");}
- void processarstruct(int linha){
- for(int i=0; i<=linha;i++){
- TB1.imc[linha] = getIMC(TB1.peso[i], TB1.altura[i]);
- TB1.clas[linha] = getClas(TB1.imc[i]);
- }
- cout << "\n*** Struct processado com sucesso! ***\n\n" << endl;
- system("pause");
- }
- void exibir(int UL){
- system("cls");
- for(int i=0;i<=UL;i++){
- cout << "\nNome: " << TB1.nome[i];
- cout << "\nPeso: " << TB1.peso[i];
- cout << "\nAltura: " << TB1.altura[i];
- cout << "\nIMC: " << TB1.imc[i];
- cout << "\nClassificação: " << TB1.clas[i];
- cout << "\n" << endl;}
- system("pause");}
- int tela(){
- system("cls");
- int T;
- cout << "\n *** Calculadora IMC ***\n" << endl;
- cout << "\n1 - Ler \
- \n2 - Calcular \
- \n3 - Exibir \
- \n4 - Sair \
- \n\nItem: ";
- cin >> T;
- return T;}
- void menu(){
- double pes, alt;
- string cla, nom;
- int tecla = -1, linh = -1;
- while(tecla!=4){//Inicio Menu
- tecla = tela();
- if(tecla==1){
- nom = lernome();
- pes = lerpeso();
- alt = leraltura();
- linh ++;
- inserirstruct(linh, nom, pes, alt);
- }
- else if(tecla==2){
- system("cls");
- cout << "\nCalculando o IMC..." << endl;
- processarstruct(linh);
- }
- else if(tecla==3){
- system("cls");
- exibir(linh);
- }
- else if(tecla==4){
- system("cls");
- cout << "\n\n *** Obrigado por utilizar a calculadora de IMC ***\n\n" << endl;
- }
- }//Fim Menu
- }
- int main(){
- setlocale(LC_ALL, "Portuguese");
- system("cls");
- cout << "\n *** Calculadora IMC ***\n" << endl;
- menu();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement