Advertisement
LightProgrammer000

Bubble Sort [Maior e Menor]

Nov 28th, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.47 KB | None | 0 0
  1. // Bibliotecas
  2. #include <conio.h>
  3. #include <string.h>
  4. #include <locale.h>
  5. #include <stdlib.h>
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. /// Definições
  10. #define TAM 10
  11.  
  12. /// Variáveis Globais
  13. float cadastro[TAM];
  14.  
  15. /// Funções
  16. void Maior_Menor();
  17. char Menu(char cod);
  18. void Entrada_Dados();
  19. void Ordem_Crescente();
  20. void Ordem_Decrescente();
  21.  
  22. /// Programa
  23. int main( int argc, char *argv [] )
  24. {
  25.     // Variável Estratégica
  26.     char cod = 'A';
  27.  
  28.     // Estrutura de Repetição
  29.     while( cod != 'n' && cod != 'N' )
  30.     {
  31.         // Sistemas
  32.         setlocale(LC_ALL, "");
  33.         system("cls & color E");
  34.  
  35.         // Apresentação
  36.         cout << " ========================== " << endl;
  37.         system("echo  - Usuario: %username%");
  38.         system("echo  - Computador: %computername%");
  39.         system("echo  - Hora: %time:~0,-3%");
  40.         system("echo  - Data: %date:/=-%");
  41.         cout << " ========================== " << endl;
  42.  
  43.         // Chamda de Procedimento
  44.         Entrada_Dados();
  45.  
  46.         system("cls & color A");
  47.  
  48.         cout << "\n ======================= " << endl;
  49.         cout << "            ORDEM          " << endl;
  50.         cout << " ========================== " << endl;
  51.  
  52.         cout << "\n ===== Ordem Decrescente ===== " << endl;
  53.         Ordem_Decrescente();
  54.         cout << " ============================= \n" << endl;
  55.  
  56.         cout << "\n ===== Ordem Crescente ===== " << endl;
  57.         Ordem_Crescente();
  58.         cout << " ============================= \n" << endl;
  59.  
  60.         cout << "\n ***** Maior e Menor ***** " << endl;
  61.         Maior_Menor();
  62.         cout << " *************************** \n" << endl;
  63.  
  64.         // Menu Interativo
  65.         cod = Menu(cod);
  66.     }
  67.  
  68.     return(0);
  69. }
  70. /////////////////////////// FUNÇÕES ///////////////////////////
  71.  
  72. // Entrada de Dados
  73. void Entrada_Dados()
  74. {
  75.     int i;
  76.  
  77.     //system("cls & color A");
  78.     cout << "\n ===== Cadastro ===== \n" << endl;
  79.  
  80.     for ( i = 0; i < TAM ; i++ )
  81.     {
  82.         cout << " - Digite ["<< (i + 1) <<"]: ";
  83.         cin >>  cadastro[i];
  84.     }
  85.     cout << " ===================== " << endl;
  86. }
  87.  
  88. // Ordem Crescente
  89. void Ordem_Crescente()
  90. {
  91.     int i, j;
  92.     float aux;
  93.  
  94.     for ( i = 0; i < TAM; i++ )
  95.     {
  96.         for ( j = 0; j < i; j++ )
  97.         {
  98.             if ( cadastro[j] > cadastro[i] )
  99.             {
  100.                 aux = cadastro[i];
  101.                 cadastro[i] = cadastro[j];
  102.                 cadastro[j] = aux;
  103.             }
  104.         }
  105.     }
  106.  
  107.     for ( i = 0; i < TAM; i++ )
  108.     {
  109.         cout << " - " << cadastro[i] << endl;
  110.     }
  111. }
  112.  
  113. // Ordem Decrescente
  114. void Ordem_Decrescente()
  115. {
  116.     int i, j;
  117.     float aux;
  118.  
  119.     for ( i = 0; i < TAM; i++ )
  120.     {
  121.         for ( j = 0; j < i; j++ )
  122.         {
  123.             if ( cadastro[j] < cadastro[i] )
  124.             {
  125.                 aux = cadastro[i];
  126.                 cadastro[i] = cadastro[j];
  127.                 cadastro[j] = aux;
  128.             }
  129.         }
  130.     }
  131.  
  132.     for ( i = 0; i < TAM; i++ )
  133.     {
  134.         cout << " - " << cadastro[i] << endl;
  135.     }
  136. }
  137.  
  138. // Maior ou Menor
  139. void Maior_Menor()
  140. {
  141.     cout << " * Menor: " << cadastro[0] << endl;
  142.     cout << " * Maior: " << cadastro[TAM - 1] << endl;
  143. }
  144.  
  145. // Menu
  146. char Menu(char cod)
  147. {
  148.     cout << "\n\n - Deseja Realizar novas Tarefas ? " << endl;
  149.     cout << " - [s] Sim" << endl;
  150.     cout << " - [n] Não " << endl;
  151.     cout << " - Opc.: ";
  152.     cod = getche();
  153.     cout << "" << endl;
  154.  
  155.     return (cod);
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement