-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.c
186 lines (157 loc) · 3.89 KB
/
process.c
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
/***********************/
/* FTE calculator */
/* Dr. Sherif F. Fahmy */
/***********************/
#include <stdio.h>
#include <string.h>
/*Without the include below, code will not work*/
#include <stdlib.h>
typedef struct{
char rank[50];
int hours;
}ranks;
typedef struct{
char name[60];
char level[50];
int hours;
int FT;
char dept[3];
int tenure;
}faculty_m;
float FTE=0; //the final FTE value, total
ranks x[5]; //table of ranks
float PT_tenure_FTE=0;
float PT_nonten_FTE=0;
float FT_tenure_FTE=0;
float FT_nonten_FTE=0;
float tenure_FTE=0;
float nonten_FTE=0;
int tenure = 0;
int non_tenure =0;
/************************/
/* fill ranks array */
/************************/
void fillranks(ranks *input){
strcpy(input[0].rank,"Prof.");
input[0].hours=10;
strcpy(input[1].rank,"Teacher");
input[1].hours=16;
strcpy(input[2].rank,"Asc. Prof");
input[2].hours=14;
strcpy(input[3].rank,"TA");
input[3].hours=18;
strcpy(input[4].rank,"MM");
input[4].hours=4;
}
/***********************/
/* get hours for rank */
/***********************/
int gethours(char *rank,ranks *x){
int i;
for(i=0; i<5; i++){
if (strcmp(rank,x[i].rank)==0){
return x[i].hours;
}
}
return -1;
}
/************************/
/* process one line */
/************************/
void processline(char *line){
int i=0;
char *token,sep[3]=",\n";
faculty_m a;
token=strtok(line,sep);
while(token!=NULL){
i++;
switch(i){
case 1: strcpy(a.name,token);
break;
case 2: strcpy(a.level,token);
break;
case 3: a.hours=atoi(token);
break;
case 5: if (strcmp(token,"FT")==0)
a.FT=1;
else
a.FT=0;
break;
case 6: strcpy(a.dept,token);
break;
case 7: if (strcmp(token,"NT")!=0)
a.tenure=1;
else
a.tenure=0;
}
token=strtok(NULL,sep);
}
if (a.FT==1 && strcmp(a.dept,"CE")==0){ //full time faculty member in department is one FTE
FTE+=1; //total FTE
//this part is just being added, mind blown
if (a.tenure==1){ //because not all fulltimers are tenured, eg Wahdan & Ashraf
tenure_FTE+=1;
FT_tenure_FTE++;
tenure++;
}else{
nonten_FTE++;
FT_nonten_FTE++;
non_tenure++;
}
}else{ //none CE faculty members, less than one FTE
if (a.hours>0){ //teaches in CE program
float value=(float)a.hours/gethours(a.level,x); //get fraction of FTE
//here we handle the many new cases that I discovered we need in the report
if (a.tenure==1 && a.FT==1){
FT_tenure_FTE+=value;
//tenure++;
} else if (a.tenure==0 && a.FT==1){
FT_nonten_FTE+=value;
//non_tenure++;
} else if (a.tenure==1 && a.FT==0){
PT_tenure_FTE+=value;
//tenure++;
puts(a.name);
puts("panic!!!");
}
else if (a.tenure==0 && a.FT==0){
PT_nonten_FTE+=value;
//non_tenure++;
}
FTE+=value; //add fraction to total FTE
if(a.tenure==1){ //distribute to either tenured or none tenured
tenure_FTE+=value; //eg, Hadi, tenured but not 1 FTE in CE
tenure++;
}else{
nonten_FTE+=value; //example Mahmoud Khaleel
non_tenure++;
}
}
}
}
int main(){
char filename[50]; //filename
FILE *p; //file pointer
char line[90]; //line read from file
fillranks(x);
strcpy(filename,"data.txt");
//open the file
p=fopen(filename,"r");
if(p==NULL){
puts("Could not find file, exiting program\n");
return -1;
}
while(!feof(p)){
fgets(line,90,p); //read a line
processline(line); //process it
}
printf("The total FTE so far is %f\n",FTE);
printf("No of tenured faculty %d, with FTE %f\n",tenure,tenure_FTE);
printf("No of non-tenured faculty %d, with FTE %f\n",non_tenure,nonten_FTE);
printf("Pt tenured %f\n",PT_tenure_FTE);
printf("Pt non-tensure %f\n",PT_nonten_FTE);
printf("Ft tenured %f\n",FT_tenure_FTE);
printf("Ft non-tenured %f\n",FT_nonten_FTE);
fclose(p);
return 0;
}