From 83b4f6496ecac263025dce446959d7a492fee700 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 16:55:10 +0100 Subject: [PATCH 01/67] added arithmetic Multiplication --- src/arithmeticMultiplication_Int.c | 17 +++++++++++++++++ src/arithmeticMultiplication_Int.h | 8 ++++++++ test/test_arithmeticMultiplication_Int.c | 21 +++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 src/arithmeticMultiplication_Int.c create mode 100644 src/arithmeticMultiplication_Int.h create mode 100644 test/test_arithmeticMultiplication_Int.c diff --git a/src/arithmeticMultiplication_Int.c b/src/arithmeticMultiplication_Int.c new file mode 100644 index 0000000..6fff2ec --- /dev/null +++ b/src/arithmeticMultiplication_Int.c @@ -0,0 +1,17 @@ + + +#include "arithmeticMultiplication_Int.h" +#include + +int* multiplication_integer(int num1, int num2) { + int *result = (int*)malloc(sizeof(int)); + if (result == NULL) { + // Handle memory allocation failure + return NULL; + } + + *result = num1 * num2; + + return result; +} + diff --git a/src/arithmeticMultiplication_Int.h b/src/arithmeticMultiplication_Int.h new file mode 100644 index 0000000..4222d1f --- /dev/null +++ b/src/arithmeticMultiplication_Int.h @@ -0,0 +1,8 @@ + + +#ifndef THEADMIRALS_ARITHMETICMULTIPLICATION_INT_H +#define THEADMIRALS_ARITHMETICMULTIPLICATION_INT_H + +int* multiplication_integer(int, int); + +#endif //THEADMIRALS_ARITHMETICMULTIPLICATION_INT_H diff --git a/test/test_arithmeticMultiplication_Int.c b/test/test_arithmeticMultiplication_Int.c new file mode 100644 index 0000000..b5fb385 --- /dev/null +++ b/test/test_arithmeticMultiplication_Int.c @@ -0,0 +1,21 @@ +#include "../src/arithmeticMultiplication_Int.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + +void test_arithmeticMultiplication_numbertimesnumberequalsnumber(void) { + int expectedResult = 10; + int* result; + result = multiplication_integer(2,5); + TEST_ASSERT_EQUAL_INT(expectedResult, *result); +} + + + From fccee6873ca32eb0be9864aaf7f71d3f16547d32 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 17:05:53 +0100 Subject: [PATCH 02/67] Added arithmetic addition including unittest --- src/arithmeticAddition.c | 13 +++++++++++++ src/arithmeticAddition.h | 6 ++++++ test/test_arithmeticAddition.c | 24 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 src/arithmeticAddition.c create mode 100644 src/arithmeticAddition.h create mode 100644 test/test_arithmeticAddition.c diff --git a/src/arithmeticAddition.c b/src/arithmeticAddition.c new file mode 100644 index 0000000..d75b63f --- /dev/null +++ b/src/arithmeticAddition.c @@ -0,0 +1,13 @@ +#include "arithmeticAddition.h" +#include +#include +#include + +int* addition_integer(int num1, int num2) { + if ((num2 > 0 && num1 > INT_MAX - num2) || (num2 < 0 && num1 < INT_MIN - num2)) { + return NULL; + } + int* result = malloc(sizeof(int)); + *result = num1 + num2; + return result; +} \ No newline at end of file diff --git a/src/arithmeticAddition.h b/src/arithmeticAddition.h new file mode 100644 index 0000000..92907ff --- /dev/null +++ b/src/arithmeticAddition.h @@ -0,0 +1,6 @@ +#ifndef THEADMIRALS_ARITHMETICADDITION_H +#define THEADMIRALS_ARITHMETICADDITION_H + +int* addition_integer(int, int); + +#endif //THEADMIRALS_ARITHMETICADDITION_H diff --git a/test/test_arithmeticAddition.c b/test/test_arithmeticAddition.c new file mode 100644 index 0000000..a7089a6 --- /dev/null +++ b/test/test_arithmeticAddition.c @@ -0,0 +1,24 @@ +#include "../src/arithmeticAddition.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + +void test_arithmeticAddition_numberplusnumberequalsnumber(void) { + int expectedResult = 8; + int* result; + result = addition_integer(5, 3); + TEST_ASSERT_EQUAL_INT(expectedResult, *result); +} + +void test_arithmeticAddition_numberplusmaxintegervalueequalsnull(void) { + int* result; + result = addition_integer(INT_MAX, 1); + TEST_ASSERT_NULL(result); +} \ No newline at end of file From b286688bded4247f21379de7ad8bb83013ba49a8 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 17:24:17 +0100 Subject: [PATCH 03/67] added meter to foot and cm to inch converter --- src/convert_m_to_ft.c | 23 +++++++++++++++++++++++ src/convert_m_to_ft.h | 8 ++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/convert_m_to_ft.c create mode 100644 src/convert_m_to_ft.h diff --git a/src/convert_m_to_ft.c b/src/convert_m_to_ft.c new file mode 100644 index 0000000..021c6b3 --- /dev/null +++ b/src/convert_m_to_ft.c @@ -0,0 +1,23 @@ + +#include "convert_m_to_ft.h" +#include + +float convert_length(float value, char from_unit, char to_unit) { + float result; + + if (from_unit == 'm' && to_unit == 'f') { + result = value * 3.281; // Meters to feet + } else if (from_unit == 'f' && to_unit == 'm') { + result = value / 3.281; // Feet to meters + } 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 + } else { + printf("Invalid units or conversion not supported.\n"); + result = -1; // Error code + } + + return result; +} + diff --git a/src/convert_m_to_ft.h b/src/convert_m_to_ft.h new file mode 100644 index 0000000..6b9317c --- /dev/null +++ b/src/convert_m_to_ft.h @@ -0,0 +1,8 @@ + +#ifndef THEADMIRALS_CONVERT_M_TO_FT_H +#define THEADMIRALS_CONVERT_M_TO_FT_H + + +float convert_length(float value, char from_unit, char to_unit); + +#endif //THEADMIRALS_CONVERT_M_TO_FT_H From e7700f8faf785caa218ec909ae84b74da16076ed Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 17:24:58 +0100 Subject: [PATCH 04/67] added test for the meter to foot and cm to inch converter --- test/test_convert_m_to_ft.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/test_convert_m_to_ft.c diff --git a/test/test_convert_m_to_ft.c b/test/test_convert_m_to_ft.c new file mode 100644 index 0000000..8c117a8 --- /dev/null +++ b/test/test_convert_m_to_ft.c @@ -0,0 +1,29 @@ + +#include "../src/convert_m_to_ft.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // Set up resources here if needed +} + +void tearDown(void) { + // Clean up resources here if needed +} + +void test_convert_length(void) { + float value = 10.0; + char from_unit = 'm'; + char to_unit = 'f'; + + // Perform the conversion + float result = convert_length(value, from_unit, to_unit); + + // Define the expected result (10 meters to feet is approximately 32.81 feet) + float expectedResult = 32.81; + + // Assert the result + TEST_ASSERT_EQUAL_FLOAT(expectedResult, result); +} + +// Note: No main function needed in unit tests \ No newline at end of file From 84196e721e41f0cdd7a3066479205e8eff96361a Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 17:25:40 +0100 Subject: [PATCH 05/67] Added arithmetic division including unittest --- src/arithmeticDivision.c | 17 +++++++++++++++++ src/arithmeticDivision.h | 6 ++++++ test/test_arithmeticDivision.c | 19 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/arithmeticDivision.c create mode 100644 src/arithmeticDivision.h create mode 100644 test/test_arithmeticDivision.c diff --git a/src/arithmeticDivision.c b/src/arithmeticDivision.c new file mode 100644 index 0000000..7cdfc7e --- /dev/null +++ b/src/arithmeticDivision.c @@ -0,0 +1,17 @@ +#include "arithmeticDivision.h" +#include +#include +#include + +int* division_integer(int dividend, int divisor) { + if(divisor == 0) { + return NULL; + } + // Overflow protection + if (dividend == INT_MIN && divisor == -1) { + return NULL; + } + int* result = malloc(sizeof(int)); + *result = dividend / divisor; + return result; +} \ No newline at end of file diff --git a/src/arithmeticDivision.h b/src/arithmeticDivision.h new file mode 100644 index 0000000..e4080b7 --- /dev/null +++ b/src/arithmeticDivision.h @@ -0,0 +1,6 @@ +#ifndef THEADMIRALS_ARITHMETICDIVISION_H +#define THEADMIRALS_ARITHMETICDIVISION_H + +int* division_integer(int, int); + +#endif //THEADMIRALS_ARITHMETICDIVISION_H diff --git a/test/test_arithmeticDivision.c b/test/test_arithmeticDivision.c new file mode 100644 index 0000000..6428ea0 --- /dev/null +++ b/test/test_arithmeticDivision.c @@ -0,0 +1,19 @@ +#include "../src/arithmeticDivision.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + + +void test_arithmeticDivision_numberdividedbynumberequalsnumber(void) { + int expectedResult = 2; + int* result; + result = division_integer(14, 7); + TEST_ASSERT_EQUAL_INT(expectedResult, *result); +} From 1d779d437fc6bb0709323625d40112188e7add56 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 17:30:20 +0100 Subject: [PATCH 06/67] add myself to team --- team.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/team.md b/team.md index 9389aab..317f693 100644 --- a/team.md +++ b/team.md @@ -1,3 +1,4 @@ - Eric Bagus, fdai7812 - Leon Wolf, fdai7845 -- Sandro Welte, fdai7728 \ No newline at end of file +- Sandro Welte, fdai7728 +- Jonas Zitzmann, fdai7791 \ No newline at end of file From b34a590c548aac53f2c269b482bc64cdedfe7ed3 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 17:31:18 +0100 Subject: [PATCH 07/67] add logarithmic Function --- src/logarithmicFunctions.c | 18 ++++++++++++++++++ src/logarithmicFunctions.h | 6 ++++++ test/test_logarithmicFunctions.c | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/logarithmicFunctions.c create mode 100644 src/logarithmicFunctions.h create mode 100644 test/test_logarithmicFunctions.c diff --git a/src/logarithmicFunctions.c b/src/logarithmicFunctions.c new file mode 100644 index 0000000..e940cb5 --- /dev/null +++ b/src/logarithmicFunctions.c @@ -0,0 +1,18 @@ +#include "logarithmicFunctions.h" +#include +#include +#include + +double* logarithm_two_integer(int base, int num){ + if(base <= 1 || num <= 0){ + return NULL; + } + + double* result = (double*)malloc(sizeof(double)); + if (result == NULL) { + return NULL; + } + + *result = log(num) / log(base); + return result; +} diff --git a/src/logarithmicFunctions.h b/src/logarithmicFunctions.h new file mode 100644 index 0000000..c13f29d --- /dev/null +++ b/src/logarithmicFunctions.h @@ -0,0 +1,6 @@ +#ifndef THEADMIRALS_LOGARITHMICFUNCTIONS_H +#define THEADMIRALS_LOGARITHMICFUNCTIONS_H + +double* logarithm_two_integer(int base, int num); + +#endif //THEADMIRALS_LOGARITHMICFUNCTIONS_H diff --git a/test/test_logarithmicFunctions.c b/test/test_logarithmicFunctions.c new file mode 100644 index 0000000..512696e --- /dev/null +++ b/test/test_logarithmicFunctions.c @@ -0,0 +1,18 @@ +#include "../src/logarithmicFunctions.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + +void test_logarithmicFunctions_logarithmiccalculation(void){ + double expectedResult = 3.000000; + double* result; + result = logarithm_two_integer(2,8); + TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result); +} \ No newline at end of file From 3eaff2e1a76170d349624c67ec5daf344e90d8d4 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 17:32:58 +0100 Subject: [PATCH 08/67] Commit arithmetic Subtraction integer --- src/arithmeticSubtraction.c | 10 ++++++++++ src/arithmeticSubtraction.h | 7 +++++++ test/test_arithmeticSubtraction.c | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/arithmeticSubtraction.c create mode 100644 src/arithmeticSubtraction.h create mode 100644 test/test_arithmeticSubtraction.c diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c new file mode 100644 index 0000000..f8a7eb5 --- /dev/null +++ b/src/arithmeticSubtraction.c @@ -0,0 +1,10 @@ + +#include "arithmeticSubtraction.h" + +#include + +int* subtraction_integer(int a, int b) { + int* result= malloc(sizeof (int)); + *result=a - b; + return result; +} diff --git a/src/arithmeticSubtraction.h b/src/arithmeticSubtraction.h new file mode 100644 index 0000000..5a36ba5 --- /dev/null +++ b/src/arithmeticSubtraction.h @@ -0,0 +1,7 @@ + +#ifndef THEADMIRALS_ARITHMETICSUBTRACTION_H +#define THEADMIRALS_ARITHMETICSUBTRACTION_H + +int* subtraction_integer(int a, int b); + +#endif //THEADMIRALS_ARITHMETICSUBTRACTION_H diff --git a/test/test_arithmeticSubtraction.c b/test/test_arithmeticSubtraction.c new file mode 100644 index 0000000..26d05c4 --- /dev/null +++ b/test/test_arithmeticSubtraction.c @@ -0,0 +1,18 @@ +#include "../src/arithmeticSubtraction.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} +void test_arithmeticSubtraction_subractionoftwonumbers(void) { + int expectedResult = 7; + int* result; + result = subtraction_integer(14, 7); + TEST_ASSERT_EQUAL_INT(expectedResult, *result); +} + From 7d03f56fe9a8cfa75c7bb3cb4729ab7beaa377a7 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 17:38:22 +0100 Subject: [PATCH 09/67] added Celsius to Fahrenheit converter --- src/convert_C_to_F.c | 19 +++++++++++++++++++ src/convert_C_to_F.h | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 src/convert_C_to_F.c create mode 100644 src/convert_C_to_F.h diff --git a/src/convert_C_to_F.c b/src/convert_C_to_F.c new file mode 100644 index 0000000..ddbdd3e --- /dev/null +++ b/src/convert_C_to_F.c @@ -0,0 +1,19 @@ +#include "stdio.h" +#include "convert_C_to_F.h" + +float convert_temperature(float value, char from_unit, char to_unit) { + float result; + + if (from_unit == 'c' && to_unit == 'f') { + result = (value * 9 / 5) + 32; // Celsius to Fahrenheit + } else if (from_unit == 'f' && to_unit == 'c') { + result = (value - 32) * 5 / 9; // Fahrenheit to Celsius + } else { + printf("Invalid units or conversion not supported.\n"); + result = -1; // Error code + } + + return result; +} + + diff --git a/src/convert_C_to_F.h b/src/convert_C_to_F.h new file mode 100644 index 0000000..3981936 --- /dev/null +++ b/src/convert_C_to_F.h @@ -0,0 +1,7 @@ + +#ifndef THEADMIRALS_CONVERT_C_TO_F_H +#define THEADMIRALS_CONVERT_C_TO_F_H + +float convert_temperature(float value, char from_unit, char to_unit); + +#endif //THEADMIRALS_CONVERT_C_TO_F_H From ea42bf7367a6bfd44151de14e989a7013795b3da Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 17:39:55 +0100 Subject: [PATCH 10/67] Added exponentials including unittest --- src/exponentials.c | 9 +++++++++ src/exponentials.h | 6 ++++++ test/test_exponentials.c | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/exponentials.c create mode 100644 src/exponentials.h create mode 100644 test/test_exponentials.c diff --git a/src/exponentials.c b/src/exponentials.c new file mode 100644 index 0000000..389997b --- /dev/null +++ b/src/exponentials.c @@ -0,0 +1,9 @@ +#include "exponentials.h" +#include +#include + +double* exponentials_double(int base, int exponent) { + double* result = malloc(sizeof(double)); + *result = pow(base, exponent); + return result; +} \ No newline at end of file diff --git a/src/exponentials.h b/src/exponentials.h new file mode 100644 index 0000000..49ab5b9 --- /dev/null +++ b/src/exponentials.h @@ -0,0 +1,6 @@ +#ifndef THEADMIRALS_EXPONENTIALS_H +#define THEADMIRALS_EXPONENTIALS_H + +double* exponentials_double(int, int); + +#endif //THEADMIRALS_EXPONENTIALS_H diff --git a/test/test_exponentials.c b/test/test_exponentials.c new file mode 100644 index 0000000..6266ac7 --- /dev/null +++ b/test/test_exponentials.c @@ -0,0 +1,18 @@ +#include "../src/exponentials.h" +#include "unity.h" +#include "limits.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + +void test_exponentials_calculatenumfrombaseandexponent(void) { + double expectedResult = 32.000000; + double* result; + result = exponentials_double(2, 5); + TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result); +} \ No newline at end of file From 80b6ee577e033cbe4266ac1af9a6a53b614efda8 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 17:40:19 +0100 Subject: [PATCH 11/67] Commit arithmetic Subtraction float --- src/arithmeticSubtraction.c | 5 +++++ src/arithmeticSubtraction.h | 1 + test/test_arithmeticSubtraction.c | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index f8a7eb5..c1bfacd 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -8,3 +8,8 @@ int* subtraction_integer(int a, int b) { *result=a - b; return result; } +float* subtraction_float(float a, float b) { + float* result= malloc(sizeof (float)); + *result=a - b; + return result; +} diff --git a/src/arithmeticSubtraction.h b/src/arithmeticSubtraction.h index 5a36ba5..b7af606 100644 --- a/src/arithmeticSubtraction.h +++ b/src/arithmeticSubtraction.h @@ -3,5 +3,6 @@ #define THEADMIRALS_ARITHMETICSUBTRACTION_H int* subtraction_integer(int a, int b); +float* subtraction_float(float a, float b); #endif //THEADMIRALS_ARITHMETICSUBTRACTION_H diff --git a/test/test_arithmeticSubtraction.c b/test/test_arithmeticSubtraction.c index 26d05c4..633829c 100644 --- a/test/test_arithmeticSubtraction.c +++ b/test/test_arithmeticSubtraction.c @@ -15,4 +15,10 @@ void test_arithmeticSubtraction_subractionoftwonumbers(void) { result = subtraction_integer(14, 7); TEST_ASSERT_EQUAL_INT(expectedResult, *result); } +void test_arithmeticSubtraction_subractionoftwonumberswithfloat(void) { + float expectedResult = 7; + float* result; + result = subtraction_float(14, 7); + TEST_ASSERT_EQUAL_FLOAT(expectedResult, *result); +} From cd1a80534e62369b93c8f73af8e0582be5e35115 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 17:43:10 +0100 Subject: [PATCH 12/67] Commit arithmetic Subtraction double --- src/arithmeticSubtraction.c | 5 +++++ src/arithmeticSubtraction.h | 1 + test/test_arithmeticSubtraction.c | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index c1bfacd..0585677 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -13,3 +13,8 @@ float* subtraction_float(float a, float b) { *result=a - b; return result; } +double* subtraction_double(double a, double b) { + double* result= malloc(sizeof (double)); + *result=a - b; + return result; +} diff --git a/src/arithmeticSubtraction.h b/src/arithmeticSubtraction.h index b7af606..44ea27b 100644 --- a/src/arithmeticSubtraction.h +++ b/src/arithmeticSubtraction.h @@ -4,5 +4,6 @@ int* subtraction_integer(int a, int b); float* subtraction_float(float a, float b); +double* subtraction_double(double a, double b); #endif //THEADMIRALS_ARITHMETICSUBTRACTION_H diff --git a/test/test_arithmeticSubtraction.c b/test/test_arithmeticSubtraction.c index 633829c..007b72b 100644 --- a/test/test_arithmeticSubtraction.c +++ b/test/test_arithmeticSubtraction.c @@ -21,4 +21,11 @@ void test_arithmeticSubtraction_subractionoftwonumberswithfloat(void) { result = subtraction_float(14, 7); TEST_ASSERT_EQUAL_FLOAT(expectedResult, *result); } +void test_arithmeticSubtraction_subractionoftwonumberswithdouble(void) { + double expectedResult = 7; + double* result; + result = subtraction_double(14, 7); + TEST_ASSERT_EQUAL_DOUBLE (expectedResult, *result); +} + From df6e7fe12d669b5355de1b32000194a8ec2cd6b2 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 17:46:19 +0100 Subject: [PATCH 13/67] add converter kph to mps --- src/convert_kph_to_mps.c | 6 ++++++ src/convert_kph_to_mps.h | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 src/convert_kph_to_mps.c create mode 100644 src/convert_kph_to_mps.h diff --git a/src/convert_kph_to_mps.c b/src/convert_kph_to_mps.c new file mode 100644 index 0000000..02b5c60 --- /dev/null +++ b/src/convert_kph_to_mps.c @@ -0,0 +1,6 @@ +#include "convert_kph_to_mps.h" + +double converter_kph_to_mps(double kph){ + double speed = kph / 3.6; + return speed; +} \ No newline at end of file diff --git a/src/convert_kph_to_mps.h b/src/convert_kph_to_mps.h new file mode 100644 index 0000000..467bc72 --- /dev/null +++ b/src/convert_kph_to_mps.h @@ -0,0 +1,6 @@ +#ifndef THEADMIRALS_CONVERT_KPH_TO_MPS_H +#define THEADMIRALS_CONVERT_KPH_TO_MPS_H + +double converter_kph_to_mps(double kph); + +#endif //THEADMIRALS_CONVERT_KPH_TO_MPS_H From f8a17da00e99893b797a469fc0f85d7f8a6c4f33 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 17:48:55 +0100 Subject: [PATCH 14/67] add converter mps to kph --- src/convert_kph_to_mps.c | 5 +++++ src/convert_kph_to_mps.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/convert_kph_to_mps.c b/src/convert_kph_to_mps.c index 02b5c60..ddb0da4 100644 --- a/src/convert_kph_to_mps.c +++ b/src/convert_kph_to_mps.c @@ -3,4 +3,9 @@ double converter_kph_to_mps(double kph){ double speed = kph / 3.6; return speed; +} + +double converter_mps_to_kph(double mps){ + double speed = mps * 3.6; + return speed; } \ No newline at end of file diff --git a/src/convert_kph_to_mps.h b/src/convert_kph_to_mps.h index 467bc72..c4a8592 100644 --- a/src/convert_kph_to_mps.h +++ b/src/convert_kph_to_mps.h @@ -2,5 +2,6 @@ #define THEADMIRALS_CONVERT_KPH_TO_MPS_H double converter_kph_to_mps(double kph); +double converter_mps_to_kph(double mps); #endif //THEADMIRALS_CONVERT_KPH_TO_MPS_H From 56f6adbd5877aa38a2bc657eae2f4f207e04e416 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 17:51:35 +0100 Subject: [PATCH 15/67] refactoring: changed variable num1 to a and variable num2 to b --- src/arithmeticMultiplication_Int.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arithmeticMultiplication_Int.c b/src/arithmeticMultiplication_Int.c index 6fff2ec..1ad1a19 100644 --- a/src/arithmeticMultiplication_Int.c +++ b/src/arithmeticMultiplication_Int.c @@ -3,14 +3,14 @@ #include "arithmeticMultiplication_Int.h" #include -int* multiplication_integer(int num1, int num2) { +int* multiplication_integer(int a, int b) { int *result = (int*)malloc(sizeof(int)); if (result == NULL) { // Handle memory allocation failure return NULL; } - *result = num1 * num2; + *result = a * b; return result; } From 2aa1aaa17d42f45dd2a22147b87cc7c57ad83c54 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 17:51:20 +0100 Subject: [PATCH 16/67] Added input operation handler operation check --- src/operationHandler.c | 10 ++++++++++ src/operationHandler.h | 7 +++++++ 2 files changed, 17 insertions(+) create mode 100644 src/operationHandler.c create mode 100644 src/operationHandler.h diff --git a/src/operationHandler.c b/src/operationHandler.c new file mode 100644 index 0000000..0f63fb7 --- /dev/null +++ b/src/operationHandler.c @@ -0,0 +1,10 @@ +#include "operationHandler.h" +#include + +bool checkOperationInput(int input) { + switch (input) { + case 4: case 3: case 2: case 1: + return true; + } + return false; +} \ No newline at end of file diff --git a/src/operationHandler.h b/src/operationHandler.h new file mode 100644 index 0000000..5293b1e --- /dev/null +++ b/src/operationHandler.h @@ -0,0 +1,7 @@ +#ifndef THEADMIRALS_OPERATIONHANDLER_H +#define THEADMIRALS_OPERATIONHANDLER_H +#include + +bool checkOperationInput(int); + +#endif //THEADMIRALS_OPERATIONHANDLER_H From 2b1a599aee923f09ea1cfcd48c0b4b5e17f1fe21 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 17:53:58 +0100 Subject: [PATCH 17/67] Commit trigonometric Functions --- src/trigonometricFunctions.c | 25 +++++++++++++++++++++++++ src/trigonometricFunctions.h | 9 +++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/trigonometricFunctions.c create mode 100644 src/trigonometricFunctions.h diff --git a/src/trigonometricFunctions.c b/src/trigonometricFunctions.c new file mode 100644 index 0000000..0a9a956 --- /dev/null +++ b/src/trigonometricFunctions.c @@ -0,0 +1,25 @@ + +#include "trigonometricFunctions.h" +#include "math.h" +#include +#include + +double* calculate_sin_double(double angle) { + double* result= malloc(sizeof (double)); + *result=sin(angle); + return result; +} + + +double* calculate_cos_double(double angle) { + double* result= malloc(sizeof (double)); + *result=cos(angle); + return result; +} + + +double* calculate_tan_double(double angle) { + double* result= malloc(sizeof (double)); + *result=tan(angle); + return result; +} diff --git a/src/trigonometricFunctions.h b/src/trigonometricFunctions.h new file mode 100644 index 0000000..add1a8a --- /dev/null +++ b/src/trigonometricFunctions.h @@ -0,0 +1,9 @@ + +#ifndef THEADMIRALS_TRIGONOMETRICFUNCTIONS_H +#define THEADMIRALS_TRIGONOMETRICFUNCTIONS_H + +double* calculate_sin_double(double angle); +double* calculate_cos_double(double angle); +double* calculate_tan_double(double angle); + +#endif //THEADMIRALS_TRIGONOMETRICFUNCTIONS_H From e57f0309a4085ec9b965d85609dad27959d3f98e Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 17:56:30 +0100 Subject: [PATCH 18/67] Added operation handler formatting check --- src/operationHandler.c | 26 ++++++++++++++++++++++++++ src/operationHandler.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/src/operationHandler.c b/src/operationHandler.c index 0f63fb7..ef41efb 100644 --- a/src/operationHandler.c +++ b/src/operationHandler.c @@ -1,5 +1,7 @@ #include "operationHandler.h" #include +#include +#include bool checkOperationInput(int input) { switch (input) { @@ -7,4 +9,28 @@ bool checkOperationInput(int input) { return true; } return false; +} + +bool containsTwoNumbers(const char* str) { + int numbersCount = 0; + bool hasSpace = false; + bool isInNumber = false; + + for (int i = 0; str[i] != '\0'; i++) { + if (isdigit(str[i])) { + if (!isInNumber) { + isInNumber = true; + numbersCount++; + } + } else if (str[i] == ' ' && isInNumber) { + hasSpace = true; + isInNumber = false; + } else if (str[i] == ' ' && !isInNumber) { + hasSpace = false; + } else { + hasSpace = false; + isInNumber = false; + } + } + return (numbersCount == 2 && hasSpace); } \ No newline at end of file diff --git a/src/operationHandler.h b/src/operationHandler.h index 5293b1e..cb083e2 100644 --- a/src/operationHandler.h +++ b/src/operationHandler.h @@ -4,4 +4,6 @@ bool checkOperationInput(int); +bool containsTwoNumbers(const char*); + #endif //THEADMIRALS_OPERATIONHANDLER_H From 27c48490743bfa73ba347446eef80bf14753dea4 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 17:59:22 +0100 Subject: [PATCH 19/67] add converter min to sec --- src/convert_time.c | 6 ++++++ src/convert_time.h | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 src/convert_time.c create mode 100644 src/convert_time.h diff --git a/src/convert_time.c b/src/convert_time.c new file mode 100644 index 0000000..e684f66 --- /dev/null +++ b/src/convert_time.c @@ -0,0 +1,6 @@ +#include "convert_time.h" + +double converter_min_to_sec(double min){ + double time = min / 60; + return time; +} \ No newline at end of file diff --git a/src/convert_time.h b/src/convert_time.h new file mode 100644 index 0000000..6ac0124 --- /dev/null +++ b/src/convert_time.h @@ -0,0 +1,6 @@ +#ifndef THEADMIRALS_CONVERT_TIME_H +#define THEADMIRALS_CONVERT_TIME_H + +double converter_min_to_sec(double min); + +#endif //THEADMIRALS_CONVERT_TIME_H From d36313dcdc6ea87cfcc95bdf2fdc48227c96bde0 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 18:05:01 +0100 Subject: [PATCH 20/67] Added operation handler method extracting two numbers of input --- src/operationHandler.c | 55 ++++++++++++++++++++++++++++++++++++++++++ src/operationHandler.h | 4 +++ 2 files changed, 59 insertions(+) diff --git a/src/operationHandler.c b/src/operationHandler.c index ef41efb..616b627 100644 --- a/src/operationHandler.c +++ b/src/operationHandler.c @@ -2,6 +2,7 @@ #include #include #include +#include bool checkOperationInput(int input) { switch (input) { @@ -11,6 +12,28 @@ bool checkOperationInput(int input) { return false; } +int* evaluateInput(char* input, int operation) { + if(!containsTwoNumbers(input)) return NULL; + int firstNumber = extractFirstNumber(input); + int secondNumber = atoi(input); + int* result = malloc(sizeof(int)); + switch (operation) { + case 1: + *result = firstNumber + secondNumber; + break; + case 2: + *result = firstNumber - secondNumber; + break; + case 3: + *result = firstNumber * secondNumber; + break; + case 4: + *result = firstNumber / secondNumber; + break; + } + return result; +} + bool containsTwoNumbers(const char* str) { int numbersCount = 0; bool hasSpace = false; @@ -33,4 +56,36 @@ bool containsTwoNumbers(const char* str) { } } return (numbersCount == 2 && hasSpace); +} + +int extractFirstNumber(char* str) { + int number = 0; + bool isInNumber = false; + int endIndex = 0; + + for (int i = 0; str[i] != '\0'; i++) { + if (isdigit(str[i])) { + if (!isInNumber) { + isInNumber = true; + number = str[i] - '0'; + } else { + number = number * 10 + (str[i] - '0'); + } + } else if (str[i] == ' ' && isInNumber) { + endIndex = i; + break; + } else { + isInNumber = false; + } + } + + int index = 0; + char temp[strlen(str)-endIndex+1]; + for(int i = endIndex+1; i < strlen(str); i++) { + temp[index++] = str[i]; + } + temp[index] = '\0'; + strcpy(str, temp); + + return number; } \ No newline at end of file diff --git a/src/operationHandler.h b/src/operationHandler.h index cb083e2..58ca89a 100644 --- a/src/operationHandler.h +++ b/src/operationHandler.h @@ -4,6 +4,10 @@ bool checkOperationInput(int); +int* evaluateInput(char*, int); + bool containsTwoNumbers(const char*); +int extractFirstNumber(char*); + #endif //THEADMIRALS_OPERATIONHANDLER_H From 91e59504657c9ccdccdc588d9a9c2351367c0a38 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:08:11 +0100 Subject: [PATCH 21/67] refactoring: Change the var name --- src/convert_time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/convert_time.c b/src/convert_time.c index e684f66..9381271 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -1,6 +1,6 @@ #include "convert_time.h" -double converter_min_to_sec(double min){ - double time = min / 60; +double converter_sec_to_min(double sec){ + double time = sec / 60; return time; -} \ No newline at end of file +} From 7d377e3da763d2b591742f207a864b82952505a0 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 18:11:53 +0100 Subject: [PATCH 22/67] refactoring: removed unnecessary comment --- test/test_convert_m_to_ft.c | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_convert_m_to_ft.c b/test/test_convert_m_to_ft.c index 8c117a8..98ba87e 100644 --- a/test/test_convert_m_to_ft.c +++ b/test/test_convert_m_to_ft.c @@ -26,4 +26,3 @@ void test_convert_length(void) { TEST_ASSERT_EQUAL_FLOAT(expectedResult, result); } -// Note: No main function needed in unit tests \ No newline at end of file From adcb9dc559dae9240decaa5067fba14c9e7b53ca Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:10:54 +0100 Subject: [PATCH 23/67] refactoring: Change the name --- src/convert_time.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_time.h b/src/convert_time.h index 6ac0124..190a814 100644 --- a/src/convert_time.h +++ b/src/convert_time.h @@ -1,6 +1,6 @@ #ifndef THEADMIRALS_CONVERT_TIME_H #define THEADMIRALS_CONVERT_TIME_H -double converter_min_to_sec(double min); +double converter_sec_to_min(double sec); #endif //THEADMIRALS_CONVERT_TIME_H From 67ffbb8c24f4f1bda8e20d7f3731b4815e6bbb05 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:12:10 +0100 Subject: [PATCH 24/67] add new converter --- src/convert_time.c | 5 +++++ src/convert_time.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/convert_time.c b/src/convert_time.c index 9381271..22b705a 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -4,3 +4,8 @@ double converter_sec_to_min(double sec){ double time = sec / 60; return time; } + +double converter_min_to_sec(double min){ + double time = min * 60; + return time; +} diff --git a/src/convert_time.h b/src/convert_time.h index 190a814..bbadf16 100644 --- a/src/convert_time.h +++ b/src/convert_time.h @@ -2,5 +2,6 @@ #define THEADMIRALS_CONVERT_TIME_H double converter_sec_to_min(double sec); +double converter_min_to_sec(double min); #endif //THEADMIRALS_CONVERT_TIME_H From ef8f573757e7bd1ba86a1e09edd295ba14a7b7e0 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 18:12:39 +0100 Subject: [PATCH 25/67] Added operation handler unittest for operation input --- test/test_operationHandler.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/test_operationHandler.c diff --git a/test/test_operationHandler.c b/test/test_operationHandler.c new file mode 100644 index 0000000..0a33c4a --- /dev/null +++ b/test/test_operationHandler.c @@ -0,0 +1,28 @@ +#include "../src/operationHandler.h" +#include "unity.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + +void test_operationHandler_truereturnvaluewithvalidinput(void) { + int expectedResult = 1; + int result1 = checkOperationInput(1); + int result2 = checkOperationInput(2); + int result3 = checkOperationInput(3); + int result4 = checkOperationInput(4); + TEST_ASSERT_EQUAL_INT(expectedResult, result1); + TEST_ASSERT_EQUAL_INT(expectedResult, result2); + TEST_ASSERT_EQUAL_INT(expectedResult, result3); + TEST_ASSERT_EQUAL_INT(expectedResult, result4); +} + +void test_operationHandler_falsereturnvaluewithinvalidinput(void) { + int expectedResult = 0; + int result = checkOperationInput(8); + TEST_ASSERT_EQUAL_INT(expectedResult, result); +} \ No newline at end of file From 57f159cd96bcb3ec90a58fb6615d79454e715c36 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 18:18:56 +0100 Subject: [PATCH 26/67] Added multiple tests for operation handler input processing --- test/test_operationHandler.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/test_operationHandler.c b/test/test_operationHandler.c index 0a33c4a..1cdfb1d 100644 --- a/test/test_operationHandler.c +++ b/test/test_operationHandler.c @@ -25,4 +25,25 @@ void test_operationHandler_falsereturnvaluewithinvalidinput(void) { int expectedResult = 0; int result = checkOperationInput(8); TEST_ASSERT_EQUAL_INT(expectedResult, result); +} + +void test_operationHandler_truereturnvaluewithformattedinput(void) { + int expectedResult = 1; + const char str[] = {'1', '4', ' ', '5', '6', '\0'}; + int result = containsTwoNumbers(str); + TEST_ASSERT_EQUAL_INT(expectedResult, result); +} + +void test_operationHandler_falsereturnvaluewithwronginput(void) { + int expectedResult = 0; + const char str[] = {'5', '6', '\0'}; + int result = containsTwoNumbers(str); + TEST_ASSERT_EQUAL_INT(expectedResult, result); +} + +void test_operationHandler_extractingFirstNumber(void) { + int expectedResult = 48; + char str[] = {'4', '8', ' ', '5', '\0'}; + int result = extractFirstNumber(str); + TEST_ASSERT_EQUAL_INT(expectedResult, result); } \ No newline at end of file From 2039112b1676dfba69481024f4095f1d6f54b20b Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 18:21:28 +0100 Subject: [PATCH 27/67] Added main function ability executing first part of calculator features --- src/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main.c b/src/main.c index 86d4137..4f4b2b5 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,17 @@ #include +#include +#include "operationHandler.h" + +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"); + } \ No newline at end of file From 5a164c3660195111b85cfb5450a7a6f4d45029f3 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 18:25:21 +0100 Subject: [PATCH 28/67] Expanded main function with operation handler processing methods --- src/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main.c b/src/main.c index 4f4b2b5..befd311 100644 --- a/src/main.c +++ b/src/main.c @@ -14,4 +14,17 @@ int main() { } printf("\nPlease enter the first and the second number separated by a space...\n"); + while(fgets(buffer, 100, stdin)) { + buffer[strcspn(buffer, "\n")] = '\0'; + if (strlen(buffer) > 0) { + break; + } + } + + int* result = evaluateInput(buffer, input); + if(result == NULL) { + printf("\nInvalid formatting. Two numbers need to be separated by a space\n"); + return 0; + } + printf("\nResult: %d", *result); } \ No newline at end of file From eee8c709f965413c379ec9f4b67717681beb10b5 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 18:25:57 +0100 Subject: [PATCH 29/67] Commit convert CM in M --- src/convert_CM_in_M.c | 7 +++++++ src/convert_CM_in_M.h | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 src/convert_CM_in_M.c create mode 100644 src/convert_CM_in_M.h diff --git a/src/convert_CM_in_M.c b/src/convert_CM_in_M.c new file mode 100644 index 0000000..94444be --- /dev/null +++ b/src/convert_CM_in_M.c @@ -0,0 +1,7 @@ + +#include "convert_CM_in_M.h" +#include + +float cm_to_meter(float cm) { + return cm / 100.0; +} diff --git a/src/convert_CM_in_M.h b/src/convert_CM_in_M.h new file mode 100644 index 0000000..49b0383 --- /dev/null +++ b/src/convert_CM_in_M.h @@ -0,0 +1,7 @@ + +#ifndef THEADMIRALS_CONVERT_CM_IN_M_H +#define THEADMIRALS_CONVERT_CM_IN_M_H + +float cm_to_meter(float cm); + +#endif //THEADMIRALS_CONVERT_CM_IN_M_H From 89348dd75293858fa2802a0a5c7f3651023bfed4 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:26:47 +0100 Subject: [PATCH 30/67] add new converter: Hour to min --- src/convert_time.c | 6 ++++++ src/convert_time.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/convert_time.c b/src/convert_time.c index 22b705a..76d8279 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -9,3 +9,9 @@ double converter_min_to_sec(double min){ double time = min * 60; return time; } + +double converter_hour_to_min(double hour){ + double time = hour * 60; + return time; +} + diff --git a/src/convert_time.h b/src/convert_time.h index bbadf16..a61eed5 100644 --- a/src/convert_time.h +++ b/src/convert_time.h @@ -3,5 +3,6 @@ double converter_sec_to_min(double sec); double converter_min_to_sec(double min); +double converter_hour_to_min(double hour) #endif //THEADMIRALS_CONVERT_TIME_H From d7a6796768d860cebd94eed2dca92301ceb77d68 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:27:49 +0100 Subject: [PATCH 31/67] add new converter: Hour to min --- src/convert_time.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert_time.h b/src/convert_time.h index a61eed5..b27c0f3 100644 --- a/src/convert_time.h +++ b/src/convert_time.h @@ -3,6 +3,6 @@ double converter_sec_to_min(double sec); double converter_min_to_sec(double min); -double converter_hour_to_min(double hour) +double converter_hour_to_min(double hour); #endif //THEADMIRALS_CONVERT_TIME_H From c96e7191533a69fd4f97c7cc324852f9841466e6 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 18:30:29 +0100 Subject: [PATCH 32/67] convert length specification --- 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 94444be..bdc42ea 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 float cm_to_meter(float cm) { return cm / 100.0; } From 5aaffa84671048c33fc65dfc68c16913bebbeac9 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:31:21 +0100 Subject: [PATCH 33/67] add new converter: min to hour --- src/convert_time.c | 4 ++++ src/convert_time.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/convert_time.c b/src/convert_time.c index 76d8279..36b9599 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -15,3 +15,7 @@ double converter_hour_to_min(double hour){ return time; } +double converter_min_to_hour(double min){ + double time = min / 60; + return time; +} \ No newline at end of file diff --git a/src/convert_time.h b/src/convert_time.h index b27c0f3..e48117f 100644 --- a/src/convert_time.h +++ b/src/convert_time.h @@ -4,5 +4,6 @@ double converter_sec_to_min(double sec); double converter_min_to_sec(double min); double converter_hour_to_min(double hour); +double converter_min_to_hour(double min); #endif //THEADMIRALS_CONVERT_TIME_H From 8d21cb81c5bfbc16319ba1f72ef5095bbf709179 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 18:32:52 +0100 Subject: [PATCH 34/67] arithmetic Subtraction specification --- src/arithmeticSubtraction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index 0585677..ed12a2b 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -2,7 +2,7 @@ #include "arithmeticSubtraction.h" #include - +//arithmetic Subtraction specification int* subtraction_integer(int a, int b) { int* result= malloc(sizeof (int)); *result=a - b; From c455bf1c82deaf922180feca63a4a612d19ee411 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 18:33:42 +0100 Subject: [PATCH 35/67] arithmetic Subtraction specification --- src/arithmeticSubtraction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index ed12a2b..e36089c 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -2,7 +2,7 @@ #include "arithmeticSubtraction.h" #include -//arithmetic Subtraction specification +//arithmetic Subtraction specification integer int* subtraction_integer(int a, int b) { int* result= malloc(sizeof (int)); *result=a - b; From 523a794b209a68ab38af42bc7027bbec77251eac Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 18:34:01 +0100 Subject: [PATCH 36/67] arithmetic Subtraction specification --- src/arithmeticSubtraction.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index e36089c..31d5c94 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -8,6 +8,7 @@ int* subtraction_integer(int a, int b) { *result=a - b; return result; } +//arithmetic Subtraction specification float float* subtraction_float(float a, float b) { float* result= malloc(sizeof (float)); *result=a - b; From d7a9ea3009562ae94f2218d7af5bfb314dcef963 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 18:34:18 +0100 Subject: [PATCH 37/67] arithmetic Subtraction specification --- src/arithmeticSubtraction.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index 31d5c94..ed08d04 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -14,6 +14,7 @@ float* subtraction_float(float a, float b) { *result=a - b; return result; } +//arithmetic Subtraction specification double double* subtraction_double(double a, double b) { double* result= malloc(sizeof (double)); *result=a - b; From fa032fb85bddf3c5cd692325d14e274433390da9 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:34:56 +0100 Subject: [PATCH 38/67] add new converter: hour to sec --- src/convert_time.c | 5 +++++ src/convert_time.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/convert_time.c b/src/convert_time.c index 36b9599..726ca28 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -18,4 +18,9 @@ double converter_hour_to_min(double hour){ double converter_min_to_hour(double min){ double time = min / 60; return time; +} + +double converter_hour_in_sec(double hour){ + double time = hour * 60 * 60; + return time; } \ No newline at end of file diff --git a/src/convert_time.h b/src/convert_time.h index e48117f..56301fa 100644 --- a/src/convert_time.h +++ b/src/convert_time.h @@ -5,5 +5,6 @@ double converter_sec_to_min(double sec); double converter_min_to_sec(double min); double converter_hour_to_min(double hour); double converter_min_to_hour(double min); +double converter_hour_in_sec(double hour); #endif //THEADMIRALS_CONVERT_TIME_H From 42d12cc51362c2ccfd95e0a0594fdfeb8db3c339 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:38:43 +0100 Subject: [PATCH 39/67] add new converter: sec to hour --- src/convert_time.c | 5 +++++ src/convert_time.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/convert_time.c b/src/convert_time.c index 726ca28..42266b6 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -23,4 +23,9 @@ double converter_min_to_hour(double min){ double converter_hour_in_sec(double hour){ double time = hour * 60 * 60; return time; +} + +double converter_sec_in_hour(double sec){ + double time = sec / 60 / 60; + return time; } \ No newline at end of file diff --git a/src/convert_time.h b/src/convert_time.h index 56301fa..1a4b196 100644 --- a/src/convert_time.h +++ b/src/convert_time.h @@ -6,5 +6,6 @@ double converter_min_to_sec(double min); double converter_hour_to_min(double hour); double converter_min_to_hour(double min); double converter_hour_in_sec(double hour); +double converter_sec_in_hour(double sec); #endif //THEADMIRALS_CONVERT_TIME_H From 216de268774101edf0e03db070b25b7af700a8f0 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:41:41 +0100 Subject: [PATCH 40/67] add new converter: sec to hour --- src/convert_time.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/convert_time.h b/src/convert_time.h index 1a4b196..fcd1b4c 100644 --- a/src/convert_time.h +++ b/src/convert_time.h @@ -8,4 +8,5 @@ double converter_min_to_hour(double min); double converter_hour_in_sec(double hour); double converter_sec_in_hour(double sec); + #endif //THEADMIRALS_CONVERT_TIME_H From ffb36c62428da6bbb063414d4f58fa8ad2ab3be8 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:50:00 +0100 Subject: [PATCH 41/67] add new converter: days to years --- src/convert_time.c | 5 +++++ src/convert_time.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/convert_time.c b/src/convert_time.c index 42266b6..d465b90 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -28,4 +28,9 @@ double converter_hour_in_sec(double hour){ double converter_sec_in_hour(double sec){ double time = sec / 60 / 60; return time; +} + +double converter_days_to_years(double days){ + double time = days / 365; + return time; } \ No newline at end of file diff --git a/src/convert_time.h b/src/convert_time.h index fcd1b4c..380316a 100644 --- a/src/convert_time.h +++ b/src/convert_time.h @@ -7,6 +7,6 @@ double converter_hour_to_min(double hour); double converter_min_to_hour(double min); double converter_hour_in_sec(double hour); double converter_sec_in_hour(double sec); - +double converter_days_to_years(double days); #endif //THEADMIRALS_CONVERT_TIME_H From f6dffc93d3230cf976e59cf109dc1ddca0fa1c7e Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 18:55:08 +0100 Subject: [PATCH 42/67] added type double to multiplication --- src/arithmeticMultiplication_Double.c | 12 ++++++++++++ src/arithmeticMultiplication_Double.h | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/arithmeticMultiplication_Double.c create mode 100644 src/arithmeticMultiplication_Double.h diff --git a/src/arithmeticMultiplication_Double.c b/src/arithmeticMultiplication_Double.c new file mode 100644 index 0000000..845eaa1 --- /dev/null +++ b/src/arithmeticMultiplication_Double.c @@ -0,0 +1,12 @@ +#include "stdlib.h" +#include "arithmeticMultiplication_Double.h" + + +double* multiplication_double(double num1, double num2) { + double* result = (double*)malloc(sizeof(double)); + if (result == NULL) { + return NULL; // Handle memory allocation failure + } + *result = num1 * num2; + return result; +} diff --git a/src/arithmeticMultiplication_Double.h b/src/arithmeticMultiplication_Double.h new file mode 100644 index 0000000..0642564 --- /dev/null +++ b/src/arithmeticMultiplication_Double.h @@ -0,0 +1,14 @@ + + +#ifndef THEADMIRALS_ARITHMETICMULTIPLICATION_DOUBLE_H +#define THEADMIRALS_ARITHMETICMULTIPLICATION_DOUBLE_H + + + + + +double* multiplication_double(double num1, double num2); + + + +#endif //THEADMIRALS_ARITHMETICMULTIPLICATION_DOUBLE_H From 305490d1a1c72a70877a53a0b21ace91d3022fee Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:53:54 +0100 Subject: [PATCH 43/67] 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 d465b90..e2956e9 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -1,5 +1,6 @@ #include "convert_time.h" +// Converts Seconds to Minutes double converter_sec_to_min(double sec){ double time = sec / 60; return time; From 5a6c45a9fddf6a5ad7eff86d01687f67dafd3595 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 18:57:26 +0100 Subject: [PATCH 44/67] added type float to multiplication --- src/arithmeticMultiplication_Float.c | 12 ++++++++++++ src/arithmeticMultiplication_Float.h | 13 +++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/arithmeticMultiplication_Float.c create mode 100644 src/arithmeticMultiplication_Float.h diff --git a/src/arithmeticMultiplication_Float.c b/src/arithmeticMultiplication_Float.c new file mode 100644 index 0000000..1014f33 --- /dev/null +++ b/src/arithmeticMultiplication_Float.c @@ -0,0 +1,12 @@ +#include "arithmeticMultiplication_Float.h" +#include + +float* multiplication_float(float num1, float num2) { + float* result = (float*)malloc(sizeof(float)); + if (result == NULL) { + return NULL; // Handle memory allocation failure + } + *result = num1 * num2; + return result; +} + diff --git a/src/arithmeticMultiplication_Float.h b/src/arithmeticMultiplication_Float.h new file mode 100644 index 0000000..48ff7a8 --- /dev/null +++ b/src/arithmeticMultiplication_Float.h @@ -0,0 +1,13 @@ + +#ifndef THEADMIRALS_ARITHMETICMULTIPLICATION_FLOAT_H +#define THEADMIRALS_ARITHMETICMULTIPLICATION_FLOAT_H + + + + + + +float* multiplication_float(float num1, float num2); + + +#endif //THEADMIRALS_ARITHMETICMULTIPLICATION_FLOAT_H From 6e776105492a9bfb561c96b5203bb3b1df604c9a Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:56:02 +0100 Subject: [PATCH 45/67] 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 e2956e9..75b464c 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -6,6 +6,7 @@ double converter_sec_to_min(double sec){ return time; } +// Converts Minutes to Seconds double converter_min_to_sec(double min){ double time = min * 60; return time; From b20d611f8edeea5968e0d82b47e84bc5aa2e3559 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:56:37 +0100 Subject: [PATCH 46/67] 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 75b464c..f84943b 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -12,6 +12,7 @@ double converter_min_to_sec(double min){ return time; } +// Converts Hours to Minutes double converter_hour_to_min(double hour){ double time = hour * 60; return time; From 7df5cef1797c23ed2ed090636e4d0825638686fc Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 18:59:11 +0100 Subject: [PATCH 47/67] added type float to multiplication --- src/convert_ton_to_kg.c | 8 ++++++++ src/convert_ton_to_kg.h | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/convert_ton_to_kg.c create mode 100644 src/convert_ton_to_kg.h diff --git a/src/convert_ton_to_kg.c b/src/convert_ton_to_kg.c new file mode 100644 index 0000000..32b0f60 --- /dev/null +++ b/src/convert_ton_to_kg.c @@ -0,0 +1,8 @@ + +#include "convert_ton_to_kg.h" + + + +double tons_to_kg(double tons) { + return tons * 1000.0; // 1 ton = 1000 kilograms +} diff --git a/src/convert_ton_to_kg.h b/src/convert_ton_to_kg.h new file mode 100644 index 0000000..45a1b58 --- /dev/null +++ b/src/convert_ton_to_kg.h @@ -0,0 +1,12 @@ + + +#ifndef THEADMIRALS_CONVERT_TON_TO_KG_H +#define THEADMIRALS_CONVERT_TON_TO_KG_H + + + +double tons_to_kg(double tons); + + + +#endif //THEADMIRALS_CONVERT_TON_TO_KG_H From 3050b0c8714b73fb4a69eb96732214a4b11e9d01 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 18:58:40 +0100 Subject: [PATCH 48/67] 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 f84943b..3ac150e 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -18,6 +18,7 @@ double converter_hour_to_min(double hour){ return time; } +// Converts Minutes To Hours double converter_min_to_hour(double min){ double time = min / 60; return time; From 943a5b1066f173702259ba3237b551e9c37126fd Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 18:59:54 +0100 Subject: [PATCH 49/67] refactoring: clarifications in operation handler methods --- src/operationHandler.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operationHandler.c b/src/operationHandler.c index 616b627..519fc31 100644 --- a/src/operationHandler.c +++ b/src/operationHandler.c @@ -4,6 +4,7 @@ #include #include +// checking integer input as operation id bool checkOperationInput(int input) { switch (input) { case 4: case 3: case 2: case 1: @@ -12,9 +13,12 @@ bool checkOperationInput(int input) { return false; } +// full input process int* evaluateInput(char* input, int operation) { + // check if formatting is correct if(!containsTwoNumbers(input)) return NULL; int firstNumber = extractFirstNumber(input); + // origin string "input" has been edited int secondNumber = atoi(input); int* result = malloc(sizeof(int)); switch (operation) { From bfa3738c166fcef5e898d251c22a8e683f4236b2 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:00:19 +0100 Subject: [PATCH 50/67] convert M in KM --- src/convert_M_in_KM.c | 7 +++++++ src/convert_M_in_KM.h | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 src/convert_M_in_KM.c create mode 100644 src/convert_M_in_KM.h diff --git a/src/convert_M_in_KM.c b/src/convert_M_in_KM.c new file mode 100644 index 0000000..66ef45a --- /dev/null +++ b/src/convert_M_in_KM.c @@ -0,0 +1,7 @@ + +#include "convert_M_in_KM.h" +#include + +double meter_to_kilometer(double meter) { + return meter / 1000.0; +} diff --git a/src/convert_M_in_KM.h b/src/convert_M_in_KM.h new file mode 100644 index 0000000..9dc3232 --- /dev/null +++ b/src/convert_M_in_KM.h @@ -0,0 +1,7 @@ + +#ifndef THEADMIRALS_CONVERT_M_IN_KM_H +#define THEADMIRALS_CONVERT_M_IN_KM_H + +double meter_to_kilometer(double meter); + +#endif //THEADMIRALS_CONVERT_M_IN_KM_H From 0f32f62b9ee4284f419b3389553fcef1146a896a Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:01:26 +0100 Subject: [PATCH 51/67] Convert length specification --- 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 66ef45a..966872e 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 double meter_to_kilometer(double meter) { return meter / 1000.0; } From 925c68075760855a66ae5f689fc9e65eeff8d591 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 19:01:59 +0100 Subject: [PATCH 52/67] Add converter years to days --- src/convert_time.c | 5 +++++ src/convert_time.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/convert_time.c b/src/convert_time.c index 3ac150e..6f7f163 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -37,4 +37,9 @@ double converter_sec_in_hour(double sec){ double converter_days_to_years(double days){ double time = days / 365; return time; +} + +double converter_years_to_days(double years){ + double time = years * 365; + return time; } \ No newline at end of file diff --git a/src/convert_time.h b/src/convert_time.h index 380316a..ac2ec74 100644 --- a/src/convert_time.h +++ b/src/convert_time.h @@ -8,5 +8,6 @@ double converter_min_to_hour(double min); double converter_hour_in_sec(double hour); double converter_sec_in_hour(double sec); double converter_days_to_years(double days); +double converter_years_to_days(double years); #endif //THEADMIRALS_CONVERT_TIME_H From b38beebfa1f1a2769b25a662676b72ea5366bd7c Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 19:04:27 +0100 Subject: [PATCH 53/67] refactoring: wrong commit notice, right notice: added ton to kg converter --- src/convert_ton_to_kg.c | 1 - src/convert_ton_to_kg.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/convert_ton_to_kg.c b/src/convert_ton_to_kg.c index 32b0f60..44202e2 100644 --- a/src/convert_ton_to_kg.c +++ b/src/convert_ton_to_kg.c @@ -2,7 +2,6 @@ #include "convert_ton_to_kg.h" - double tons_to_kg(double tons) { return tons * 1000.0; // 1 ton = 1000 kilograms } diff --git a/src/convert_ton_to_kg.h b/src/convert_ton_to_kg.h index 45a1b58..3ad55e5 100644 --- a/src/convert_ton_to_kg.h +++ b/src/convert_ton_to_kg.h @@ -4,7 +4,6 @@ #define THEADMIRALS_CONVERT_TON_TO_KG_H - double tons_to_kg(double tons); From b1002a79a7cf25e91ec6bb35b2b2efc73b247154 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 19:03:12 +0100 Subject: [PATCH 54/67] 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 6f7f163..b067fd4 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -24,6 +24,7 @@ double converter_min_to_hour(double min){ return time; } +// Converts Hours in Seconds double converter_hour_in_sec(double hour){ double time = hour * 60 * 60; return time; From d7c9a370e8f062b4113fca51a87e0b6f905ddee1 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 19:03:52 +0100 Subject: [PATCH 55/67] 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 b067fd4..479b71c 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -30,6 +30,7 @@ double converter_hour_in_sec(double hour){ return time; } +// Converts Seconds in Hours double converter_sec_in_hour(double sec){ double time = sec / 60 / 60; return time; From 92335f301702dea5cc76ff5d5a91df499536bf25 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 19:05:47 +0100 Subject: [PATCH 56/67] refactoring: descriptions to complex functions in operation handler --- src/operationHandler.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/operationHandler.c b/src/operationHandler.c index 519fc31..6fb44b8 100644 --- a/src/operationHandler.c +++ b/src/operationHandler.c @@ -38,6 +38,7 @@ int* evaluateInput(char* input, int operation) { return result; } +// formatting check of string bool containsTwoNumbers(const char* str) { int numbersCount = 0; bool hasSpace = false; @@ -62,6 +63,7 @@ bool containsTwoNumbers(const char* str) { return (numbersCount == 2 && hasSpace); } +// extracting of first number and removing from string int extractFirstNumber(char* str) { int number = 0; bool isInNumber = false; From 60744a93dd32a9a10f6869de55de74cae96051c3 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 19:10:23 +0100 Subject: [PATCH 57/67] added kg to ton converter --- src/convert_kg_to_ton.c | 6 ++++++ src/convert_kg_to_ton.h | 13 +++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/convert_kg_to_ton.c create mode 100644 src/convert_kg_to_ton.h diff --git a/src/convert_kg_to_ton.c b/src/convert_kg_to_ton.c new file mode 100644 index 0000000..51cea7a --- /dev/null +++ b/src/convert_kg_to_ton.c @@ -0,0 +1,6 @@ + +#include "convert_kg_to_ton.h" + +double kg_to_tons(double kilograms) { + return kilograms / 1000.0; // 1 ton = 1000 kilograms +} diff --git a/src/convert_kg_to_ton.h b/src/convert_kg_to_ton.h new file mode 100644 index 0000000..01f9369 --- /dev/null +++ b/src/convert_kg_to_ton.h @@ -0,0 +1,13 @@ + +#ifndef THEADMIRALS_CONVERT_KG_TO_TON_H +#define THEADMIRALS_CONVERT_KG_TO_TON_H + + + + +double kg_to_tons(double kilograms); + + + + +#endif //THEADMIRALS_CONVERT_KG_TO_TON_H From 5fd80942f4ca3ab84fc02c96295c0ae3e27854fe Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:10:51 +0100 Subject: [PATCH 58/67] calculate Factorial function added --- src/calculateFactorial.c | 19 +++++++++++++++++++ src/calculateFactorial.h | 8 ++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/calculateFactorial.c create mode 100644 src/calculateFactorial.h diff --git a/src/calculateFactorial.c b/src/calculateFactorial.c new file mode 100644 index 0000000..adb19d0 --- /dev/null +++ b/src/calculateFactorial.c @@ -0,0 +1,19 @@ + + +#include "calculateFactorial.h" + +int calculateFactorial_integer(int n) { + if (n < 0) { + + } else if (n == 0 || n == 1) { + + return 1; + } else { + + int result = 1; + for (int i = 2; i <= n; ++i) { + result *= i; + } + return result; + } +} diff --git a/src/calculateFactorial.h b/src/calculateFactorial.h new file mode 100644 index 0000000..f48849b --- /dev/null +++ b/src/calculateFactorial.h @@ -0,0 +1,8 @@ + + +#ifndef THEADMIRALS_CALCULATEFACTORIAL_H +#define THEADMIRALS_CALCULATEFACTORIAL_H + +int calculateFactorial_integer(int n); + +#endif //THEADMIRALS_CALCULATEFACTORIAL_H From 83ecc563645e940f723ee0cadc985f5e1f12c9ff Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 19:11:20 +0100 Subject: [PATCH 59/67] refactoring: change var name --- src/convert_time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/convert_time.c b/src/convert_time.c index 479b71c..86d93ca 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -42,6 +42,6 @@ double converter_days_to_years(double days){ } double converter_years_to_days(double years){ - double time = years * 365; - return time; + double amount = years * 365; + return amount; } \ No newline at end of file From b63bbe41bbfe2bb1fde7d94a370c08aee1dd1560 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 19:15:00 +0100 Subject: [PATCH 60/67] refactoring: changed variables --- src/arithmeticMultiplication_Double.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arithmeticMultiplication_Double.c b/src/arithmeticMultiplication_Double.c index 845eaa1..f83f0fb 100644 --- a/src/arithmeticMultiplication_Double.c +++ b/src/arithmeticMultiplication_Double.c @@ -2,11 +2,11 @@ #include "arithmeticMultiplication_Double.h" -double* multiplication_double(double num1, double num2) { +double* multiplication_double(double a, double b) { double* result = (double*)malloc(sizeof(double)); if (result == NULL) { return NULL; // Handle memory allocation failure } - *result = num1 * num2; + *result = a * b; return result; } From 1466519e36bb98d57a66a676a25f4a9b14d526d5 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 19:15:17 +0100 Subject: [PATCH 61/67] refactoring: changed variables --- src/arithmeticMultiplication_Float.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arithmeticMultiplication_Float.c b/src/arithmeticMultiplication_Float.c index 1014f33..8e063f2 100644 --- a/src/arithmeticMultiplication_Float.c +++ b/src/arithmeticMultiplication_Float.c @@ -1,12 +1,12 @@ #include "arithmeticMultiplication_Float.h" #include -float* multiplication_float(float num1, float num2) { +float* multiplication_float(float a, float b) { float* result = (float*)malloc(sizeof(float)); if (result == NULL) { return NULL; // Handle memory allocation failure } - *result = num1 * num2; + *result = a * b; return result; } From db69a56b09e6ccf64c784dd054f8f3f94b0e213a Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 19:19:50 +0100 Subject: [PATCH 62/67] Expanded arithmetic addition by double calculation --- src/arithmeticAddition.c | 6 ++++++ src/arithmeticAddition.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/arithmeticAddition.c b/src/arithmeticAddition.c index d75b63f..81ba426 100644 --- a/src/arithmeticAddition.c +++ b/src/arithmeticAddition.c @@ -10,4 +10,10 @@ int* addition_integer(int num1, int num2) { int* result = malloc(sizeof(int)); *result = num1 + num2; return result; +} + +double* addition_double(double num1, double num2) { + double* result = malloc(sizeof(double)); + *result = num1+num2; + return result; } \ No newline at end of file diff --git a/src/arithmeticAddition.h b/src/arithmeticAddition.h index 92907ff..ab7db2a 100644 --- a/src/arithmeticAddition.h +++ b/src/arithmeticAddition.h @@ -3,4 +3,6 @@ int* addition_integer(int, int); +double* addition_double(double, double); + #endif //THEADMIRALS_ARITHMETICADDITION_H From 3befbff35d0c82f04eeb08712474128fe2517959 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 19:23:15 +0100 Subject: [PATCH 63/67] refactoring: changed variable names --- src/arithmeticAddition.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arithmeticAddition.c b/src/arithmeticAddition.c index 81ba426..7d664f2 100644 --- a/src/arithmeticAddition.c +++ b/src/arithmeticAddition.c @@ -12,8 +12,8 @@ int* addition_integer(int num1, int num2) { return result; } -double* addition_double(double num1, double num2) { +double* addition_double(double number1, double number2) { double* result = malloc(sizeof(double)); - *result = num1+num2; + *result = number1+number2; return result; } \ No newline at end of file From e7f5c2db8e6fdf892e487dfbb4dc9de8ebaa71fc Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:26:52 +0100 Subject: [PATCH 64/67] calculate Factorial specification --- src/calculateFactorial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calculateFactorial.c b/src/calculateFactorial.c index adb19d0..c3a1b48 100644 --- a/src/calculateFactorial.c +++ b/src/calculateFactorial.c @@ -1,7 +1,7 @@ #include "calculateFactorial.h" - +//Factorial int calculateFactorial_integer(int n) { if (n < 0) { From 82e32bf203946d07aa35cfa98aa39226c01fef1f Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:27:36 +0100 Subject: [PATCH 65/67] calculate Factorial specification --- src/calculateFactorial.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/calculateFactorial.c b/src/calculateFactorial.c index c3a1b48..0c6cbf0 100644 --- a/src/calculateFactorial.c +++ b/src/calculateFactorial.c @@ -2,6 +2,7 @@ #include "calculateFactorial.h" //Factorial +// Function for Factorial int calculateFactorial_integer(int n) { if (n < 0) { From 66234bc7d9352881032fa5b269f743ae8f8495a3 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Thu, 8 Feb 2024 19:28:42 +0100 Subject: [PATCH 66/67] Expanded arithmetic addition by multiple datatypes --- src/arithmeticAddition.c | 12 ++++++++++++ src/arithmeticAddition.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/arithmeticAddition.c b/src/arithmeticAddition.c index 7d664f2..8f93738 100644 --- a/src/arithmeticAddition.c +++ b/src/arithmeticAddition.c @@ -16,4 +16,16 @@ double* addition_double(double number1, double number2) { double* result = malloc(sizeof(double)); *result = number1+number2; return result; +} + +float* addition_float(float number1, float number2) { + float* result = malloc(sizeof(float)); + *result = number1+number2; + return result; +} + +long* addition_long(long number1, long number2) { + long* result = malloc(sizeof(long)); + *result = number1+number2; + return result; } \ No newline at end of file diff --git a/src/arithmeticAddition.h b/src/arithmeticAddition.h index ab7db2a..3bad5ba 100644 --- a/src/arithmeticAddition.h +++ b/src/arithmeticAddition.h @@ -5,4 +5,8 @@ int* addition_integer(int, int); double* addition_double(double, double); +float* addition_float(float, float); + +long* addition_long(long, long); + #endif //THEADMIRALS_ARITHMETICADDITION_H From 838f3180b5c005b22f74f24708a54612b350ee8f Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 19:32:27 +0100 Subject: [PATCH 67/67] refactoring: added descriptions to a function --- 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 f83f0fb..3207551 100644 --- a/src/arithmeticMultiplication_Double.c +++ b/src/arithmeticMultiplication_Double.c @@ -7,6 +7,6 @@ double* multiplication_double(double a, double b) { if (result == NULL) { return NULL; // Handle memory allocation failure } - *result = a * b; + *result = a * b; // we multiply a times b and the result gets saved in *result return result; }