Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions Examen1/Data_Statistic.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Media:
4
Mediana:
4
Moda:
5
50 changes: 50 additions & 0 deletions Examen1/Data_histo.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
5, 27
5, 26
5, 25
4, 23
4, 22
4, 21
5, 24
5, 23
4, 20
5, 22
5, 21
4, 19
5, 20
4, 18
5, 19
5, 18
5, 17
5, 16
5, 15
5, 14
4, 17
4, 16
5, 13
4, 15
4, 14
5, 12
4, 13
4, 12
5, 11
5, 10
5, 9
4, 11
5, 8
4, 10
5, 7
4, 9
5, 6
4, 8
4, 7
4, 6
4, 5
4, 4
5, 5
5, 4
4, 3
4, 2
5, 3
5, 2
5, 1
4, 1
Binary file added Examen1/Examen 1 David Perez .pdf
Binary file not shown.
Binary file modified Examen1/Primer examen parcial Grupo B Otoño 2020.pdf
Binary file not shown.
65 changes: 65 additions & 0 deletions Examen1/TDA_Statistics.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <stdio.h>
#include <stdlib.h>
//#include "dispersion.h"
#include "media.h"
#include "files.h"

int crearhnum(int aux[100][2], int num[]);
int main(void)
{
char ar[50];
int num[100];
int hnum[100][2];
int cant;
int auxcant;
int media, mediana, moda;
//int dispersion
printf("Inserte el nombre del archivo a leer: ");
scanf("%s", ar);

files_leer(ar, num, &cant);
media=media_media(num, cant);
mediana=media_mediana(num,cant);
moda=media_moda(num,cant);

auxcant=crearhnum(hnum, num,cant);

files_meterdata(media, mediana, moda);

files_meterhisto(hnum, auxcant);

return 0;
}

int crearhnum(int aux[100][2], int num[], int cant)
{
int i;
int auxcant=0;
int j=0;
int moda=0, nummoda=0;
for(i=0;i<cant;i++)
{
if(i==0)
{
aux[0][0]=num[i];
aux[0][1]=1;
auxcant++;
}
else
{
for(j=0;j<auxcant;j++)
{
if(num[i]==aux[j][0])
aux[j][1]++;
}
if(j==auxcant)
{
aux[auxcant][0]=num[i];
aux[auxcant][1]=1;
auxcant++;
}
}

}
return auxcant;
}
51 changes: 51 additions & 0 deletions Examen1/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
,0
0,5.077850806
1,5.11361086
2,5.013413304
3,4.7066951
4,4.976198376
5,4.687136226
6,5.124400784
7,5.091652721
8,4.626762324
9,5.35344503
10,5.031065345
11,4.162632474
12,5.099215149
13,4.314255758
14,5.071030028
15,5.146366446
16,5.286848671
17,5.132360742
18,5.04395336
19,5.636707268
20,4.777943651
21,4.89574049
22,5.169317399
23,4.893662278
24,4.417269492
25,5.076816536
26,4.955695648
27,4.815426492
28,5.126990887
29,5.111338314
30,5.478111414
31,4.925767003
32,5.042099781
33,4.676226811
34,5.079265995
35,4.424209541
36,5.028716159
37,4.933538801
38,4.978475742
39,4.798586263
40,4.695443163
41,4.923005744
42,5.167948946
43,5.139372134
44,4.670964362
45,4.903235874
46,5.202417898
47,5.190025396
48,5.076624563
49,4.501765132
49 changes: 49 additions & 0 deletions Examen1/files.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
#include "files.h"

void files_leer(char name[], int num[], int *cant)
{
FILE *archivo=NULL;
char linea[50];

int i=0,aux;
archivo=fopen(name, "rt");

while(!feof(archivo))
{
fgets(linea, 50, archivo);
sscanf(linea, "%d,%d",&aux, &num[i]);
if(feof(archivo))
break;
i++;

}
(*cant)=i;
fclose(archivo);
}


void files_meterhisto(int num[100][2], int cant)
{
FILE *archivo;
int i;
archivo=fopen("Data_histo.csv", "wt");
for(i=0;i<cant;i++)
fprintf(archivo, "%d, %d", num[i][0], num[i][1]);

fclose(archivo);
}

void files_meterdata(int media, int mediana, int moda)
{
FILE *archivo;
archivo=fopen("Data_Statistic.csv", "wt");

fprintf(archivo, "Media:\n\t%d\n", media);
fprintf(archivo, "Mediana:\n\t%d\n", mediana);
fprintf(archivo, "Moda:\n\t%d\n", moda);

fclose(archivo);

}
96 changes: 96 additions & 0 deletions Examen1/files.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// files.h
//
//
// Created by David Perez on 08/10/2020.
//

#ifndef files_h
#define files_h


/*
* System headers required by the following declarations
* (the implementation will import its specific dependencies):
*/

#include <stdio.h>
#include <stdlib.h>
/*
* Application specific headers required by the following declarations
* (the implementation will import its specific dependencies):
*/

/* Constants declarations. */

/* Set EXTERN macro: */

#ifndef files_IMPORT
#define EXTERN
#else
#define EXTERN extern
#endif

/* Types declarations. */

/* Global variables declarations. */


/* Function prototypes. */


/*
*
* La funcion files_leer lee el archivo dado por el usuario
*
* @params
* name (char[]):
* nombre del archivo a leer
* num(int[]);
* arreglo de numeros a leer
* cant (int*):
* cantidad leida de datos
* @returns
* void
*/


EXTERN void files_leer(char name[], int num[], int *cant);
/*
*
* La funcion files_meterdata metes los datos calculados a un archivo;
*
* @params
*
* media(int);
* media calculada
* mediana (int);
* mediana calculada
* moda(int);
* moda calculada
* @returns
* void.
*/


EXTERN void files_meterdata(int media, int mediana, int moda);

/*
*
* La funcion files_meterhisto crear el archivo que GNUPLOT puede leer
*
* @params
* num[int **]
* arreglo doble para ver numeros
* cant (int);
* cantidad de numeros
* @returns
* void
*/


EXTERN void files_meterhisto(int num[100][2], int cant);

#undef files_IMPORT
#undef EXTERN
#endif /* files_h */
Loading