Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "iostream" // comando cin cout
- #include "cstdlib" // comando system
- #include "math.h" // funções matemáticas
- #define n 3
- using namespace std;
- typedef struct triangulo tri;
- struct triangulo
- { double a[n], b[n], c[n], base[n], altura[n], area[n], semper[n];
- string tipo[n];
- };
- tri t1;
- double lerA()
- { double a;
- system("cls");
- cout << "\nDigite o LADO A: ";
- cin >> a;
- return a;
- }
- double lerB()
- { double b;
- system("cls");
- cout << "\nDigite o LADO B: ";
- cin >> b;
- return b;
- }
- double lerC()
- { double c;
- system("cls");
- cout << "\nDigite o LADO C: ";
- cin >> c;
- return c;
- }
- string gettipo(double a, double b, double c)
- {
- if (a==b && a == c) return "equilatero";
- else if (a!=b && a!=c && b!=c) return "escaleno";
- else return "isoceles";
- }
- double getsemper(double a, double b, double c)
- { return ( a+b+c)/2; }
- double getarea(double a, double b, double c, double s)
- { return sqrt( s*(s-a)* (s-b)* (s-c) ); }
- double getbase(double a, double b, double c, string tp)
- { if (tp == "equilatero") return a;
- else if (tp == "escaleno"){
- if (a>b && a > c) return a;
- else if (b>a && b > c) return b;
- else return c;}
- else{
- if (a==b) return c;
- else if (a==c) return b;
- else return a;} }
- double getaltura(double b, double a)
- { return (2 * a )/b;
- }
- void armazena_struct(double a1, double b1,double c1, string tipo1, int linha)
- {
- t1.a[linha] = a1; t1.b[linha] =b1; t1.c[linha] = c1; t1.tipo[linha] = tipo1;
- }
- void processar_struct(int linha)
- {
- for (int i=0; i<= linha ;i++)
- { t1.semper[i] = getsemper(t1.a[i], t1.b[i], t1.c[i] );
- t1.area[i] = getarea(t1.a[i], t1.b[i], t1.c[i], t1.semper[i] );
- t1.base[i] = getbase(t1.a[i], t1.b[i], t1.c[i], t1.tipo[i] );
- t1.altura[i] = getaltura( t1.area[i], t1.base[i]);
- }
- }
- void telasaida(int linh)
- { system("cls");
- for (int i =0; i<= linh; i++)
- {
- cout << "\n\nRelatório de Saída " << i+1 << endl;
- cout << "\nValor de LA....: " << t1.a[i];
- cout << "\nValor de LB....: " << t1.b[i];
- cout << "\nValor de LC....: " << t1.c[i];
- cout << "\nValor de TIPO: " << t1.tipo[i];
- cout << "\nValor de BASE...: " << t1.base[i];
- cout << "\nValor de ALTURA...: " << t1.altura[i];
- cout << "\nValor de AREA..: " << t1.area[i];
- cout << "\nValor de SEMPER...: " << t1.semper[i];
- cout << "\n" << endl;
- }
- system("pause");
- }
- int telaentrada() {
- int tecla;
- system("cls");
- cout << "\nTela de Entrada\n";
- cout << "\n1- ler A, B e C";
- cout << "\n2- Calcular ";
- cout << "\n3- exibir ";
- cout << "\n4- Finalizar";
- cout << "\nItem: ";
- cin >> tecla;
- return tecla; }
- void controlemenu() {
- float a, b, c;
- string tipo;
- int tecla = -1, linh = -1, x = -1;
- while (tecla != 4)
- { tecla = telaentrada();// chama a tela
- switch (tecla)
- {
- case 1:
- linh ++;
- if(linh<n){
- a = lerA();
- b = lerB();
- c = lerC();
- tipo = gettipo(a,b,c);
- armazena_struct(a,b,c, tipo, linh);
- }
- else{
- system("cls");
- cout << "\nNão há mais espaço para novos dados!\n" << endl;
- linh --;
- system("pause");}
- break;
- case 2:
- x++;
- if(x<n){
- system("cls");
- processar_struct(linh);
- cout << "\nCálculo realizado com sucesso!\n" << endl;
- system("pause");
- }
- else{
- system("cls");
- cout << "\nNão há novos dados para cálculo!\n" << endl;
- x--;
- system("pause");}
- break;
- case 3:
- telasaida(linh);
- break;
- }}}
- int main()
- {
- setlocale(LC_ALL, "Portuguese");
- controlemenu();
- return 0; }
Advertisement
Add Comment
Please, Sign In to add comment