Skip to content

Instantly share code, notes, and snippets.

@juancarloscruzd
Last active December 30, 2015 09:39
Show Gist options
  • Save juancarloscruzd/7810862 to your computer and use it in GitHub Desktop.
Save juancarloscruzd/7810862 to your computer and use it in GitHub Desktop.
Patty, ahi ta tu trabajo....no lo he terminado de probar ...sobre todo la parte D3. Si lo vas a presentar impreso, como si nada....si lo vas a tener que correr en laboratorio ...ahi si está la incertidumbre...hasta el paso D2 lo he testeado y funciona perfecto. El paso D3 solo lo he traducido.
//
// main.cpp
// patty
//
// Created by Juanca on 2/12/13.
// Copyright (c) 2013 Juancarlos Cruz. All rights reserved.
//
#include <iostream>
#include <iomanip>
#include <ctime>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int convertir(float a, int b){
b = a;
return b;
}
void D1(int n){
float p, fd, me, eep, no;
int s;
do {
std::cout << "\t\t\t\t TABLA DE VALORES POSIBLES \n";
std::cout << "(0 < P <= 40) \t (60 <= Q <= 100) \t σp \t MARGEN DE ERROR\n";
std::cout << "------------------------------------------------------------\n";
std::cout << "\t\t\t\t\t\t\t\t\t 1.96 \t 10 \n";
std::cout << "\t\t\t\t\t\t\t\t\t 2.58 \t 7 \n";
std::cout << "\t\t\t\t\t\t\t\t\t 3.3 \t 5 \n";
std::cout << "------------------------------------------------------------\n";
std::cout << "\n\n";
std::cout << "\tPORCENTAJE DE TIEMPO INACTIVO (P): "; std::cin >> p;
std::cout << "\n";
std::cout << "\tPORCENTAJE DE TIEMPO EN MARCHA (Q): " << printf("%f",100-p) << " \n";
std::cout << "\tFACTOR DE σp: "; std::cin >> fd;
std::cout << "\n";
std::cout << "\tMARGEN DE ERROR: "; std::cin >> me;
std::cout << "\n";
eep = me/fd;
std::cout << "\tERROR ESTANDAR DE PROPORCION (dp): " << printf("%f", eep);
//convertir(eep, s);
s = (int)eep;
no = (p*(100-p))/(s*s);
n = int(no+0.5);
std::cout << "\tNUMERO DE OBSERVACIONES (dp): " << n;
if(no > 48){
std::cout << "\n";
std::cout << "EL NUMERO DE OBSERVACIONES DEBE SER MENOR O IGUAL QUE 48, INGRESE NUEVOS DATOS\n";
}
} while (no > 48);
}
void D2(int aleat[800]){
int c = 0, f = 0, na;
int tabla[800];
std::cout << "\n\n\t\t\t\tTABLA DE NUMEROS ALEATORIOS \n\n";
srand((unsigned)time(0));
for (int t = 0; t < 800; t++) {
na = (rand()%99)+1;
tabla[t] = na;
if(c == 20){
std::cout << "\n";
f = f+1;
c = 0;
}
if(na < 10){
std::cout << "0";
printf("%d",na);
} else {
printf("%d",na);
}
std::cout << " ";
c = c+1;
}
std::cout << "\n";
//Vaciando los valores de {tabla} a {aleat}
for (int i = 0; i <=800; i++) {
aleat[i] = tabla[i];
}
}
void D3(int n1, int n2[]){
int arreglo1[800], arreglo2[800];
int l,h,m;
//Bloque GUARDANDO
int j = 0, encontrado = 0;
for (int t = 0; t <= 800; t++) {
if (n2[t] <= 48) {
encontrado = 0;
j = j+1;
if(j==1){
arreglo1[1] = n2[t];
} else {
for (int l = 1; l <= j-1; l++) {
if (n2[t] == arreglo1[l]) {
encontrado = 1;
}
}
if(encontrado == 1){
j = j-1;
}else{
arreglo1[j] = n2[t];
}
}
}
}
//Bloque ORDENANDO
int aux;
for (int i = 1; i <= n1; i++) {
arreglo2[i] = arreglo1[i];
}
for (int l = 1; l <= n1; l++) {
for (int i = 1; i <= n1; i++) {
if (arreglo2[i-1] > arreglo2[i]) {
aux = arreglo2[i];
arreglo2[i] = arreglo2[i-1];
arreglo2[i-1] = aux;
}
}
}
//Bloque principal D3
std::cout << "\n\n\n\n";
std::cout << "CIFRAS UTILIZABLES \t\t CLASIFICADOS \t\t HORA DE LA \n";
std::cout << "RELACIONADAS DE LA TABLA \t\t POR ORDEN \t\t OBSERVACION \n";
std::cout << "DE NUMEROS ALEATORIOS \t\t NUMERICO \t\t \n";
for (int i = 1; n1; i++) {
if (arreglo1[i] < 10) {
std::cout << "0";
std::cout << arreglo1[i];
} else {
std::cout << arreglo1[i];
}
std::cout << "\t\t";
if (arreglo2[i] < 10) {
std::cout << "0";
std::cout << arreglo2[i];
} else {
std::cout << arreglo2[i];
}
h = (420 + (arreglo2[i])*10)%60;
m = (420 + (arreglo2[i])*10) - (h*60);
std::cout << "\t\t";
if(m == 0){
std::cout << printf("%i :0%i", h, m);
} else {
std::cout << printf("%i:%i", h,m);
}
}
}
int main(int argc, const char * argv[])
{
int num1 = 0;
int num2[800];
D1(num1);
D2(num2);
D3(num1, num2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment