From 8c1db561bfa83a7f3e44accf4cdc42d249106f94 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 19:34:24 +0100 Subject: [PATCH 01/70] refactoring: Add function description --- src/convert_time.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/convert_time.c b/src/convert_time.c index 86d93ca..72a41c4 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -36,6 +36,7 @@ double converter_sec_in_hour(double sec){ return time; } +// Converts Days in Years double converter_days_to_years(double days){ double time = days / 365; return time; From 864272c3f440af7b81a700e5e0735c9a4e302a0e Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 19:39:20 +0100 Subject: [PATCH 02/70] added kg to g converter --- src/convert_kg_to_g.c | 6 ++++++ src/convert_kg_to_g.h | 13 +++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/convert_kg_to_g.c create mode 100644 src/convert_kg_to_g.h diff --git a/src/convert_kg_to_g.c b/src/convert_kg_to_g.c new file mode 100644 index 0000000..92bdd70 --- /dev/null +++ b/src/convert_kg_to_g.c @@ -0,0 +1,6 @@ + +#include "convert_kg_to_g.h" + +double kg_to_gram(double kilograms) { + return kilograms * 1000.0; // 1 kilogram = 1000 grams +} diff --git a/src/convert_kg_to_g.h b/src/convert_kg_to_g.h new file mode 100644 index 0000000..707a161 --- /dev/null +++ b/src/convert_kg_to_g.h @@ -0,0 +1,13 @@ + + +#ifndef THEADMIRALS_CONVERT_KG_TO_G_H +#define THEADMIRALS_CONVERT_KG_TO_G_H + + + + +double kg_to_gram(double kilograms); + + + +#endif //THEADMIRALS_CONVERT_KG_TO_G_H From 15c94f42b5a741e648271f6694e3e7bf5848bdf8 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 19:42:41 +0100 Subject: [PATCH 03/70] refactoring: Add function description --- src/convert_time.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/convert_time.c b/src/convert_time.c index 72a41c4..2114697 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -42,6 +42,7 @@ double converter_days_to_years(double days){ return time; } +// convert Years in days double converter_years_to_days(double years){ double amount = years * 365; return amount; From 89719003732da4c974e4df8c3a8937ed9118174e Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 19:48:33 +0100 Subject: [PATCH 04/70] added g to mg converter --- src/convert_g_to_mg.c | 6 ++++++ src/convert_g_to_mg.h | 13 +++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/convert_g_to_mg.c create mode 100644 src/convert_g_to_mg.h diff --git a/src/convert_g_to_mg.c b/src/convert_g_to_mg.c new file mode 100644 index 0000000..a7c17ad --- /dev/null +++ b/src/convert_g_to_mg.c @@ -0,0 +1,6 @@ + +#include "convert_g_to_mg.h" + +double g_to_mg(double grams) { + return grams * 1000.0; // 1 gram = 1000 milligrams +} diff --git a/src/convert_g_to_mg.h b/src/convert_g_to_mg.h new file mode 100644 index 0000000..557244a --- /dev/null +++ b/src/convert_g_to_mg.h @@ -0,0 +1,13 @@ + +#ifndef THEADMIRALS_CONVERT_G_TO_MG_H +#define THEADMIRALS_CONVERT_G_TO_MG_H + + + + + +double g_to_mg(double grams); + + + +#endif //THEADMIRALS_CONVERT_G_TO_MG_H From 7592aad08c6245e0f4fbca7d900ad16c6171218a Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 19:47:33 +0100 Subject: [PATCH 05/70] Expanded arithmetic division by long datatype --- src/arithmeticDivision.c | 9 +++++++++ src/arithmeticDivision.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/arithmeticDivision.c b/src/arithmeticDivision.c index 7cdfc7e..34949dd 100644 --- a/src/arithmeticDivision.c +++ b/src/arithmeticDivision.c @@ -14,4 +14,13 @@ int* division_integer(int dividend, int divisor) { int* result = malloc(sizeof(int)); *result = dividend / divisor; return result; +} + +long* division_long(long num1, long num2) { + if(num2 == 0) { + return NULL; + } + long* result = malloc(sizeof(long)); + *result = num1 / num2; + return result; } \ No newline at end of file diff --git a/src/arithmeticDivision.h b/src/arithmeticDivision.h index e4080b7..08bc4f5 100644 --- a/src/arithmeticDivision.h +++ b/src/arithmeticDivision.h @@ -3,4 +3,6 @@ int* division_integer(int, int); +long* division_long(long, long); + #endif //THEADMIRALS_ARITHMETICDIVISION_H From d5520c11a30aa3aaac24b33b127d84002804fab3 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 19:50:09 +0100 Subject: [PATCH 06/70] refactoring: changed variables for long method similar to integer method --- src/arithmeticDivision.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arithmeticDivision.c b/src/arithmeticDivision.c index 34949dd..dfdf00a 100644 --- a/src/arithmeticDivision.c +++ b/src/arithmeticDivision.c @@ -16,11 +16,11 @@ int* division_integer(int dividend, int divisor) { return result; } -long* division_long(long num1, long num2) { - if(num2 == 0) { +long* division_long(long dividend, long divisor) { + if(divisor == 0) { return NULL; } long* result = malloc(sizeof(long)); - *result = num1 / num2; + *result = dividend / divisor; return result; } \ No newline at end of file From 27265fab4bc9d4b3404c8b2cc084396d71b6820a Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:51:54 +0100 Subject: [PATCH 07/70] added convert cm into dm --- src/convert_cm_in_dm.c | 7 +++++++ src/convert_cm_in_dm.h | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 src/convert_cm_in_dm.c create mode 100644 src/convert_cm_in_dm.h diff --git a/src/convert_cm_in_dm.c b/src/convert_cm_in_dm.c new file mode 100644 index 0000000..4f0cf97 --- /dev/null +++ b/src/convert_cm_in_dm.c @@ -0,0 +1,7 @@ + +#include "convert_cm_in_dm.h" +#include + +double cm_to_dm(double cm) { + return cm / 10.0; +} diff --git a/src/convert_cm_in_dm.h b/src/convert_cm_in_dm.h new file mode 100644 index 0000000..eafecd9 --- /dev/null +++ b/src/convert_cm_in_dm.h @@ -0,0 +1,7 @@ + +#ifndef THEADMIRALS_CONVERT_CM_TO_DM_H +#define THEADMIRALS_CONVERT_CM_TO_DM_H + +double cm_to_dm(double cm); + +#endif //THEADMIRALS_CONVERT_CM_TO_DM_H From 8db1855f38bab98533cf30e4ab8a1791a0712d28 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:56:57 +0100 Subject: [PATCH 08/70] refactoring: description added --- src/convert_CM_in_M.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_CM_in_M.c b/src/convert_CM_in_M.c index bdc42ea..7898886 100644 --- a/src/convert_CM_in_M.c +++ b/src/convert_CM_in_M.c @@ -1,7 +1,7 @@ #include "convert_CM_in_M.h" #include -//convert length +//convert length for float float cm_to_meter(float cm) { return cm / 100.0; } From 4e5bd6d08493b7fe0ba83fe778644a76037e9664 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:57:36 +0100 Subject: [PATCH 09/70] refactoring: description added --- src/convert_cm_in_dm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_cm_in_dm.c b/src/convert_cm_in_dm.c index 4f0cf97..0db3d1a 100644 --- a/src/convert_cm_in_dm.c +++ b/src/convert_cm_in_dm.c @@ -1,7 +1,7 @@ #include "convert_cm_in_dm.h" #include - +//convert length for double double cm_to_dm(double cm) { return cm / 10.0; } From abf3fda0439688021a1ff705a6c2f3303d34a19a Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:58:14 +0100 Subject: [PATCH 10/70] refactoring: description added --- src/convert_M_in_KM.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_M_in_KM.c b/src/convert_M_in_KM.c index 966872e..cdc37a2 100644 --- a/src/convert_M_in_KM.c +++ b/src/convert_M_in_KM.c @@ -1,7 +1,7 @@ #include "convert_M_in_KM.h" #include -//convert length +//convert length for double double meter_to_kilometer(double meter) { return meter / 1000.0; } From c1c06df756625278e94ed693af185b8ec07688bf Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:58:46 +0100 Subject: [PATCH 11/70] refactoring: description added --- src/convert_M_in_KM.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_M_in_KM.c b/src/convert_M_in_KM.c index cdc37a2..2f8b0e3 100644 --- a/src/convert_M_in_KM.c +++ b/src/convert_M_in_KM.c @@ -1,7 +1,7 @@ #include "convert_M_in_KM.h" #include -//convert length for double +//convert length for double m into km double meter_to_kilometer(double meter) { return meter / 1000.0; } From fe2326799c60fbb79e61e9251b3cb353dcdd06bf Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:59:24 +0100 Subject: [PATCH 12/70] refactoring: description added --- src/convert_CM_in_M.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_CM_in_M.c b/src/convert_CM_in_M.c index 7898886..825caca 100644 --- a/src/convert_CM_in_M.c +++ b/src/convert_CM_in_M.c @@ -1,7 +1,7 @@ #include "convert_CM_in_M.h" #include -//convert length for float +//convert length for float cm into meter float cm_to_meter(float cm) { return cm / 100.0; } From 6a5d0dab7b3b9f07ade8ce2a799ec997950d49dd Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:59:47 +0100 Subject: [PATCH 13/70] refactoring: description added --- src/convert_cm_in_dm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_cm_in_dm.c b/src/convert_cm_in_dm.c index 0db3d1a..05d87e3 100644 --- a/src/convert_cm_in_dm.c +++ b/src/convert_cm_in_dm.c @@ -1,7 +1,7 @@ #include "convert_cm_in_dm.h" #include -//convert length for double +//convert length for double cm into dm double cm_to_dm(double cm) { return cm / 10.0; } From 668db497d6eeeb75edd2db6830bb5ff569185a8e Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:03:05 +0100 Subject: [PATCH 14/70] refactoring: description added --- src/arithmeticSubtraction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index ed08d04..e8af674 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -2,7 +2,7 @@ #include "arithmeticSubtraction.h" #include -//arithmetic Subtraction specification integer +//arithmetic Subtraction specification integer 1 function int* subtraction_integer(int a, int b) { int* result= malloc(sizeof (int)); *result=a - b; From 15db537e0cf604bef1e2c0f6a5280e24933c7167 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:03:21 +0100 Subject: [PATCH 15/70] refactoring: description added --- src/arithmeticSubtraction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index e8af674..363e792 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -8,7 +8,7 @@ int* subtraction_integer(int a, int b) { *result=a - b; return result; } -//arithmetic Subtraction specification float +//arithmetic Subtraction specification float 2 function float* subtraction_float(float a, float b) { float* result= malloc(sizeof (float)); *result=a - b; From 5a540e0f84cfb240723ae01ddb28394bf686647c Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:03:36 +0100 Subject: [PATCH 16/70] refactoring: description added --- src/arithmeticSubtraction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index 363e792..739e755 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -14,7 +14,7 @@ float* subtraction_float(float a, float b) { *result=a - b; return result; } -//arithmetic Subtraction specification double +//arithmetic Subtraction specification double 3 function double* subtraction_double(double a, double b) { double* result= malloc(sizeof (double)); *result=a - b; From 9e4667ddd85a9228ff8ee62b9cbc254803913de9 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:04:29 +0100 Subject: [PATCH 17/70] refactoring: description added --- src/trigonometricFunctions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trigonometricFunctions.c b/src/trigonometricFunctions.c index 0a9a956..5ff0831 100644 --- a/src/trigonometricFunctions.c +++ b/src/trigonometricFunctions.c @@ -3,7 +3,7 @@ #include "math.h" #include #include - +//function for trigonometric double* calculate_sin_double(double angle) { double* result= malloc(sizeof (double)); *result=sin(angle); From 7a9ba16194ab46c13d4d985b9a750a14e488640f Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:05:00 +0100 Subject: [PATCH 18/70] refactoring: description added --- src/calculateFactorial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calculateFactorial.c b/src/calculateFactorial.c index 0c6cbf0..3c63247 100644 --- a/src/calculateFactorial.c +++ b/src/calculateFactorial.c @@ -2,7 +2,7 @@ #include "calculateFactorial.h" //Factorial -// Function for Factorial +// Function for Factorial with integer int calculateFactorial_integer(int n) { if (n < 0) { From 7077c22833e9719986ee98cb96c71c6ba9115f2f Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:07:22 +0100 Subject: [PATCH 19/70] refactoring: removed unnecessary description --- src/arithmeticMultiplication_Int.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arithmeticMultiplication_Int.c b/src/arithmeticMultiplication_Int.c index 1ad1a19..6aaea5f 100644 --- a/src/arithmeticMultiplication_Int.c +++ b/src/arithmeticMultiplication_Int.c @@ -6,7 +6,7 @@ int* multiplication_integer(int a, int b) { int *result = (int*)malloc(sizeof(int)); if (result == NULL) { - // Handle memory allocation failure + return NULL; } From ff9a829bfb035d43322fd72d3c6d99e843c58fda Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:07:52 +0100 Subject: [PATCH 20/70] refactoring: removed unnecessary description --- src/arithmeticMultiplication_Float.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arithmeticMultiplication_Float.c b/src/arithmeticMultiplication_Float.c index 8e063f2..547b9d7 100644 --- a/src/arithmeticMultiplication_Float.c +++ b/src/arithmeticMultiplication_Float.c @@ -4,7 +4,7 @@ float* multiplication_float(float a, float b) { float* result = (float*)malloc(sizeof(float)); if (result == NULL) { - return NULL; // Handle memory allocation failure + return NULL; } *result = a * b; return result; From cf9bc55bc5fb7ac09f8a3e20c94102d90a436a6a Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:08:11 +0100 Subject: [PATCH 21/70] refactoring: removed unnecessary description --- src/arithmeticMultiplication_Double.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arithmeticMultiplication_Double.c b/src/arithmeticMultiplication_Double.c index 3207551..c33d245 100644 --- a/src/arithmeticMultiplication_Double.c +++ b/src/arithmeticMultiplication_Double.c @@ -5,7 +5,7 @@ double* multiplication_double(double a, double b) { double* result = (double*)malloc(sizeof(double)); if (result == NULL) { - return NULL; // Handle memory allocation failure + return NULL; } *result = a * b; // we multiply a times b and the result gets saved in *result return result; From 81df1a138416d3ae5b874456ca835e67229ba9a0 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 20:11:53 +0100 Subject: [PATCH 22/70] Implemented division for double values --- src/arithmeticDivision.c | 12 ++++++++++++ src/arithmeticDivision.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/arithmeticDivision.c b/src/arithmeticDivision.c index dfdf00a..3233c7b 100644 --- a/src/arithmeticDivision.c +++ b/src/arithmeticDivision.c @@ -23,4 +23,16 @@ long* division_long(long dividend, long divisor) { long* result = malloc(sizeof(long)); *result = dividend / divisor; return result; +} + +double* division_double(double num1, double num2) { + if(num2 == 0) { + return NULL; + } + + + + double* result = malloc(sizeof(double )); + *result = num1 / num2; + return result; } \ No newline at end of file diff --git a/src/arithmeticDivision.h b/src/arithmeticDivision.h index 08bc4f5..df45e81 100644 --- a/src/arithmeticDivision.h +++ b/src/arithmeticDivision.h @@ -5,4 +5,6 @@ int* division_integer(int, int); long* division_long(long, long); +double* division_double(double, double); + #endif //THEADMIRALS_ARITHMETICDIVISION_H From 7c662616672ddd6ab6d19920558a07d6d823d791 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:14:28 +0100 Subject: [PATCH 23/70] changing function for factorial --- src/calculateFactorial.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calculateFactorial.c b/src/calculateFactorial.c index 3c63247..af91e81 100644 --- a/src/calculateFactorial.c +++ b/src/calculateFactorial.c @@ -17,4 +17,6 @@ int calculateFactorial_integer(int n) { } return result; } + return 0; } + From d57e3cb30b7daa2d66a4b1d5808cdaf422254979 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:16:18 +0100 Subject: [PATCH 24/70] changing function for factorial --- src/calculateFactorial.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/calculateFactorial.c b/src/calculateFactorial.c index af91e81..f73e0fa 100644 --- a/src/calculateFactorial.c +++ b/src/calculateFactorial.c @@ -18,5 +18,6 @@ int calculateFactorial_integer(int n) { return result; } return 0; + } From b17b37d57b2497012ba52e71a2b45b0446ed97f2 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 20:17:10 +0100 Subject: [PATCH 25/70] refactoring: changed double division variables and removed spaces --- src/arithmeticDivision.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/arithmeticDivision.c b/src/arithmeticDivision.c index 3233c7b..0090bbd 100644 --- a/src/arithmeticDivision.c +++ b/src/arithmeticDivision.c @@ -25,14 +25,11 @@ long* division_long(long dividend, long divisor) { return result; } -double* division_double(double num1, double num2) { - if(num2 == 0) { +double* division_double(double dividend, double divisor) { + if(divisor == 0) { return NULL; } - - - double* result = malloc(sizeof(double )); - *result = num1 / num2; + *result = dividend / divisor; return result; } \ No newline at end of file From d447b22592050fe2166ae1456259aa7f8e2d015d Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:18:21 +0100 Subject: [PATCH 26/70] refactoring: removed unnecessary description --- src/arithmeticSubtraction.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index 739e755..ed08d04 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -2,19 +2,19 @@ #include "arithmeticSubtraction.h" #include -//arithmetic Subtraction specification integer 1 function +//arithmetic Subtraction specification integer int* subtraction_integer(int a, int b) { int* result= malloc(sizeof (int)); *result=a - b; return result; } -//arithmetic Subtraction specification float 2 function +//arithmetic Subtraction specification float float* subtraction_float(float a, float b) { float* result= malloc(sizeof (float)); *result=a - b; return result; } -//arithmetic Subtraction specification double 3 function +//arithmetic Subtraction specification double double* subtraction_double(double a, double b) { double* result= malloc(sizeof (double)); *result=a - b; From 3fd8aff3d30e1f9060ef4173b2237f134b547ea0 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:18:57 +0100 Subject: [PATCH 27/70] refactoring: removed unnecessary description --- src/calculateFactorial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calculateFactorial.c b/src/calculateFactorial.c index f73e0fa..bd7ae94 100644 --- a/src/calculateFactorial.c +++ b/src/calculateFactorial.c @@ -1,7 +1,7 @@ #include "calculateFactorial.h" -//Factorial + // Function for Factorial with integer int calculateFactorial_integer(int n) { if (n < 0) { From c0b2e43eb81eed70bea188a353946fa00022ba14 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 20:19:58 +0100 Subject: [PATCH 28/70] Expanded arithmetic division with datatype --- src/arithmeticDivision.c | 9 +++++++++ src/arithmeticDivision.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/arithmeticDivision.c b/src/arithmeticDivision.c index 0090bbd..4bb8a58 100644 --- a/src/arithmeticDivision.c +++ b/src/arithmeticDivision.c @@ -32,4 +32,13 @@ double* division_double(double dividend, double divisor) { double* result = malloc(sizeof(double )); *result = dividend / divisor; return result; +} + +float* division_float(float dividend, float divisor) { + if(divisor == 0) { + return NULL; + } + float* result = malloc(sizeof(float)); + *result = dividend / divisor; + return result; } \ No newline at end of file diff --git a/src/arithmeticDivision.h b/src/arithmeticDivision.h index df45e81..9ae1a34 100644 --- a/src/arithmeticDivision.h +++ b/src/arithmeticDivision.h @@ -7,4 +7,6 @@ long* division_long(long, long); double* division_double(double, double); +float* division_float(float, float); + #endif //THEADMIRALS_ARITHMETICDIVISION_H From 0e670feaf5b5268507367b21ed9c5af8506dbb30 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:23:49 +0100 Subject: [PATCH 29/70] added ton to megaton converter --- src/convert_ton_to_mt.c | 7 +++++++ src/convert_ton_to_mt.h | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/convert_ton_to_mt.c create mode 100644 src/convert_ton_to_mt.h diff --git a/src/convert_ton_to_mt.c b/src/convert_ton_to_mt.c new file mode 100644 index 0000000..df74434 --- /dev/null +++ b/src/convert_ton_to_mt.c @@ -0,0 +1,7 @@ + +#include "convert_ton_to_mt.h" + + +double tons_to_megatons(double tons) { + return tons / 1000000.0; // 1 megaton = 1,000,000 tons +} diff --git a/src/convert_ton_to_mt.h b/src/convert_ton_to_mt.h new file mode 100644 index 0000000..331c20b --- /dev/null +++ b/src/convert_ton_to_mt.h @@ -0,0 +1,13 @@ + +#ifndef THEADMIRALS_CONVERT_TON_TO_MT_H +#define THEADMIRALS_CONVERT_TON_TO_MT_H + + + + +double tons_to_megatons(double tons); + + + + +#endif //THEADMIRALS_CONVERT_TON_TO_MT_H From bc87fd5b76d6bc446c241e480cad8cf4255f42a4 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:23:06 +0100 Subject: [PATCH 30/70] refactoring: description added --- src/trigonometricFunctions.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/trigonometricFunctions.c b/src/trigonometricFunctions.c index 5ff0831..58e004f 100644 --- a/src/trigonometricFunctions.c +++ b/src/trigonometricFunctions.c @@ -4,6 +4,7 @@ #include #include //function for trigonometric +//Function 1 double* calculate_sin_double(double angle) { double* result= malloc(sizeof (double)); *result=sin(angle); From 70812a2289fef6008805a594ddb68053b7733414 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:23:15 +0100 Subject: [PATCH 31/70] refactoring: description added --- src/trigonometricFunctions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trigonometricFunctions.c b/src/trigonometricFunctions.c index 58e004f..bd5aac4 100644 --- a/src/trigonometricFunctions.c +++ b/src/trigonometricFunctions.c @@ -10,7 +10,7 @@ double* calculate_sin_double(double angle) { *result=sin(angle); return result; } - +//Function 2 double* calculate_cos_double(double angle) { double* result= malloc(sizeof (double)); From cc6a5f468b1f17174e1f0bebcaf4f4aabe2dee68 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:23:22 +0100 Subject: [PATCH 32/70] refactoring: description added --- src/trigonometricFunctions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trigonometricFunctions.c b/src/trigonometricFunctions.c index bd5aac4..a2e1908 100644 --- a/src/trigonometricFunctions.c +++ b/src/trigonometricFunctions.c @@ -17,7 +17,7 @@ double* calculate_cos_double(double angle) { *result=cos(angle); return result; } - +//Function 3 double* calculate_tan_double(double angle) { double* result= malloc(sizeof (double)); From e2f50f2de60acae0bfb392f41d0c7769febf8a04 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 20:23:51 +0100 Subject: [PATCH 33/70] refactoring: description added for double --- src/trigonometricFunctions.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/trigonometricFunctions.c b/src/trigonometricFunctions.c index a2e1908..6dbdfaf 100644 --- a/src/trigonometricFunctions.c +++ b/src/trigonometricFunctions.c @@ -4,20 +4,20 @@ #include #include //function for trigonometric -//Function 1 +//Function 1 double double* calculate_sin_double(double angle) { double* result= malloc(sizeof (double)); *result=sin(angle); return result; } -//Function 2 +//Function 2 double double* calculate_cos_double(double angle) { double* result= malloc(sizeof (double)); *result=cos(angle); return result; } -//Function 3 +//Function 3 double double* calculate_tan_double(double angle) { double* result= malloc(sizeof (double)); From a315db77f5afac024ed5bdaae2630c2019bbcc54 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:37:13 +0100 Subject: [PATCH 34/70] refactoring: removed unnecessary comments --- src/convert_g_to_mg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_g_to_mg.c b/src/convert_g_to_mg.c index a7c17ad..ceba263 100644 --- a/src/convert_g_to_mg.c +++ b/src/convert_g_to_mg.c @@ -2,5 +2,5 @@ #include "convert_g_to_mg.h" double g_to_mg(double grams) { - return grams * 1000.0; // 1 gram = 1000 milligrams + return grams * 1000.0; } From 80e0e2533f7f7796214234dd52b26e9de7b989df Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:37:24 +0100 Subject: [PATCH 35/70] refactoring: removed unnecessary comments --- src/convert_kg_to_g.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_kg_to_g.c b/src/convert_kg_to_g.c index 92bdd70..2ce2914 100644 --- a/src/convert_kg_to_g.c +++ b/src/convert_kg_to_g.c @@ -2,5 +2,5 @@ #include "convert_kg_to_g.h" double kg_to_gram(double kilograms) { - return kilograms * 1000.0; // 1 kilogram = 1000 grams + return kilograms * 1000.0; } From 958721ea69df5654edf3d0f31f4bd5889538aeb1 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:37:39 +0100 Subject: [PATCH 36/70] refactoring: removed unnecessary comments --- src/convert_kg_to_ton.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_kg_to_ton.c b/src/convert_kg_to_ton.c index 51cea7a..3803dce 100644 --- a/src/convert_kg_to_ton.c +++ b/src/convert_kg_to_ton.c @@ -2,5 +2,5 @@ #include "convert_kg_to_ton.h" double kg_to_tons(double kilograms) { - return kilograms / 1000.0; // 1 ton = 1000 kilograms + return kilograms / 1000.0; } From c584b3aec155fedd718fba9b373156dedaf5bc06 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:38:01 +0100 Subject: [PATCH 37/70] refactoring: removed unnecessary comments --- src/convert_m_to_ft.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_m_to_ft.c b/src/convert_m_to_ft.c index 021c6b3..34b7466 100644 --- a/src/convert_m_to_ft.c +++ b/src/convert_m_to_ft.c @@ -12,7 +12,7 @@ float convert_length(float value, char from_unit, char to_unit) { } else if (from_unit == 'i' && to_unit == 'c') { result = value * 2.54; // Inches to centimeters } else if (from_unit == 'c' && to_unit == 'i') { - result = value / 2.54; // Centimeters to inches + result = value / 2.54; } else { printf("Invalid units or conversion not supported.\n"); result = -1; // Error code From 66da5446d921d3631a0e7f1f940a7acedd290f77 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:38:52 +0100 Subject: [PATCH 38/70] refactoring: removed unnecessary comments --- src/convert_ton_to_kg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_ton_to_kg.c b/src/convert_ton_to_kg.c index 44202e2..d1653d8 100644 --- a/src/convert_ton_to_kg.c +++ b/src/convert_ton_to_kg.c @@ -3,5 +3,5 @@ double tons_to_kg(double tons) { - return tons * 1000.0; // 1 ton = 1000 kilograms + return tons * 1000.0; } From 4619d883e176ef3347191116ead00b7cd8afd173 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:39:28 +0100 Subject: [PATCH 39/70] refactoring: removed unnecessary comments --- src/convert_ton_to_mt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_ton_to_mt.c b/src/convert_ton_to_mt.c index df74434..574d21e 100644 --- a/src/convert_ton_to_mt.c +++ b/src/convert_ton_to_mt.c @@ -3,5 +3,5 @@ double tons_to_megatons(double tons) { - return tons / 1000000.0; // 1 megaton = 1,000,000 tons + return tons / 1000000.0; } From 4489eb8b3e00cd8c5b897c36412e6fb28a727c10 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:42:50 +0100 Subject: [PATCH 40/70] refactoring: description added --- src/convert_m_to_ft.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_m_to_ft.c b/src/convert_m_to_ft.c index 34b7466..e488352 100644 --- a/src/convert_m_to_ft.c +++ b/src/convert_m_to_ft.c @@ -20,4 +20,4 @@ float convert_length(float value, char from_unit, char to_unit) { return result; } - +// function converts between cm to inches and vice versa, and between m to ft and vice versa From f5f64951f964d0b80e26fdd73d315a7d8f127c2c Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 20:43:44 +0100 Subject: [PATCH 41/70] Added operation handler output function --- src/operationHandler.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/operationHandler.c b/src/operationHandler.c index 6fb44b8..93dbea7 100644 --- a/src/operationHandler.c +++ b/src/operationHandler.c @@ -3,6 +3,7 @@ #include #include #include +#include // checking integer input as operation id bool checkOperationInput(int input) { @@ -94,4 +95,8 @@ int extractFirstNumber(char* str) { strcpy(str, temp); return number; +} + +void outputInteger(int output) { + printf("Result: %d", output); } \ No newline at end of file From d0f1d25eead25ab50fe148a4f50eaaa6bc7e73e3 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 20:47:39 +0100 Subject: [PATCH 42/70] Added output function for long values --- src/operationHandler.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operationHandler.c b/src/operationHandler.c index 93dbea7..565969d 100644 --- a/src/operationHandler.c +++ b/src/operationHandler.c @@ -99,4 +99,8 @@ int extractFirstNumber(char* str) { void outputInteger(int output) { printf("Result: %d", output); +} + +void outputLong(long output) { + printf("Result: %ld", output); } \ No newline at end of file From e38ad30800599bdc28fecaf72f296d3655ee7253 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:50:20 +0100 Subject: [PATCH 43/70] refactoring: description added --- src/convert_g_to_mg.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/convert_g_to_mg.h b/src/convert_g_to_mg.h index 557244a..e764c7e 100644 --- a/src/convert_g_to_mg.h +++ b/src/convert_g_to_mg.h @@ -4,7 +4,11 @@ - +// Convert grams to milligrams +// Parameters: +// grams: weight in grams +// Returns: +// The equivalent weight in milligrams double g_to_mg(double grams); From d57ab8cde51e4977f6df4887f1fbf1d8c8d2b223 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:50:51 +0100 Subject: [PATCH 44/70] refactoring: description added --- src/convert_kg_to_g.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/convert_kg_to_g.h b/src/convert_kg_to_g.h index 707a161..15745dd 100644 --- a/src/convert_kg_to_g.h +++ b/src/convert_kg_to_g.h @@ -5,6 +5,11 @@ +// Convert kilograms to grams +// Parameters: +// kilograms: weight in kilograms +// Returns: +// The equivalent weight in grams double kg_to_gram(double kilograms); From 5eebcef3e81ccc18d85eabc08fa94c57c4b46ac5 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:51:10 +0100 Subject: [PATCH 45/70] refactoring: description added --- src/convert_kg_to_ton.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/convert_kg_to_ton.h b/src/convert_kg_to_ton.h index 01f9369..cc38ea6 100644 --- a/src/convert_kg_to_ton.h +++ b/src/convert_kg_to_ton.h @@ -5,6 +5,12 @@ +// Convert kilograms to tons +// Parameters: +// kilograms: weight in kilograms +// Returns: +// The equivalent weight in tons + double kg_to_tons(double kilograms); From 4dd0b9dc2336b3bb8ab35d9a0d319ca86fbe76eb Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:51:50 +0100 Subject: [PATCH 46/70] refactoring: description added --- src/convert_m_to_ft.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/convert_m_to_ft.h b/src/convert_m_to_ft.h index 6b9317c..3c99725 100644 --- a/src/convert_m_to_ft.h +++ b/src/convert_m_to_ft.h @@ -2,6 +2,13 @@ #ifndef THEADMIRALS_CONVERT_M_TO_FT_H #define THEADMIRALS_CONVERT_M_TO_FT_H +// Convert length from one unit to another +// Parameters: +// value: the value to be converted +// from_unit: the unit to convert from ('m' for meters, 'c' for centimeters, 'i' for inches) +// to_unit: the unit to convert to ('m' for meters, 'c' for centimeters, 'i' for inches) +// Returns: +// The converted length value float convert_length(float value, char from_unit, char to_unit); From 3bd356b725067728d64bd603a9b947a6c807715f Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 20:52:09 +0100 Subject: [PATCH 47/70] refactoring: description added --- src/convert_ton_to_kg.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/convert_ton_to_kg.h b/src/convert_ton_to_kg.h index 3ad55e5..9591ea6 100644 --- a/src/convert_ton_to_kg.h +++ b/src/convert_ton_to_kg.h @@ -3,6 +3,12 @@ #ifndef THEADMIRALS_CONVERT_TON_TO_KG_H #define THEADMIRALS_CONVERT_TON_TO_KG_H +// Convert tons to kilograms +// Parameters: +// tons: weight in tons +// Returns: +// The equivalent weight in kilograms + double tons_to_kg(double tons); From 3e9130a14ab72f50cff467e719f79353bcbaf294 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 20:51:09 +0100 Subject: [PATCH 48/70] Expanded operation handler by double output value --- src/operationHandler.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operationHandler.c b/src/operationHandler.c index 565969d..be3a094 100644 --- a/src/operationHandler.c +++ b/src/operationHandler.c @@ -103,4 +103,8 @@ void outputInteger(int output) { void outputLong(long output) { printf("Result: %ld", output); +} + +void outputDouble(double output) { + printf("Result: %lf", output); } \ No newline at end of file From 15dd594e1af46e91f1fac27c5835d1cb4cf8153f Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 20:59:53 +0100 Subject: [PATCH 49/70] Added operation handler float method and template output --- src/operationHandler.c | 8 ++++++++ src/operationHandler.h | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/operationHandler.c b/src/operationHandler.c index be3a094..122cb8b 100644 --- a/src/operationHandler.c +++ b/src/operationHandler.c @@ -107,4 +107,12 @@ void outputLong(long output) { void outputDouble(double output) { printf("Result: %lf", output); +} + +void outputFloat(float output) { + printf("Result: %f", output); +} + +void outputTemplate() { + printf("###############################\n-> Calculator\n#################################"); } \ No newline at end of file diff --git a/src/operationHandler.h b/src/operationHandler.h index 58ca89a..ad14eb2 100644 --- a/src/operationHandler.h +++ b/src/operationHandler.h @@ -10,4 +10,14 @@ bool containsTwoNumbers(const char*); int extractFirstNumber(char*); +void outputInteger(int); + +void outputDouble(double); + +void outputFloat(float); + +void outputLong(long); + +void outputTemplate(); + #endif //THEADMIRALS_OPERATIONHANDLER_H From c6141c0236f4589d254c7e21f959c99fcd227d10 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 21:00:55 +0100 Subject: [PATCH 50/70] Implemented template in output methods --- src/operationHandler.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operationHandler.c b/src/operationHandler.c index 122cb8b..df85a49 100644 --- a/src/operationHandler.c +++ b/src/operationHandler.c @@ -98,18 +98,22 @@ int extractFirstNumber(char* str) { } void outputInteger(int output) { + outputTemplate(); printf("Result: %d", output); } void outputLong(long output) { + outputTemplate(); printf("Result: %ld", output); } void outputDouble(double output) { + outputTemplate(); printf("Result: %lf", output); } void outputFloat(float output) { + outputTemplate(); printf("Result: %f", output); } From 57b66f23b200e083a8a945e7fb6b970b8eef4b7c Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 21:34:16 +0100 Subject: [PATCH 51/70] Added input handler --- src/inputHandler.c | 14 ++++++++++++++ src/inputHandler.h | 6 ++++++ 2 files changed, 20 insertions(+) create mode 100644 src/inputHandler.c create mode 100644 src/inputHandler.h diff --git a/src/inputHandler.c b/src/inputHandler.c new file mode 100644 index 0000000..da56212 --- /dev/null +++ b/src/inputHandler.c @@ -0,0 +1,14 @@ +#include "inputHandler.h" + +int getOperationId(char symbol) { + int id = 0; + switch (symbol) { + case '+': + return 1; + case '-': + return 2; + case '*': + return 3; + } + return id; +} \ No newline at end of file diff --git a/src/inputHandler.h b/src/inputHandler.h new file mode 100644 index 0000000..1014f4d --- /dev/null +++ b/src/inputHandler.h @@ -0,0 +1,6 @@ +#ifndef THEADMIRALS_INPUTHANDLER_H +#define THEADMIRALS_INPUTHANDLER_H + +int getOperationId(char); + +#endif //THEADMIRALS_INPUTHANDLER_H From 062bdc8be0f9e9963b3b18babd03ce6f8d8e6a46 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 21:35:15 +0100 Subject: [PATCH 52/70] Updated input handler return value for '*' and added division --- src/inputHandler.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/inputHandler.c b/src/inputHandler.c index da56212..0001469 100644 --- a/src/inputHandler.c +++ b/src/inputHandler.c @@ -7,8 +7,10 @@ int getOperationId(char symbol) { return 1; case '-': return 2; - case '*': + case '/': return 3; + case '*': + return 4; } return id; } \ No newline at end of file From 1bd8af661afd1914ddf54c5a74964d60ec5d3d85 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 21:36:36 +0100 Subject: [PATCH 53/70] Implemented multiple operation ids --- src/inputHandler.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/inputHandler.c b/src/inputHandler.c index 0001469..fc88238 100644 --- a/src/inputHandler.c +++ b/src/inputHandler.c @@ -11,6 +11,12 @@ int getOperationId(char symbol) { return 3; case '*': return 4; + case '^': + return 5; + case '%': + return 6; + case '!': + return 7; } return id; } \ No newline at end of file From 7e8decf5f970cf30e94b1f4e522555e69d53212c Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 21:40:01 +0100 Subject: [PATCH 54/70] Implemented reverse operation method for symbols --- src/inputHandler.c | 26 +++++++++++++++++++++++++- src/inputHandler.h | 2 ++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/inputHandler.c b/src/inputHandler.c index fc88238..2100476 100644 --- a/src/inputHandler.c +++ b/src/inputHandler.c @@ -19,4 +19,28 @@ int getOperationId(char symbol) { return 7; } return id; -} \ No newline at end of file +} + +char getOperationSymbol(int id) { + char symbol = ' '; + switch (id) { + case 1: + return '+'; + case 2: + return '-'; + case 3: + return '/'; + case 4: + return '*'; + case 5: + + return '^'; + case 6: + return '%'; + + case 7: + + return '!'; + } + return symbol; +} diff --git a/src/inputHandler.h b/src/inputHandler.h index 1014f4d..98f1421 100644 --- a/src/inputHandler.h +++ b/src/inputHandler.h @@ -3,4 +3,6 @@ int getOperationId(char); +char getOperationSymbol(int); + #endif //THEADMIRALS_INPUTHANDLER_H From 780522ca73b40fa17c57d9d09b041f92115728a7 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 21:41:02 +0100 Subject: [PATCH 55/70] refactoring: realigned code in switch --- src/inputHandler.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/inputHandler.c b/src/inputHandler.c index 2100476..107b9df 100644 --- a/src/inputHandler.c +++ b/src/inputHandler.c @@ -33,13 +33,10 @@ char getOperationSymbol(int id) { case 4: return '*'; case 5: - return '^'; case 6: return '%'; - case 7: - return '!'; } return symbol; From ea99b984a7211a8c4dac851494a5c0e9c4a8a7ca Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 21:48:47 +0100 Subject: [PATCH 56/70] Added validation check for operation id --- src/inputHandler.c | 6 ++++++ src/inputHandler.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/inputHandler.c b/src/inputHandler.c index 107b9df..0ecd1d6 100644 --- a/src/inputHandler.c +++ b/src/inputHandler.c @@ -1,4 +1,5 @@ #include "inputHandler.h" +#include int getOperationId(char symbol) { int id = 0; @@ -41,3 +42,8 @@ char getOperationSymbol(int id) { } return symbol; } + +int isOperationValid(int id) { + if(id < 0 || id > 7) return 0; + return 1; +} \ No newline at end of file diff --git a/src/inputHandler.h b/src/inputHandler.h index 98f1421..107f49e 100644 --- a/src/inputHandler.h +++ b/src/inputHandler.h @@ -5,4 +5,6 @@ int getOperationId(char); char getOperationSymbol(int); +int isOperationValid(int); + #endif //THEADMIRALS_INPUTHANDLER_H From 794c6aa70000b27bbd3c5cd35d163a6ec4262ee7 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 21:50:51 +0100 Subject: [PATCH 57/70] refactoring: description for input handler functions --- src/inputHandler.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/inputHandler.c b/src/inputHandler.c index 0ecd1d6..39af339 100644 --- a/src/inputHandler.c +++ b/src/inputHandler.c @@ -22,6 +22,7 @@ int getOperationId(char symbol) { return id; } +// returns operation symbol for a specific operation id char getOperationSymbol(int id) { char symbol = ' '; switch (id) { @@ -43,6 +44,7 @@ char getOperationSymbol(int id) { return symbol; } +// Checking if operation id is available int isOperationValid(int id) { if(id < 0 || id > 7) return 0; return 1; From 4ff0403e7d92abc74f381640fba05d590f408fb5 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 21:54:31 +0100 Subject: [PATCH 58/70] refactoring: function names changed --- src/inputHandler.c | 7 ++++--- src/inputHandler.h | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/inputHandler.c b/src/inputHandler.c index 39af339..47e5df1 100644 --- a/src/inputHandler.c +++ b/src/inputHandler.c @@ -1,7 +1,8 @@ #include "inputHandler.h" #include -int getOperationId(char symbol) { +// return operation id for a specific symbol +int getOperationIdBySymbol(char symbol) { int id = 0; switch (symbol) { case '+': @@ -23,7 +24,7 @@ int getOperationId(char symbol) { } // returns operation symbol for a specific operation id -char getOperationSymbol(int id) { +char getOperationSymbolById(int id) { char symbol = ' '; switch (id) { case 1: @@ -45,7 +46,7 @@ char getOperationSymbol(int id) { } // Checking if operation id is available -int isOperationValid(int id) { +int isOperationIdValid(int id) { if(id < 0 || id > 7) return 0; return 1; } \ No newline at end of file diff --git a/src/inputHandler.h b/src/inputHandler.h index 107f49e..6e4e4d5 100644 --- a/src/inputHandler.h +++ b/src/inputHandler.h @@ -1,10 +1,10 @@ #ifndef THEADMIRALS_INPUTHANDLER_H #define THEADMIRALS_INPUTHANDLER_H -int getOperationId(char); +int getOperationIdBySymbol(char); -char getOperationSymbol(int); +char getOperationSymbolById(int); -int isOperationValid(int); +int isOperationIdValid(int); #endif //THEADMIRALS_INPUTHANDLER_H From 5e21520280d366bd921a7fc9c7f4db8d6e57b45c Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 22:00:23 +0100 Subject: [PATCH 59/70] Added number size check in input handler --- src/inputHandler.c | 8 +++++++- src/inputHandler.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/inputHandler.c b/src/inputHandler.c index 47e5df1..f11f806 100644 --- a/src/inputHandler.c +++ b/src/inputHandler.c @@ -1,5 +1,5 @@ #include "inputHandler.h" -#include +#include // return operation id for a specific symbol int getOperationIdBySymbol(char symbol) { @@ -49,4 +49,10 @@ char getOperationSymbolById(int id) { int isOperationIdValid(int id) { if(id < 0 || id > 7) return 0; return 1; +} + +int isNumberTooBig(int number) { + if(number < 200) return 0; + printf("Diese Nummer ist zu groß"); + return 1; } \ No newline at end of file diff --git a/src/inputHandler.h b/src/inputHandler.h index 6e4e4d5..372f9d0 100644 --- a/src/inputHandler.h +++ b/src/inputHandler.h @@ -7,4 +7,6 @@ char getOperationSymbolById(int); int isOperationIdValid(int); +int isNumberTooBig(int); + #endif //THEADMIRALS_INPUTHANDLER_H From c8fc40abcbb902cf9e1620ed285740f942f3f9c9 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 22:01:22 +0100 Subject: [PATCH 60/70] refactoring: corrected text in number size check --- src/inputHandler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inputHandler.c b/src/inputHandler.c index f11f806..5c9dba9 100644 --- a/src/inputHandler.c +++ b/src/inputHandler.c @@ -53,6 +53,6 @@ int isOperationIdValid(int id) { int isNumberTooBig(int number) { if(number < 200) return 0; - printf("Diese Nummer ist zu groß"); + printf("This number is too big. Please choose a smaller one...\n"); return 1; } \ No newline at end of file From 9c5ee0b617117766c43e251ef04315c0d505a289 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 22:36:55 +0100 Subject: [PATCH 61/70] Correction of valid operation check --- src/inputHandler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inputHandler.c b/src/inputHandler.c index 5c9dba9..ed559c8 100644 --- a/src/inputHandler.c +++ b/src/inputHandler.c @@ -47,7 +47,7 @@ char getOperationSymbolById(int id) { // Checking if operation id is available int isOperationIdValid(int id) { - if(id < 0 || id > 7) return 0; + if(id < 1 || id > 7) return 0; return 1; } From 348ee0b08cdcc24f7d78996646f14d385f1f486b Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 22:45:06 +0100 Subject: [PATCH 62/70] Removed output text in number size check --- src/inputHandler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inputHandler.c b/src/inputHandler.c index ed559c8..199d2dd 100644 --- a/src/inputHandler.c +++ b/src/inputHandler.c @@ -53,6 +53,6 @@ int isOperationIdValid(int id) { int isNumberTooBig(int number) { if(number < 200) return 0; - printf("This number is too big. Please choose a smaller one...\n"); + //printf("This number is too big. Please choose a smaller one...\n"); return 1; } \ No newline at end of file From 5f8bfdb3b432cbe33b0334ef07da6637e79bd75d Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 22:47:42 +0100 Subject: [PATCH 63/70] refactoring: changed variable names --- src/arithmeticAddition.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/arithmeticAddition.c b/src/arithmeticAddition.c index 8f93738..173c438 100644 --- a/src/arithmeticAddition.c +++ b/src/arithmeticAddition.c @@ -12,20 +12,20 @@ int* addition_integer(int num1, int num2) { return result; } -double* addition_double(double number1, double number2) { +double* addition_double(double num1, double num2) { double* result = malloc(sizeof(double)); - *result = number1+number2; + *result = num1+num2; return result; } -float* addition_float(float number1, float number2) { +float* addition_float(float num1, float num2) { float* result = malloc(sizeof(float)); - *result = number1+number2; + *result = num1+num2; return result; } -long* addition_long(long number1, long number2) { +long* addition_long(long num1, long num2) { long* result = malloc(sizeof(long)); - *result = number1+number2; + *result = num1+num2; return result; } \ No newline at end of file From 38e96b104df0e84754402172286cee8db570e559 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 22:49:00 +0100 Subject: [PATCH 64/70] refactoring: added descriptions for division cases --- src/arithmeticDivision.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/arithmeticDivision.c b/src/arithmeticDivision.c index 4bb8a58..c29e7dd 100644 --- a/src/arithmeticDivision.c +++ b/src/arithmeticDivision.c @@ -4,6 +4,7 @@ #include int* division_integer(int dividend, int divisor) { + // division with 0 would cause errors if(divisor == 0) { return NULL; } @@ -17,6 +18,7 @@ int* division_integer(int dividend, int divisor) { } long* division_long(long dividend, long divisor) { + // division with 0 would cause errors if(divisor == 0) { return NULL; } @@ -26,6 +28,7 @@ long* division_long(long dividend, long divisor) { } double* division_double(double dividend, double divisor) { + // division with 0 would cause errors if(divisor == 0) { return NULL; } @@ -35,6 +38,7 @@ double* division_double(double dividend, double divisor) { } float* division_float(float dividend, float divisor) { + // division with 0 would cause errors if(divisor == 0) { return NULL; } From 94d2f5e730d9d494a356a117b1c53669fd496c2d Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 22:52:22 +0100 Subject: [PATCH 65/70] refactoring: realigned code, removed unused include and corrected description --- src/convert_M_in_KM.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/convert_M_in_KM.c b/src/convert_M_in_KM.c index 2f8b0e3..bf56016 100644 --- a/src/convert_M_in_KM.c +++ b/src/convert_M_in_KM.c @@ -1,7 +1,6 @@ - #include "convert_M_in_KM.h" -#include -//convert length for double m into km + +// convert length for double metre into kilometre double meter_to_kilometer(double meter) { return meter / 1000.0; } From 612d1db635519780837a15fde149324a0e7f5fdb Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 22:58:14 +0100 Subject: [PATCH 66/70] refactoring: realigned code --- src/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.c b/src/main.c index befd311..c9dee12 100644 --- a/src/main.c +++ b/src/main.c @@ -6,12 +6,15 @@ char buffer[100]; int main() { printf("Please enter the id of a specific operation...\n1. addition\n2. subtraction\n3. multiplication\n4. division\n"); + int input; scanf("%d", &input); + if(!checkOperationInput(input)) { printf("Invalid operation id\n"); return 0; } + printf("\nPlease enter the first and the second number separated by a space...\n"); while(fgets(buffer, 100, stdin)) { @@ -22,6 +25,7 @@ int main() { } int* result = evaluateInput(buffer, input); + if(result == NULL) { printf("\nInvalid formatting. Two numbers need to be separated by a space\n"); return 0; From eeb174e1d85af07a96e10a5e65dd1dd6f8c44998 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 22:59:58 +0100 Subject: [PATCH 67/70] refactoring: added descriptions for main function --- src/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.c b/src/main.c index c9dee12..56241ed 100644 --- a/src/main.c +++ b/src/main.c @@ -7,9 +7,11 @@ char buffer[100]; int main() { printf("Please enter the id of a specific operation...\n1. addition\n2. subtraction\n3. multiplication\n4. division\n"); + // input for math operation as integer int input; scanf("%d", &input); + // check if operation input is valid if(!checkOperationInput(input)) { printf("Invalid operation id\n"); return 0; @@ -17,6 +19,7 @@ int main() { printf("\nPlease enter the first and the second number separated by a space...\n"); + // loop to enter numbers for calculation while(fgets(buffer, 100, stdin)) { buffer[strcspn(buffer, "\n")] = '\0'; if (strlen(buffer) > 0) { @@ -24,6 +27,7 @@ int main() { } } + // extracting numbers from input int* result = evaluateInput(buffer, input); if(result == NULL) { From e66354b1940b197491ed2808a3c4df5a03dc30ca Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 23:04:04 +0100 Subject: [PATCH 68/70] Added test for operation handler extracting method --- test/test_operationHandler.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/test_operationHandler.c b/test/test_operationHandler.c index 1cdfb1d..cadef23 100644 --- a/test/test_operationHandler.c +++ b/test/test_operationHandler.c @@ -46,4 +46,11 @@ void test_operationHandler_extractingFirstNumber(void) { char str[] = {'4', '8', ' ', '5', '\0'}; int result = extractFirstNumber(str); TEST_ASSERT_EQUAL_INT(expectedResult, result); -} \ No newline at end of file +} + +void test_operationHandler_removefirstnumberfromoriginalstring(void) { + char expected[] = {'5', '\0'}; + char str[] = {'4', '8', ' ', '5', '\0'}; + extractFirstNumber(str); + TEST_ASSERT_EQUAL_STRING(expected, str); +} From bdac4949b07635c67d517f0be7d58c07ce8eb4df Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 23:07:27 +0100 Subject: [PATCH 69/70] refactoring: changed descriptions and edited layout --- src/arithmeticMultiplication_Int.c | 4 ---- src/arithmeticSubtraction.c | 10 ++++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/arithmeticMultiplication_Int.c b/src/arithmeticMultiplication_Int.c index 6aaea5f..a00b05d 100644 --- a/src/arithmeticMultiplication_Int.c +++ b/src/arithmeticMultiplication_Int.c @@ -1,15 +1,11 @@ - - #include "arithmeticMultiplication_Int.h" #include int* multiplication_integer(int a, int b) { int *result = (int*)malloc(sizeof(int)); if (result == NULL) { - return NULL; } - *result = a * b; return result; diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index ed08d04..bbabad9 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -1,20 +1,22 @@ - #include "arithmeticSubtraction.h" #include -//arithmetic Subtraction specification integer + +// arithmetic subtraction integer int* subtraction_integer(int a, int b) { int* result= malloc(sizeof (int)); *result=a - b; return result; } -//arithmetic Subtraction specification float + +// arithmetic subtraction float float* subtraction_float(float a, float b) { float* result= malloc(sizeof (float)); *result=a - b; return result; } -//arithmetic Subtraction specification double + +// arithmetic subtraction double double* subtraction_double(double a, double b) { double* result= malloc(sizeof (double)); *result=a - b; From b88040d86a114f97213d9f57ed6e5c7fea2ec0e2 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 23:12:47 +0100 Subject: [PATCH 70/70] Added second system name to team file --- team.md | 1 + 1 file changed, 1 insertion(+) diff --git a/team.md b/team.md index 317f693..bb39ebd 100644 --- a/team.md +++ b/team.md @@ -1,4 +1,5 @@ - Eric Bagus, fdai7812 +- fdai7812, fdai7812 - Leon Wolf, fdai7845 - Sandro Welte, fdai7728 - Jonas Zitzmann, fdai7791 \ No newline at end of file