Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #define DEC 10
- using namespace std;
- void bubble_sort( int v[], int qtd ){
- int i, j, aux;
- int k = qtd - 1 ;
- for(i = 0; i < qtd; i++){
- for(j = 0; j < k; j++){
- if(v[j] > v[j+1]){
- aux = v[j];
- v[j] = v[j+1];
- v[j+1]=aux;
- }
- }
- k--;
- }
- }
- void mostra_vet(int v[], int qtd){
- int cont;
- for (cont = 0; cont < qtd; cont++){
- cout << "[" << cont+1 << "] = " << v[cont] << ". # ";
- }
- cout << endl;
- }
- void dec_nagrup(){
- int tVet, cont = 0;
- float ftVet, dec;
- int *vet;
- cout << "Numero de Termos: ";
- cin >> tVet;
- vet = (int *) malloc ((tVet+1) * sizeof(int));
- do{
- cout << "Declaro os termos:" << endl;
- cout << "Termo: [" << cont+1 << "] = ";
- cin >> vet[cont];
- cont++;
- }while (cont <= (tVet-1));
- bubble_sort(vet, tVet);
- system ("CLS");
- mostra_vet(vet, tVet);
- ftVet = tVet;
- for (cont = 1; cont <= DEC; cont++){
- dec = cont * (ftVet + 1)/DEC;
- if (dec < 1){
- cout << "Decil [" << cont << "]" << " entre " << 0 << " e " << 1 << " termos." << endl;}
- //else if (cont == 1){
- // cout << "Decil [" << cont << "]" << " entre " << 0 << " e " << (int)dec << " termos." << endl;}
- else if (dec > tVet){
- cout << "Decil [" << cont << "]" << " entre " << (int)tVet << " e " << tVet << " termos." << endl;}
- else{
- cout << "Decil [" << cont << "]" << " entre " << (int)dec << " e " << (int)dec+1 << " termos." << endl;}
- }
- cout << endl;
- }
- void dec_agrup(){
- int cont, tVet, som = 0;
- float tVetF, *dec;
- int *vdF;
- float *vvi, *vvf, *vsF;
- cout << "Defina as variacoes: " << endl << "Numero de grupos: ";
- cin >> tVet;
- vvi = (float *) malloc ((tVet+1) * sizeof(float));
- vvf = (float *) malloc ((tVet+1) * sizeof(float));
- vdF = (int *) malloc ((tVet+1) * sizeof(int));
- vsF = (float *) malloc ((tVet+1) * sizeof(float));
- dec = (float *) malloc ((tVet+1) * sizeof(float));
- tVetF = tVet;
- vsF[1] = 0;
- for (cont = 1; cont <= tVet; cont++){
- cout << "[" << cont << "] variacao:\n";
- cout << "variacao de: ";
- cin >> vvi[cont];
- cout << "Ate: ";
- cin >> vvf[cont];
- cout << "com frequencia de: ";
- cin >> vdF[cont];
- vsF[cont] = vsF[cont] + vdF[cont];
- som = som + vdF[cont];
- }
- for (cont = 1; cont <= DEC; cont++){
- dec[cont] = cont * som/DEC;
- cout << (int)dec[cont] << endl;
- }
- }
- int main (){
- int ID;
- cout << "~~~Percentil/Decil's~~~" << endl;
- do{
- cout << "1.Para decis de dados nao agrupados, pressione '1': (de 1 a 30)" << endl << "2.Para decis de valores agrupados, pressione '2':"
- << endl << "3.Para sair do programa, pressione '0':" << endl;
- cin >> ID;
- system ("CLS");
- if (ID == 1){
- dec_nagrup();}
- else if (ID == 2){
- dec_agrup();}
- }while (ID != 0);
- system ("PAUSE");
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement