Advertisement
LightProgrammer000

Ordenamento [3 Notas]

Nov 26th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. /// Bibliotecas
  2. #include <conio.h>
  3. #include <locale.h>
  4. #include <iostream>
  5. #include <stdlib.h>
  6. using namespace std;
  7.  
  8. // Variáveis Globais
  9. float nota[3];
  10.  
  11. /// Funções
  12. void Ordenamento();
  13. char Menu(char cod);
  14. void Entrada_Dados();
  15.  
  16. /// Programa
  17. int main( int argc, char *argv [] )
  18. {
  19.     // Variável Estratégica
  20.     char cod = 'A';
  21.  
  22.     // Estrutura de Repetição
  23.     while( cod != 'n' && cod != 'N' )
  24.     {
  25.         // Sistemas
  26.         setlocale(LC_ALL, "");
  27.         system("cls & color E");
  28.  
  29.         // Apresentação 1
  30.         cout << " ========================== " << endl;
  31.         system("echo  - Usuario: %username%");
  32.         system("echo  - Computador: %computername%");
  33.         system("echo  - Hora: %time:~0,-3%");
  34.         system("echo  - Data: %date:/=-%");
  35.         cout << " ========================== " << endl;
  36.  
  37.         cout << "\n\n ================== " << endl;
  38.         cout << "     RESULTADOS     " << endl;
  39.         cout << " ================== " << endl;
  40.  
  41.         // Chamada de Procedimentos
  42.         Entrada_Dados();
  43.         Ordenamento();
  44.  
  45.         // Menu
  46.         cod = Menu(cod);
  47.     }
  48.  
  49.     return(0);
  50. }
  51. //////////////////// FUNÇÕES ////////////////////
  52.  
  53. // Entrada_Dados
  54. void Entrada_Dados()
  55. {
  56.     int i;
  57.  
  58.     for ( i = 0; i < 3 ; i++ )
  59.     {
  60.         cout << "\n - Digite o valor: ";
  61.         cin >> nota[i];
  62.     }
  63. }
  64.  
  65. // Ordernamento
  66. void Ordenamento()
  67. {
  68.     int i, j;
  69.     float aux;
  70.  
  71.     system("cls & color B");
  72.     cout << "\n\n ======== DADOS ======== " << endl;
  73.     cout << " - Valor [x] = " << nota[0] << endl;
  74.     cout << " - Valor [y] = " << nota[1] << endl;
  75.     cout << " - Valor [z] = " << nota[2] << endl;
  76.     cout << " ======================= " << endl;
  77.  
  78.     // Ordem Crescente
  79.     for ( i = 0; i < 3; i ++ )
  80.     {
  81.         for ( j = 0; j < i ; j ++ )
  82.         {
  83.             if ( nota[j] > nota[i] )
  84.             {
  85.                 aux = nota[i];
  86.                 nota[i] = nota[j];
  87.                 nota[j] = aux;
  88.             }
  89.         }
  90.     }
  91.  
  92.     cout << "\n\n ===== ORDENAMENTO ===== " << endl;
  93.     cout << " - Valor [x] = " << nota[0] << endl;
  94.     cout << " - Valor [y] = " << nota[1] << endl;
  95.     cout << " - Valor [z] = " << nota[2] << endl;
  96.     cout << " ======================= " << endl;
  97. }
  98.  
  99. // Menu
  100. char Menu( char cod )
  101. {
  102.     cout << "\n - Deseja Voltar ao Programa ? " << endl;
  103.     cout << " - [s] Sim" << endl;
  104.     cout << " - [n] Não " << endl;
  105.     cout << " - Opc.: ";
  106.     cod = getche();
  107.     cout << "" << endl;
  108.  
  109.     return (cod);
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement