Skip to content

Commit a15988a

Browse files
major update
1. structures are now global in header file. 2. they will be initiated, at the once. 3. removed redundant functions in header file.
1 parent dc666ea commit a15988a

File tree

3 files changed

+51
-67
lines changed

3 files changed

+51
-67
lines changed

NUB Admission Costing Calculator/main.c

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ void display_result(const char *message);
99
void show_undergraduate(GtkWidget *widget, gpointer data);
1010
void show_diploma(GtkWidget *widget, gpointer data);
1111

12-
// Function to create and show undergraduate interface
12+
// Function to create and show undergraduate and diploma interface
1313
void create_undergraduate_interface(GtkWidget *container);
14-
15-
// Function to create and show diploma interface
1614
void create_diploma_interface(GtkWidget *container);
1715

1816
// Global variables
@@ -173,63 +171,48 @@ void on_submit_button_clicked(GtkWidget *widget, gpointer data)
173171
// Clear the text view
174172
gtk_text_buffer_set_text(result_buffer, "", -1);
175173

176-
// Calling the appropriate function based on the selected department
177-
struct Undergraduate ug = {
178-
.BBA = BBA,
179-
.LLB = LLB,
180-
.EEE = EEE,
181-
.Textile = Textile,
182-
.CSE = CSE,
183-
.Civil = Civil,
184-
.ME = ME,
185-
.ECE = ECE,
186-
.B_Pharm = B_Pharm,
187-
.ELL = ELL,
188-
.Bangla = Bangla
189-
};
190-
191174
if (strcmp(selected_department, "BBA") == 0)
192175
{
193-
ug.BBA(ssc, hsc, display_result);
176+
UG.BBA(ssc, hsc, display_result);
194177
}
195178
else if (strcmp(selected_department, "LLB") == 0)
196179
{
197-
ug.LLB(display_result);
180+
UG.LLB(display_result);
198181
}
199182
else if (strcmp(selected_department, "EEE") == 0)
200183
{
201-
ug.EEE(ssc, hsc, display_result);
184+
UG.EEE(ssc, hsc, display_result);
202185
}
203186
else if (strcmp(selected_department, "Textile") == 0)
204187
{
205-
ug.Textile(ssc, hsc, display_result);
188+
UG.Textile(ssc, hsc, display_result);
206189
}
207190
else if (strcmp(selected_department, "CSE") == 0)
208191
{
209-
ug.CSE(ssc, hsc, display_result);
192+
UG.CSE(ssc, hsc, display_result);
210193
}
211194
else if (strcmp(selected_department, "Civil") == 0)
212195
{
213-
ug.Civil(ssc, hsc, display_result);
196+
UG.Civil(ssc, hsc, display_result);
214197
} else if (strcmp(selected_department, "ME") == 0)
215198
{
216-
ug.ME(ssc, hsc, display_result);
199+
UG.ME(ssc, hsc, display_result);
217200
}
218201
else if (strcmp(selected_department, "ECE") == 0)
219202
{
220-
ug.ECE(ssc, hsc, display_result);
203+
UG.ECE(ssc, hsc, display_result);
221204
}
222205
else if (strcmp(selected_department, "B_Pharm") == 0)
223206
{
224-
ug.B_Pharm(display_result);
207+
UG.B_Pharm(display_result);
225208
}
226209
else if (strcmp(selected_department, "ELL") == 0)
227210
{
228-
ug.ELL(ssc, hsc, display_result);
211+
UG.ELL(ssc, hsc, display_result);
229212
}
230213
else if (strcmp(selected_department, "Bangla") == 0)
231214
{
232-
ug.Bangla(ssc, hsc, display_result);
215+
UG.Bangla(ssc, hsc, display_result);
233216
}
234217

235218
g_free((gpointer)selected_department);
@@ -295,39 +278,29 @@ void D_on_submit_button_clicked(GtkWidget *widget, gpointer data)
295278
// Clear the text view
296279
gtk_text_buffer_set_text(result_buffer, "", -1);
297280

298-
// Calling the appropriate function based on the selected department
299-
struct UndergraduateDiploma ugd= {
300-
.EEE = D_EEE,
301-
.Textile = D_Textile,
302-
.CSE = D_CSE,
303-
.Civil = D_Civil,
304-
.ME = D_ME,
305-
.ECE = D_ECE,
306-
};
307-
308281
if (strcmp(selected_department, "EEE") == 0)
309282
{
310-
ugd.EEE(diploma, display_result);
283+
UGD.EEE(diploma, display_result);
311284
}
312285
else if (strcmp(selected_department, "Textile") == 0)
313286
{
314-
ugd.Textile(diploma, display_result);
287+
UGD.Textile(diploma, display_result);
315288
}
316289
else if (strcmp(selected_department, "CSE") == 0)
317290
{
318-
ugd.CSE(diploma, display_result);
291+
UGD.CSE(diploma, display_result);
319292
}
320293
else if (strcmp(selected_department, "ECE") == 0)
321294
{
322-
ugd.ECE(diploma, display_result);
295+
UGD.ECE(diploma, display_result);
323296
}
324297
else if (strcmp(selected_department, "Civil") == 0)
325298
{
326-
ugd.Civil(diploma, display_result);
299+
UGD.Civil(diploma, display_result);
327300
}
328301
else if (strcmp(selected_department, "ME") == 0)
329302
{
330-
ugd.ME(diploma, display_result);
303+
UGD.ME(diploma, display_result);
331304
}
332305

333306
g_free((gpointer)selected_department);
@@ -342,4 +315,4 @@ void display_result(const char *message)
342315

343316
// Debug print
344317
printf("Displaying result: %s\n", message);
345-
}
318+
}

NUB Admission Costing Calculator/test.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ void Bangla(float SSC, float HSC, ResultCallback callback)
336336
waiver = TC = year = semester = credit = 0;
337337
}// End of definition of struct Undergraduate
338338

339+
339340
// Definition of Struct UndergraduateDiploma starts from here
340341
void D_EEE(float DiplomaResult, ResultCallback callback)
341342
{
@@ -450,4 +451,28 @@ void D_ME(float DiplomaResult, ResultCallback callback)
450451
}
451452
D_Display(callback);
452453
TC = year = semester = credit = 0;
453-
}// End of definition of struct UndergraduateDiploma
454+
}// End of definition of struct UndergraduateDiploma
455+
456+
// Initialize the structs with function pointers
457+
struct Undergraduate UG = {
458+
.BBA = BBA,
459+
.LLB = LLB,
460+
.EEE = EEE,
461+
.Textile = Textile,
462+
.CSE = CSE,
463+
.Civil = Civil,
464+
.ME = ME,
465+
.ECE = ECE,
466+
.B_Pharm = B_Pharm,
467+
.ELL = ELL,
468+
.Bangla = Bangla
469+
};
470+
471+
struct UndergraduateDiploma UGD = {
472+
.EEE = D_EEE,
473+
.Textile = D_Textile,
474+
.CSE = D_CSE,
475+
.ECE = D_ECE,
476+
.Civil = D_Civil,
477+
.ME = D_ME
478+
};

NUB Admission Costing Calculator/test.h

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <gtk/gtk.h>
1010
#include <stdbool.h>
1111

12+
// Utility fuctions
1213
// The function prototype for the display callback
1314
typedef void (*ResultCallback)(const char *);
1415
void getwaiver(float SSC, float HSC);
@@ -17,18 +18,6 @@ void replace_placeholder(char *buffer, const char *placeholder, const char *valu
1718
void Display(ResultCallback callback);
1819
void D_Display(ResultCallback callback);
1920

20-
void BBA(float SSC, float HSC, ResultCallback callback);
21-
void LLB(ResultCallback callback);
22-
void EEE(float SSC, float HSC, ResultCallback callback);
23-
void Textile(float SSC, float HSC, ResultCallback callback);
24-
void CSE(float SSC, float HSC, ResultCallback callback);
25-
void Civil(float SSC, float HSC, ResultCallback callback);
26-
void ME(float SSC, float HSC, ResultCallback callback);
27-
void ECE(float SSC, float HSC, ResultCallback callback);
28-
void B_Pharm(ResultCallback callback);
29-
void ELL(float SSC, float HSC, ResultCallback callback);
30-
void Bangla(float SSC, float HSC, ResultCallback callback);
31-
3221
struct Undergraduate
3322
{
3423
void (*BBA)(float SSC, float HSC, ResultCallback callback);
@@ -44,13 +33,6 @@ struct Undergraduate
4433
void (*Bangla)(float SSC, float HSC, ResultCallback callback);
4534
};
4635

47-
void D_EEE(float DiplomaResult, ResultCallback callback);
48-
void D_Textile(float DiplomaResult, ResultCallback callback);
49-
void D_CSE(float DiplomaResult, ResultCallback callback);
50-
void D_ECE(float DiplomaResult, ResultCallback callback);
51-
void D_Civil(float DiplomaResult, ResultCallback callback);
52-
void D_ME(float DiplomaResult, ResultCallback callback);
53-
5436
struct UndergraduateDiploma
5537
{
5638
void (*EEE)(float DiplomaResult, ResultCallback callback);
@@ -61,4 +43,8 @@ struct UndergraduateDiploma
6143
void (*ME)(float DiplomaResult, ResultCallback callback);
6244
};
6345

64-
#endif
46+
// Declare the global struct for Undergraduate and UndergraduateDiploma
47+
extern struct Undergraduate UG;
48+
extern struct UndergraduateDiploma UGD;
49+
50+
#endif

0 commit comments

Comments
 (0)