-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileWriting.cpp
992 lines (742 loc) · 21.8 KB
/
FileWriting.cpp
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
//////////////////////////////////////////////////////////////
//
// Your #includes here; make sure you are allowed them ...
//
#include <fstream>
#include <stdlib.h>
#include <cmath>
#include <limits.h>
using namespace std;
//////////////////////////////////////////////////////////////
//
// local #includes and function declarations; do not remove
//
#ifndef MARMOSET_TESTING
#include <iostream>
struct Student{
int studentID;
int grade;
};
struct Dataset{
int numStudents;
Student* students;
};
struct Rejects{
int numRejects;
int* rejects;
};
struct Mode{
int numModes;
int* modes;
};
struct Statistics{
int minimum;
float average;
int maximum;
float popStdDev;
float smplStdDev;
Mode mode;
int histogram[10];
};
#endif
//////////////////////////////////////////////////////////////
//
// struct definitions
//
//////////////////////////////////////////////////////////////
//
// Function declarations; do not remove
//
bool sort(int dataset[], const int size);
bool stringToInt(const char input[], int& value);
void merge (int data[], const int lower, const int upper);
char* stringConcat(const char base[] , const char exten[]);
char* stringCut(const char base[]);
bool statistics(const float dataset[], const int size,
float& min, float& avg, float& max,
float& popSD, float& smplSD, float& mdn);
int minimum(const int dataset[], const int size);
float average(const int dataset[], const int size);
int maximum(const int dataset[], const int size);
float popStdDev(const int dataset[], const int size);
float smplStdDev(const int dataset[], const int size);
int mode(const int dataset[], const int size, Mode& modeStructure);
int modHelper(const int data[], const int size,int mode[] ,int currentIndex,
int currentRep, int maxRep, int indOfMod);
int computeStatistics(Dataset& data, Statistics& stats);
int readCSV(const char filename[],const int minAcceptableID,
const int maxAcceptableID,Dataset& data,
Rejects& rejects);
int writeCSV(const char filename[], const Statistics& stats);
int readSCVHelp(char inputLine [],int& lineNum,Rejects& rejectionStruct,
const int minAcceptableID, const int maxAcceptableID, Dataset& dataStruct);
//////////////////////////////////////////////////////////////
//
// Your code here ...
//
// SORT OR HELPER FUNCTIONS
////////////////////////////////////////////////////////////////////
bool sort(int dataset[], const int size){
merge(dataset,0,size);
return true;
}
void merge (int data[], const int lower, const int upper){ // [lower,upper)
int middlePoint = (upper+lower)/2;
if ( (upper-lower) > 2){ //keep dividing
merge(data,lower,middlePoint);
merge(data,middlePoint,upper);
}
int temp[upper-lower]; // temp array
int i= lower; //starting point of i
int j= middlePoint; //starting point of j
int k = 0; //new array counter
while( (i< middlePoint) && (j < upper) ){ //while one of them is not empty
if(data[i] <= data[j]){
temp[k] = data[i];
i++;
}
else{
temp[k]= data[j];
j++;
}
k++; //next array
}
// if one of the data array is depleted before the other one
while (j < upper){
temp[k] = data[j];
j++;
k++;
}
while(i < middlePoint){
temp[k] = data[i];
i++;
k++;
}
//copy it back to data
for(int c = 0; c < (upper-lower); c++){
data[lower+c] = temp[c];
}
}
bool stringToInt(const char input[], int& value) {
enum state{ gotSign, gotNum, Done, Reject, Start};
state conversion = Start;
if (input[0] == 0 ){
//cout << "rejection" << endl;
return false;
}
int i = 0;
int num = 0;
int sign = 1; //pos by default
while (input[i] != 0){ //is the input nan
switch(conversion){
case Start:
if ( (input[i] == '-') || (input[i] == '+') )
conversion = gotSign;
else if ( (input[i] >= '0') && (input[i] <= '9') )
conversion = gotNum;
else{
conversion = Reject;
}
break;
case gotSign:
if ( input[i] == '+'){
sign = 1;
conversion = gotNum;
i++;
} else{
sign = -1;
conversion = gotNum;
i++;
}
break;
case gotNum:
if ( (input[i] >= '0') && (input[i] <= '9') &&
num <= (INT_MAX -input[i] + 48)/10){ //assume its a positive number
num *= 10; //multiply the previous number by 10
num += (input[i] - 48); //ascii value of 0 is 48.
i++;
} else {
conversion = Reject;
}
break;
case Reject:
if ( num == 214748364 && sign == -1 ){
if (input[i] == '8' && input[i+1] == 0){
value = INT_MIN;
return true;
}
}
return false;
break;
} // switch loop
}//while loop
value = sign * num;
return true;
}
char* stringConcat(const char base[] , const char exten[]){
if (base == NULL){
return NULL;
}
char* myString = new char[40];
int index = 0; //count how many index values we are at
for (;base[index] != 0; index++){ //copy base
myString[index] = base[index];
//cout << myString[index] << endl;
}
// now index is pointing to an empty area due to the for loop running one more time
// abc .txt
for(int i = 0; exten[i] != 0; i++){ // copy
myString[index] = exten[i];
index++;
}
myString[index+1] = 0;
return myString;
}
char* stringCut(const char base[]){
// cut out the .ext
if (base == NULL){
return NULL;
}
char* cutString = new char[40];
int i = 0;
for (; base[i] != 0; i++){
if (base[i] == '.'){
cutString[i]= 0;
} else {
cutString[i] = base[i];
}
}
cutString[i] = 0;
return cutString;
}
//STATISTICS
/////////////////////////////////////////////////////////////////////
int minimum(const int dataset[], const int size) {
int c = 1 ; //starting at index value 1 since 0 is already done
int minVal = dataset[0];
while(c < size){
if (dataset[c] < minVal){
minVal = dataset[c];
}
c++ ;
}
return minVal;
}
float average(const int dataset[], const int size) {
int c = 0; //counter
float total = 0;
while (c < size){
total += dataset[c];
c++;
}
return (total/size);
}
int maximum(const int dataset[], const int size) {
int c = 1 ; //starting at index value 1 since 0 is already done
int maxVal = dataset[0];
while(c < size){
if (dataset[c] > maxVal){
maxVal = dataset[c];
}
c++ ;
}
return maxVal;
}
float popStdDev(const int dataset[], const int size) {
int x = 0; //counter
float variance = 0;
float av = average(dataset, size);
while (x < size){
variance += (dataset[x]-av)*(dataset[x]-av);
//cout << variance << endl;
x++;
}
return sqrt(variance/size);
}
float smplStdDev(const int dataset[], const int size) {
int x = 0; //counter
float variance = 0;
float av = average(dataset, size);
while (x < size){
variance += (dataset[x]-av)*(dataset[x]-av);
//cout << variance << endl;
x++;
}
return sqrt(variance/(size-1));
}
void histogram(const int dataset[], const int size, int histogram[]){
int bucket;
for (int i = 0; i < 10; i++){
histogram[i] = 0;
}
// initialize histogram to 0
for (int i = 0; i < size; i++){
bucket = dataset[i] / 10;
if (bucket >= 10){ //100%
bucket--;
}
histogram[bucket]++;
}
}
int mode(const int dataset[], const int size, Mode& modeStruct){
modeStruct.modes = new int[size];
int*& newNameforModeArray = modeStruct.modes;
// declare the mode array as another name
int copyDataset[size];
for(int i = 0; i < size; i++){
copyDataset[i] = dataset[i];
}
sort(copyDataset,size);
if (size == 1){
newNameforModeArray[0] = dataset[0];
modeStruct.numModes = 1;
return 0;
}
// struct Mode{
// int numModes;
// int* modes;
// };
modeStruct.numModes = modHelper(copyDataset,size,newNameforModeArray,1,1,1,0);
//cout << modeStruct.numModes << endl;
return 0;
}
int modHelper(const int data[], const int size,int mode[] ,int currentIndex,
int currentRep, int maxRep, int indOfMod){ //max rep and current start at 1 num Of Mod starts at 0
if (currentIndex > (size-1)){ // base case
return (indOfMod+1); // since it is an index
}
if (data[currentIndex] != data[currentIndex -1]){ // one number is not gonna break the record
if ((currentRep == maxRep) && (maxRep == 1)){//technically everyone is a mod when the max is 1
if (currentIndex == 1){ //to start off the first number
mode[0] = data[0];
}
indOfMod++; //about the make an other entry
mode[indOfMod] = data[currentIndex]; // set number as the next mod
//reset the currentRep only
return modHelper(data,size,mode,currentIndex+1, 1, maxRep, indOfMod);
}
else{ //rejected number because below record
return modHelper(data,size,mode,currentIndex+1, 1, maxRep,indOfMod);
}
}
else{//if the number is equal to the previous
currentRep++; //repetition starts ONLY INCREMENT IT HERE
}
if (currentRep > maxRep){ //beating the record (might continue to beat the record)
mode[0] = data[currentIndex]; // set it as the new champ indOfMod = 0 rep++
return modHelper(data,size,mode, currentIndex+1, currentRep, currentRep,0);
// it will reset if the record is beaten again.
}
else if (currentRep == maxRep){ //just equalized the record
indOfMod++;
mode[indOfMod] = data[currentIndex];
//
return modHelper(data,size,mode,currentIndex+1, currentRep, maxRep,indOfMod);
}
else{//not record breaking... nothing interesting
return modHelper(data,size,mode, currentIndex+1, currentRep, maxRep, indOfMod);
}
}
int computeStatistics(Dataset& data, Statistics& stats){
int size = data.numStudents;
if(size <= 0){ //error check
return -1;
}
int gradeArray[size];
for (int i = 0; i < size; i++){
gradeArray[i] = data.students[i].grade;
}
stats.maximum = maximum(gradeArray,size);
stats.minimum = minimum(gradeArray,size);
stats.average = average(gradeArray,size);
stats.smplStdDev = smplStdDev(gradeArray,size);
stats.popStdDev = popStdDev(gradeArray,size);
histogram(gradeArray,size,stats.histogram);
mode(gradeArray,size,stats.mode);
return 0;
}
//READ
///////////////////////////////////////////////////////////////////
int readSCVHelp(char inputLine [],int& lineNum,Rejects& rejectionStruct,
const int minAcceptableID, const int maxAcceptableID, Dataset& dataStruct){
enum readingState {WSbID,WSaID,WSbGrade,WSaGrade,commas,ID,SCORE,ERROR,DONE,SKIP};
const int maxNumErrors = 10; //max numbers of error
int i = 0; //counter
char num[20];
int numInd = 0;
char grade[20];
char gradeInd= 0;
int myNum;
int myGrade;
int fnRes; // function result
readingState cancerInput = WSbID; //cancerInput is my state :)
//start with WhiteSpaces;
if (inputLine[0] == 0){ //if empty next line skip...
cancerInput = SKIP;
}
while (inputLine[i] != 0 ){
switch (cancerInput){
case WSbID: //if blank line I error it.
if ( (inputLine[i] == 9) || (inputLine[i] == ' ') ){ // 9= tab
i++;//next
}
else if ( (inputLine[i] >= '0') && (inputLine[i] <= '9') ){
cancerInput = ID;
}
else if ((inputLine[i] < 0)){
i++; //a weird error im having so move on
}
else if (inputLine[i+1] ==0){ //if the next char is 0; this is a blank space line
cancerInput = SKIP;
}
else{
cancerInput = ERROR;
}
break;
case WSaID:
if ( (inputLine[i] == 9) || (inputLine[i] == ' ') ){ // 9= tab
i++; //next
}
else if ( inputLine[i] == ',' ){
cancerInput = commas;
//cout << "commas detected" << endl;
} else {
cancerInput = ERROR;
}
break;
case WSbGrade:
if ( (inputLine[i] == 9) || (inputLine[i] == ' ') ){ // 9= tab
i++;//next
}
else if (( (inputLine[i] >= '0') && (inputLine[i] <= '9') ) || (inputLine[i] == '-') ){
//cout << "grade detected..." << endl;
cancerInput = SCORE;
} else {
cancerInput = ERROR;
}
break;
case WSaGrade:
if (inputLine[i+1] == 0){
cancerInput = DONE; //it is done!
inputLine[i] == 0; //break
}
//still want to check
if ( (inputLine[i] == 9) || (inputLine[i] == ' ') || (inputLine[i] == '\r' ) ){ // 9= tab
i++;//next
}
// else if ( (inputLine[i] == ',') || ( (inputLine[i] >='0') && (inputLine[i] <='9') ) ){
// cancerInput = ERROR;
//will run to error again next time since no i++;
// }
else{
cancerInput = ERROR;
}
break;
case commas:
if (inputLine[i] == ','){
cancerInput = WSbGrade;
i++;
//cout << "commas case reached" << endl;
} else{
cancerInput = ERROR;
}
break;
case ID:
if (( (inputLine[i] >= '0') && (inputLine[i] <= '9') ) || (inputLine[i] == '-') ){
//cout << "number detected: " << inputLine[i] << endl;
num[numInd] = inputLine[i];
numInd++;
i++;
if (numInd > 20){
cancerInput = ERROR;
}
if (inputLine[i] == 0){
cancerInput = ERROR;
}
}
else if ((inputLine[i] == 9) || (inputLine[i] == ' ') || (inputLine[i] == ',') ){
//cout << "end of the ID reading..." << in << endl;
//asci to integer;
//so gimme that null terminator
num[numInd] = 0;
fnRes = stringToInt(num,myNum);
//if false exit
if (fnRes == false)
{
cancerInput = ERROR; //maybe just reject it
//return -1;
}
//cout << "Id..." << myNum << endl;
//------------------------------------//
if ( (myNum > maxAcceptableID) || (myNum < minAcceptableID) ){
//num out of bound
cancerInput = ERROR;
} else{
cancerInput = WSaID;
}
}
// else if(in == ','){
// cancerInput = commas;
else{ // if nothing goes
cancerInput = ERROR;
}
break;
case SCORE:
if (( (inputLine[i] >= '0') && (inputLine[i] <= '9') ) || (inputLine[i] == '-') ){
//cout << "grade detected: " << inputLine[i] << endl;
grade[gradeInd] = inputLine[i];
gradeInd++;
if (gradeInd > 5){
cancerInput = ERROR;
inputLine[i] = 100;
}
//if too many numbers
i++;
//char next = inputLine[i];
//cout << "next char " <<(int)next << endl;
if (inputLine[i] == 0){ //already over
grade[gradeInd] = 0;
fnRes = stringToInt(grade,myGrade);
if (fnRes == false){
cancerInput = ERROR;
inputLine[i] = 100;
//return -1;
}
//cout << "mygrade saved is" << myGrade << endl;
//------------------------------------//
if ( (myGrade > 100) || (myGrade < 0) ){
//num out of bound
cancerInput = ERROR;
inputLine[i] = 100; // make sure the error goes thru
} else{
cancerInput = DONE;
}
}
}
else if ((inputLine[i] == 9) || (inputLine[i] == ' ') || (inputLine[i] == '\r') ){
//NASTY BUG here 98,
//asci to integer
grade[gradeInd] = 0; //null terminationbb
fnRes = stringToInt(grade,myGrade);
if (fnRes == false){
cancerInput == ERROR;
//return -1
}
//cout << "mygrade is" << myGrade << endl;
//------------------------------------//
else if ( (myGrade > 100) || (myGrade < 0) ){
// num out of bound
cancerInput = ERROR;
} else{
cancerInput = WSaGrade;
}
}
else{ // if nothing goes
cancerInput = ERROR;
//return -1;
}
break;
case ERROR:
//cout << "ERROR LINE!!!!!s " << lineNum << endl;
rejectionStruct. rejects[rejectionStruct.numRejects]= lineNum;
rejectionStruct. numRejects++;
inputLine[i] = 0;//break
break;
case SKIP:
lineNum--;
return 0;
break;
}//switch loop
}//whileloop
if ( cancerInput == DONE){
dataStruct.students[dataStruct.numStudents].studentID = myNum; //fill student struc
dataStruct.students[dataStruct.numStudents].grade= myGrade;
dataStruct.numStudents++; // add one student;
}
else if ((cancerInput != ERROR) && (cancerInput != SKIP)){
rejectionStruct. rejects[rejectionStruct.numRejects]= lineNum;
rejectionStruct. numRejects++;
}
return 0;
}
int readCSV(const char filename[],const int minAcceptableID,
const int maxAcceptableID,Dataset& data,
Rejects& rejects) {
if (filename == NULL){
return -1;
}
char* betterName;
bool extDetected = false; //abc
for (int i = 0; filename[i] != 0 ; i++){
if (filename[i] == '.'){
extDetected = true; //abc.csv
}
}
///////////////////////////////////////////
betterName = stringConcat(filename,".csv");
/////////////////////////////////////////////////////////////////////
const int maxLineLength = 500;
char line[maxLineLength];
ifstream infile;
// declare the file object
//cout << betterName << endl;
for (int i = 0; i < 20 ; i++){
//cout << betterName[i] << endl;
}
if(!extDetected){
infile.open(betterName);
} else{
infile.open(filename);
}
// open the file
if (!infile.is_open()) //if the file isnt open
return -2;
// Unable to open filebool done = false;
int fileLineNumber = 1;
bool imDone = false; //not Done yet
const int maxNumErrors = 9; //max numbers of error
int res; // res for the result of helper function
rejects. rejects = new int[10]; //reject array maximum 10 give one more for error purposes
rejects. numRejects = 0;
data. numStudents = 0;
data. students = new Student[50];
while (!imDone) {
if (minAcceptableID > maxAcceptableID){
data.numStudents = 0;
data. students = NULL;
return -1;
//error checking
}
if (rejects.numRejects > maxNumErrors-1){
data.numStudents = 0;
data. students = NULL;
return -1;
// if more than
}//error checking again
//cout << rejects.numRejects << endl;
// Read from file++fileLineNumber;
if (!infile.getline(line, maxLineLength)) {
// Get next line in my array
//will return false if can't store it
if (infile.eof()) {
imDone = true; //exit on the if statement
//End of filedone = true;
}else {
// Some error reading file
data.numStudents = 0;
data. students = NULL;
return -1;
}
}
if (!imDone){
//cout << "processing.. " << line << endl;
res =readSCVHelp(line,fileLineNumber,rejects, minAcceptableID,maxAcceptableID, data);
if(res == -1){
data.numStudents = 0;
data. students = NULL;
return -1;
// error have to exit
}
//increment lineCount
fileLineNumber++;
}//if loop
}//while
infile.close();
if (rejects.numRejects == 0){
return 0;
} else{
return 1;
}
}
//WRITE
///////////////////////////////////////////////////////////
int writeCSV(const char filename[], const Statistics& stats){
char* betterName = stringCut(filename);
betterName = stringConcat(betterName,".stat");
//cout << betterName << endl;
ofstream output;
output.open(betterName);
// }
if(!output.is_open()){
return -1;
}
output << "Minimum: " << stats.minimum << "\n";
output << "Average: "<< stats.average << "\n";
output << "Maximum: "<< stats.maximum << "\n";
output << "Population Standard Deviation: " << stats.popStdDev<< "\n";
output << "Sample Standard Deviation: "<< stats.smplStdDev<< "\n";
output << "Modes: ";
for (int i = 0; i < stats.mode.numModes; i++){
output << stats.mode.modes[i];
if( (i+1) < stats.mode.numModes ){
output << ", ";
}
}
output << "\n";
output << "Histogram:" << "\n";
for (int i = 0; i < 10; i++){
output << "[" << i*10 << "-" << ( (i+1)* 10 )-1 + i/9 << "]: " ;
output << stats.histogram[i]<< "\n";
}
output.close();
return 0;
}
//////////////////////////////////////////////////////////////
//
// Test Driver
//
// Do not remove the #ifndef and its associated #endif
//
#ifndef MARMOSET_TESTING
#define isNaN(X) (X != X) // NaN is the only float that is not equal to itself
int main(const int argc, const char* const argv[]) {
// Some test driver code here ....
int minAcceptableID = 22200000;
int maxAcceptableID = 22299999;
Dataset data = {0};
Rejects rejects = {0};
Statistics stats = {0};
std::cout << std::endl << "Implement some more appropriate tests in main()" << std::endl << std::endl;
if(readCSV("inputfile.csv", minAcceptableID, maxAcceptableID, data, rejects) < 0)
{
std::cout << ".csv file could not be read" << std::endl;
}
if (computeStatistics(data, stats) < 0)
{
std::cout << "Stats could not be computed" << std::endl;
}
if (writeCSV("inputfile", stats) < 0)
{
std::cout << ".stat file could not be written" << std::endl;
}
std::cout << "Minimum: " << stats.minimum << std::endl;
std::cout << "Average: " << stats.average << std::endl;
std::cout << "Maximum: " << stats.maximum << std::endl;
std::cout << "Population standard deviation: " << stats.popStdDev << std::endl;
std::cout << "Sample standard deviation: " << stats.smplStdDev << std::endl;
for (unsigned char i = 0; i < stats.mode.numModes; i++)
{
std::cout << "Mode: " << stats.mode.modes[i] << std::endl;
}
for (unsigned char i = 0; i < 10; i++)
{
std::cout << "Histogram bin [" << (i*10) << ", " << ((((i+1)*10) - 1) + i/9) << "]: " << stats.histogram[i] << std::endl;
}
// struct Student{
// int studentID;
// int grade;
// };
// struct Dataset{
// int numStudents;
// Student* students;
// };
for(int i = 0; i < data.numStudents;i++){
cout << data.students[i].studentID << endl;
cout << data.students[i].grade << endl;
}
for(int i = 0 ; i < rejects.numRejects; i++){
cout << rejects.rejects[i] << endl;
}
return 0;
}
#endif