Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #define DEC 10
  4.  
  5.  
  6.    using namespace std;
  7.    
  8.    void bubble_sort( int v[], int qtd ){
  9.    int i, j, aux;
  10.    int k = qtd - 1 ;
  11.  
  12.    for(i = 0; i < qtd; i++){
  13.       for(j = 0; j < k; j++){
  14.          if(v[j] > v[j+1]){
  15.             aux = v[j];
  16.             v[j] = v[j+1];
  17.             v[j+1]=aux;
  18.          }
  19.       }
  20.    k--;
  21.    }
  22.    }
  23.    
  24.    void mostra_vet(int v[], int qtd){
  25.       int cont;
  26.       for (cont = 0; cont < qtd; cont++){
  27.          cout << "[" << cont+1 << "] = " << v[cont] << ". # ";
  28.       }
  29.       cout << endl;
  30.    }
  31.    
  32.    void dec_nagrup(){
  33.    
  34.    int tVet, cont = 0;
  35.    float ftVet, dec;
  36.    int *vet;
  37.    
  38.    cout << "Numero de Termos: ";
  39.    cin >> tVet;
  40.    vet = (int *) malloc ((tVet+1) * sizeof(int));
  41.  
  42.    do{
  43.       cout << "Declaro os termos:" << endl;
  44.       cout << "Termo: [" << cont+1 << "] = ";
  45.       cin >> vet[cont];
  46.       cont++;
  47.    }while (cont <= (tVet-1));
  48.    
  49.    bubble_sort(vet, tVet);
  50.    system ("CLS");
  51.    mostra_vet(vet, tVet);
  52.    ftVet = tVet;
  53.    
  54.    
  55.    for (cont = 1; cont <= DEC; cont++){
  56.       dec = cont * (ftVet + 1)/DEC;
  57.       if (dec < 1){
  58.          cout << "Decil [" << cont << "]" << " entre " << 0 << " e " << 1 << " termos." << endl;}
  59.       //else if (cont == 1){
  60.         // cout << "Decil [" << cont << "]" << " entre " << 0 << " e " << (int)dec << " termos." << endl;}
  61.       else if (dec > tVet){
  62.          cout << "Decil [" << cont << "]" << " entre " << (int)tVet << " e " << tVet << " termos." << endl;}
  63.       else{
  64.          cout << "Decil [" << cont << "]" << " entre " << (int)dec << " e " << (int)dec+1 << " termos." << endl;}
  65.    }
  66.    cout << endl;  
  67.    }
  68.    
  69.    void dec_agrup(){
  70.       int cont, tVet, som = 0;
  71.       float tVetF, *dec;
  72.       int *vdF;
  73.       float *vvi, *vvf, *vsF;
  74.      
  75.       cout << "Defina as variacoes: " << endl << "Numero de grupos: ";
  76.       cin >> tVet;
  77.       vvi = (float *) malloc ((tVet+1) * sizeof(float));
  78.       vvf = (float *) malloc ((tVet+1) * sizeof(float));
  79.       vdF = (int *) malloc ((tVet+1) * sizeof(int));
  80.       vsF = (float *) malloc ((tVet+1) * sizeof(float));
  81.       dec = (float *) malloc ((tVet+1) * sizeof(float));
  82.       tVetF = tVet;
  83.       vsF[1] = 0;
  84.       for (cont = 1; cont <= tVet; cont++){
  85.          cout << "[" << cont << "] variacao:\n";
  86.          cout << "variacao de: ";
  87.          cin >> vvi[cont];
  88.          cout << "Ate: ";
  89.          cin >> vvf[cont];
  90.          cout << "com frequencia de: ";
  91.          cin >> vdF[cont];
  92.          vsF[cont] = vsF[cont] + vdF[cont];
  93.          som = som + vdF[cont];
  94.       }
  95.       for (cont = 1; cont <= DEC; cont++){
  96.          dec[cont] = cont * som/DEC;
  97.          cout << (int)dec[cont] << endl;
  98.          }
  99.          
  100.    }
  101.    
  102.    int main (){
  103.        
  104.       int ID;
  105.      
  106.       cout << "~~~Percentil/Decil's~~~" << endl;
  107.          
  108.       do{
  109.          cout << "1.Para decis de dados nao agrupados, pressione '1': (de 1 a 30)" << endl << "2.Para decis de valores agrupados, pressione '2':"
  110.          << endl << "3.Para sair do programa, pressione '0':" << endl;
  111.          cin >> ID;
  112.          system ("CLS");
  113.          if (ID == 1){
  114.          dec_nagrup();}
  115.          else if (ID == 2){
  116.          dec_agrup();}
  117.      
  118.       }while (ID != 0);
  119.      
  120.    system ("PAUSE");
  121.    return (0);
  122.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement