-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathController.c
More file actions
157 lines (132 loc) · 5.33 KB
/
Controller.c
File metadata and controls
157 lines (132 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "DataShell.h"
#include "dataStatics.h"
int main (void)
{
char* fileName=NULL;
int numLines = 0, numElements;
int option;
int flagOption = 0, flagGraph = 0;
float median, mean, mode, SD;
float sum;
float min, max;
//Calling function to get name
menuOne(&fileName);
numLines = NumberLines(fileName); //Calling function to count how many lines
numElements = countElements(fileName); //Calling function to count elements in line
float **Matrix = malloc(sizeof(float) * numLines * numElements); //Create Matrix
readDB(Matrix, fileName, numElements); //We read the DB and store it in Matrix
float arr[numLines];
float arr2[numLines];
float arr3[numLines];
do{
option = menuTwo();
switch (option)
{
case 1: //case print csv
/* code */
printMatrix(Matrix, &numLines, &numElements);
//Wait:
printf("\nPress [enter] to go back to the menu.\n");
__fpurge(stdin);
getchar();
break;
case 2: //case calculate data statics
/* code */
flagOption = 1;
sortArray(Matrix, &numLines, &numElements, arr, 1);
sum = addData(arr, &numLines);
mean = calculateMean(&sum, &numLines);
median = calculateMedian(arr, &numLines);
mode = calculateMode(arr, &numLines);
SD = calculateStandardDeviation(arr, &mean, &numLines);
//Rango(arr, &numLines, &min, &max);
//Results
printf("\tData Statics:\n");
//printf("Sum: %0.6f\n", sum);
printf("Media: %.6f\n", mean);
printf("Mediana: %.6f\n", median);
printf("Moda: %0.6f\n", mode);
printf("Desviacion Estandar: %0.6f\n", SD);
//printf("Rango: min. %0.6f, max.%0.6f\n", min, max);
writeCSV(&mean, &median, &mode, &SD);
/* code */
printf("Creating graph...\n");
//createGraph();
histogram(arr, &numLines, 1);
/*
for(int i = 0; i < numLines; i ++)
{
printf("%0.6f\n", arr[i]);
}*/
//Wait:
printf("\nPress [enter] to go back to the menu.\n");
__fpurge(stdin);
getchar();
break;
case 3: //case second column
/* code */
sortArray(Matrix, &numLines, &numElements, arr2, 2);
sum = addData(arr2, &numLines);
mean = calculateMean(&sum, &numLines);
median = calculateMedian(arr2, &numLines);
mode = calculateMode(arr2, &numLines);
SD = calculateStandardDeviation(arr2, &mean, &numLines);
//Results
printf("\tData Statics:\n");
//printf("Sum: %0.6f\n", sum);
printf("Media: %.6f\n", mean);
printf("Mediana: %.6f\n", median);
printf("Moda: %0.6f\n", mode);
printf("Desviacion Estandar: %0.6f\n", SD);
writeCSV(&mean, &median, &mode, &SD);
/*for(int i = 0; i < numLines; i ++)
{
printf("%0.6f\n", arr2[i]);
}*/
/* code */
printf("Creating graph...\n");
//createGraph();
histogram(arr2, &numLines, 2);
//Wait:
printf("\nPress [enter] to go back to the menu.\n");
__fpurge(stdin);
getchar();
break;
case 4: //case column 3
/* code */
printf("3\n");
sortArray(Matrix, &numLines, &numElements, arr3, 3);
sum = addData(arr3, &numLines);
mean = calculateMean(&sum, &numLines);
median = calculateMedian(arr3, &numLines);
mode = calculateMode(arr3, &numLines);
SD = calculateStandardDeviation(arr3, &mean, &numLines);
//Results
printf("\tData Statics:\n");
//printf("Sum: %0.6f\n", sum);
printf("Media: %.6f\n", mean);
printf("Mediana: %.6f\n", median);
printf("Moda: %0.6f\n", mode);
printf("Desviacion Estandar: %0.6f\n", SD);
writeCSV(&mean, &median, &mode, &SD);
/*
for(int i = 0; i < numLines; i ++)
{
printf("%0.6f\n", arr3[i]);
}*/
/* code */
printf("Creating graph...\n");
//createGraph();
histogram(arr3, &numLines, 3);
//Wait:
printf("\nPress [enter] to go back to the menu.\n");
__fpurge(stdin);
getchar();
break;
default:
break;
}
}while(option != 5);
free(Matrix);
return 0;
}