Skip to content

Commit c99bef8

Browse files
committed
Final changes
1 parent a0a269e commit c99bef8

File tree

8 files changed

+48
-102
lines changed

8 files changed

+48
-102
lines changed

data/SCHS21-1.csv

-56
This file was deleted.

data/output.csv

-24
This file was deleted.

include/resource.h

-5
This file was deleted.

mark

-85.5 KB
Binary file not shown.

source/getopt.c source/getopt.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
#include <string.h>
44
#include <stdio.h>
5-
5+
66
int opterr = 1, /* if error message should be printed */
77
optind = 1, /* index into parent argv vector */
88
optopt, /* character checked for validity */
99
optreset; /* reset getopt */
1010
char *optarg; /* argument associated with option */
11-
11+
1212
#define BADCH (int)'?'
1313
#define BADARG (int)':'
1414
#define EMSG ""
15-
15+
1616
/*
1717
* getopt --
1818
* Parse argc/argv argument vector.
1919
*/
20-
int getopt(int nargc, char * const nargv[], const char *ostr)
20+
int getopt(int nargc, char * const *nargv, const char *ostr)
2121
{
2222
static char *place = EMSG; /* option letter processing */
2323
const char *oli; /* option letter list index */
24-
24+
2525
if (optreset || !*place) { /* update scanning pointer */
2626
optreset = 0;
2727
if (optind >= nargc || *(place = nargv[optind]) != '-') {
@@ -70,4 +70,4 @@ int getopt(int nargc, char * const nargv[], const char *ostr)
7070
++optind;
7171
}
7272
return (optopt); /* dump back option letter */
73-
}
73+
}

source/harrizcsv.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@
33
bool HarrizCSV::read(const char* lpFn)
44
{
55
strcpy(_file_path, lpFn);
6-
cout << "Reading file (harriz): \"" << _file_path << "\"" << endl;
6+
cout << "Reading file (harriz): \"" << _file_path << "\"" << endl;
77
ifstream file;
88
file.open(_file_path);
99
char line_buffer[MAX_ROW_LENGTH] = "";
1010

11+
if(!file.good() || file.eof()){
12+
cout <<"BAD FILE!!!!!!" << endl;
13+
return false;
14+
}
15+
else
16+
cout << "Good file." << endl;
17+
1118
file.getline(line_buffer, MAX_ROW_LENGTH);
1219

1320
bool start_reading = false;
1421

1522
while(!file.eof() && file.good())
1623
{
17-
if(strcmp(line_buffer, "Type") >= 4 && start_reading == false)
24+
if(strncmp(line_buffer, "Type", 4) == 0 && start_reading == false)
1825
{
1926
// Initialize headers and tell to start reading
2027
char* pch = strtok(line_buffer, ";");
@@ -53,4 +60,4 @@ bool HarrizCSV::read(const char* lpFn)
5360
vector<char*> *HarrizCSV::headers()
5461
{
5562
return &_headers;
56-
}
63+
}

source/main.cpp

+24-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
#include "../include/harrizcsv.h"
22
#include "../include/mark.h"
33
#include "../include/student.h"
4-
#include "../include/resource.h"
4+
#include <unistd.h>
55

66
using namespace std;
77

88
int main(int argc, char **argv)
99
{
10+
cout << getcwd(0,0) << endl;
1011
char *lpFn = new char[1024];
1112
char *only = new char[256];
1213
char *exclude = new char[256];
1314
char *outputFn = new char[1024];
1415

1516
strcpy(lpFn, "data/SCHS21-1.csv");
1617
strcpy(outputFn, "data/output.csv");
18+
strcpy(only, "");
19+
strcpy(exclude, "");
1720

1821
int n_terms = 0;
1922
char c;
20-
while((c = getopt(argc, argv, ":f:n:e:i")) != -1)
23+
while((c = getopt(argc, argv, ":f:n:e:i:o")) != -1)
2124
{
2225
switch(c)
2326
{
@@ -33,6 +36,9 @@ int main(int argc, char **argv)
3336
case 'i':
3437
strncpy(only, optarg, 256);
3538
break;
39+
case 'o':
40+
strncpy(outputFn, optarg, 256);
41+
break;
3642
case '?':
3743
if(optopt == 'f' || optopt == 'n' || optopt == 'e' || optopt == 'i')
3844
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
@@ -70,7 +76,7 @@ int main(int argc, char **argv)
7076
strcpy(new_student->a, columns->at(1));
7177
for(int col = 2; col < columns->size(); col++)
7278
{
73-
if(strcmp(headers->at(col), "O.A") == 0)
79+
if(strncmp(headers->at(col), "O.A", 3) == 0)
7480
{
7581
new_student->OAs.push_back(Mark(columns->at(col)));
7682
}
@@ -154,8 +160,13 @@ int main(int argc, char **argv)
154160
outfile << student->OAs.at(iterm).to_int() << ";";
155161
for(int isum = 0; isum < n_summatives; isum++)
156162
outfile << student->Summatives.at(isum).to_int() << ";";
157-
for(int iex = 0; iex < n_exams; iex++)
158-
outfile << student->Exams.at(iex).to_int() << ";";
163+
for(int iex = 0; iex < n_exams; iex++) {
164+
int exmark = student->Exams.at(iex).to_int();
165+
if(exmark == -1000000)
166+
outfile << "A" << ";";
167+
else
168+
outfile << exmark << ";";
169+
}
159170
outfile << ";;" << student->term_mark(n_terms).to_int() << ";";
160171
outfile << student->final_mark(n_terms).to_int();
161172
outfile << endl;
@@ -182,8 +193,13 @@ int main(int argc, char **argv)
182193
outfile << student->OAs.at(iterm).to_int() << ";";
183194
for(int isum = 0; isum < n_summatives; isum++)
184195
outfile << student->Summatives.at(isum).to_int() << ";";
185-
for(int iex = 0; iex < n_exams; iex++)
186-
outfile << student->Exams.at(iex).to_int() << ";";
196+
for(int iex = 0; iex < n_exams; iex++) {
197+
int exmark = student->Exams.at(iex).to_int();
198+
if(exmark == -1000000)
199+
outfile << "A" << ";";
200+
else
201+
outfile << exmark << ";";
202+
}
187203
outfile << ";;" << student->term_mark(n_terms).to_int() << ";";
188204
outfile << student->final_mark(n_terms).to_int();
189205
outfile << endl;
@@ -193,4 +209,4 @@ int main(int argc, char **argv)
193209
outfile.close();
194210

195211
return 0;
196-
}
212+
}

source/mark.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
int str_to_int(char* str)
44
{
5+
if(str[0] == '-'){
6+
strcpy(str, str+1);
7+
strcat(str, "-");
8+
}
9+
if(str[0] == '+'){
10+
strcpy(str, str+1);
11+
strcat(str, "+");
12+
}
513
switch(str[0])
614
{
715
case 'R':

0 commit comments

Comments
 (0)