From 83b4f6496ecac263025dce446959d7a492fee700 Mon Sep 17 00:00:00 2001 From: Sandro Welte Date: Thu, 8 Feb 2024 16:55:10 +0100 Subject: [PATCH 001/155] 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 002/155] 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 003/155] 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 004/155] 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 005/155] 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 006/155] 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 007/155] 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 008/155] 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 009/155] 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 010/155] 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 011/155] 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 012/155] 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 013/155] 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 014/155] 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 015/155] 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 016/155] 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 017/155] 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 018/155] 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 019/155] 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 020/155] 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 021/155] 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 022/155] 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 023/155] 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 024/155] 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 025/155] 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 026/155] 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 027/155] 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 028/155] 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 029/155] 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 030/155] 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 031/155] 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 032/155] 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 033/155] 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 034/155] 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 035/155] 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 036/155] 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 037/155] 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 038/155] 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 039/155] 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 040/155] 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 041/155] 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 042/155] 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 043/155] 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 044/155] 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 045/155] 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 046/155] 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 047/155] 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 048/155] 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 049/155] 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 050/155] 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 051/155] 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 052/155] 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 053/155] 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 054/155] 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 055/155] 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 056/155] 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 057/155] 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 058/155] 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 059/155] 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 060/155] 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 061/155] 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 062/155] 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 063/155] 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 064/155] 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 065/155] 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 066/155] 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 067/155] 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; } From 8c1db561bfa83a7f3e44accf4cdc42d249106f94 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Thu, 8 Feb 2024 19:34:24 +0100 Subject: [PATCH 068/155] 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 069/155] 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 070/155] 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 071/155] 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 072/155] 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 073/155] 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 074/155] 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 075/155] 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 076/155] 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 077/155] 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 078/155] 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 079/155] 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 080/155] 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 081/155] 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 082/155] 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 083/155] 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 084/155] 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 085/155] 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 086/155] 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 087/155] 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 088/155] 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 089/155] 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 090/155] 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 091/155] 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 092/155] 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 093/155] 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 094/155] 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 095/155] 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 096/155] 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 097/155] 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 098/155] 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 099/155] 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 100/155] 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 101/155] 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 102/155] 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 103/155] 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 104/155] 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 105/155] 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 106/155] 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 107/155] 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 108/155] 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 109/155] 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 110/155] 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 111/155] 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 112/155] 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 113/155] 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 114/155] 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 115/155] 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 116/155] 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 117/155] 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 118/155] 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 119/155] 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 120/155] 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 121/155] 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 122/155] 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 123/155] 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 124/155] 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 125/155] 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 126/155] 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 127/155] 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 128/155] 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 129/155] 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 130/155] 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 131/155] 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 132/155] 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 133/155] 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 134/155] 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 135/155] 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 136/155] 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 137/155] 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 From 8fcae449cc6740834c5111633b4f17dd2898a7a6 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Fri, 9 Feb 2024 12:24:41 +0100 Subject: [PATCH 138/155] refactoring: changed descriptions for 3 subtraction function --- src/arithmeticSubtraction.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arithmeticSubtraction.c b/src/arithmeticSubtraction.c index bbabad9..339431b 100644 --- a/src/arithmeticSubtraction.c +++ b/src/arithmeticSubtraction.c @@ -2,21 +2,21 @@ #include -// arithmetic subtraction integer +// arithmetic subtraction for integer int* subtraction_integer(int a, int b) { int* result= malloc(sizeof (int)); *result=a - b; return result; } -// arithmetic subtraction float +// arithmetic subtraction for float float* subtraction_float(float a, float b) { float* result= malloc(sizeof (float)); *result=a - b; return result; } -// arithmetic subtraction double +// arithmetic subtraction for double double* subtraction_double(double a, double b) { double* result= malloc(sizeof (double)); *result=a - b; From 0609ed4765a882a509418b3d783282e3c75cb1dc Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Fri, 9 Feb 2024 12:31:04 +0100 Subject: [PATCH 139/155] refactoring: changed description mistake for kilometers --- 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 bf56016..4237094 100644 --- a/src/convert_M_in_KM.c +++ b/src/convert_M_in_KM.c @@ -1,6 +1,6 @@ #include "convert_M_in_KM.h" -// convert length for double metre into kilometre +// convert length for double metre into kilometers double meter_to_kilometer(double meter) { return meter / 1000.0; } From 20631017c988a60137353b20d7072cf0e38f507d Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Fri, 9 Feb 2024 12:44:52 +0100 Subject: [PATCH 140/155] Updated specification and gap at 3 trigonometric function --- src/trigonometricFunctions.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/trigonometricFunctions.c b/src/trigonometricFunctions.c index 6dbdfaf..db262a0 100644 --- a/src/trigonometricFunctions.c +++ b/src/trigonometricFunctions.c @@ -4,21 +4,19 @@ #include #include //function for trigonometric -//Function 1 double +//Function 1 for double double* calculate_sin_double(double angle) { double* result= malloc(sizeof (double)); *result=sin(angle); return result; } -//Function 2 double - +//Function 2 for double double* calculate_cos_double(double angle) { double* result= malloc(sizeof (double)); *result=cos(angle); return result; } -//Function 3 double - +//Function 3 for double double* calculate_tan_double(double angle) { double* result= malloc(sizeof (double)); *result=tan(angle); From 93bd716e6d6c1b7a180797039a9797155b3a1c2b Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Fri, 9 Feb 2024 16:09:57 +0100 Subject: [PATCH 141/155] Added multiple tests for arithmetic addition methods --- test/test_arithmeticAddition.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/test_arithmeticAddition.c b/test/test_arithmeticAddition.c index a7089a6..5e261b2 100644 --- a/test/test_arithmeticAddition.c +++ b/test/test_arithmeticAddition.c @@ -21,4 +21,25 @@ void test_arithmeticAddition_numberplusmaxintegervalueequalsnull(void) { int* result; result = addition_integer(INT_MAX, 1); TEST_ASSERT_NULL(result); -} \ No newline at end of file +} + +void test_arithmeticAddition_doublenumbercalculationequalscorrectdoublenumber(void) { + double expectedResult = 5.500000; + double* result; + result = addition_double(3.5, 2.0); + TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result); +} + +void test_arithmeticAddition_longnumbercalculationequalscorrectlong(void) { + long expectedResult = 10; + long* result; + result = addition_long(5, 5); + TEST_ASSERT_EQUAL_INT(expectedResult, *result); +} + +void test_arithmeticAddition_floatnumbercalculationequalsfloat(void) { + float expectedResult = 5.5; + float* result; + result = addition_float(3.5, 2.0); + TEST_ASSERT_EQUAL_FLOAT(expectedResult, *result); +} From 057982d1fb4c70735c8b510423799d066320e2f2 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Fri, 9 Feb 2024 16:13:49 +0100 Subject: [PATCH 142/155] Added more tests for division methods with different datatypes --- test/test_arithmeticDivision.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/test_arithmeticDivision.c b/test/test_arithmeticDivision.c index 6428ea0..0ae60eb 100644 --- a/test/test_arithmeticDivision.c +++ b/test/test_arithmeticDivision.c @@ -17,3 +17,24 @@ void test_arithmeticDivision_numberdividedbynumberequalsnumber(void) { result = division_integer(14, 7); TEST_ASSERT_EQUAL_INT(expectedResult, *result); } + +void test_arithmeticDivision_longdividedbylongequalscorrectlong(void) { + long expectedResult = 5; + long* result; + result = division_long(10, 2); + TEST_ASSERT_EQUAL_INT(expectedResult, *result); +} + +void test_arithmeticDivsion_floatdividedbyfloatequalscorrectfloat(void) { + float expectedResult = 5.0; + float* result; + result = division_float(10.0, 2.0); + TEST_ASSERT_EQUAL_FLOAT(expectedResult, *result); +} + +void test_arithmeticDivision_doubledividedbydoublequalscorrectdouble(void) { + double expectedResult = 5.0; + double* result; + result = division_double(10.0, 2.0); + TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result); +} From f212040c96b85e88490736028946aa1c49263d37 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Fri, 9 Feb 2024 16:18:24 +0100 Subject: [PATCH 143/155] Implemented unittest for input handler method --- test/test_inputHandler.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/test_inputHandler.c diff --git a/test/test_inputHandler.c b/test/test_inputHandler.c new file mode 100644 index 0000000..5cf92c7 --- /dev/null +++ b/test/test_inputHandler.c @@ -0,0 +1,18 @@ +#include "../src/inputHandler.h" +#include "unity.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + + +void test_inputHandler_returntwoforinputminus(void) { + int expectedResult = 2; + int result; + result = getOperationIdBySymbol('-'); + TEST_ASSERT_EQUAL_INT(expectedResult, result); +} \ No newline at end of file From 6c33f586e6b52fc0394774c78171fa4b6985ee48 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Fri, 9 Feb 2024 16:24:43 +0100 Subject: [PATCH 144/155] refactoring: implemented descriptions for methods in arithmetic addition --- src/arithmeticAddition.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/arithmeticAddition.c b/src/arithmeticAddition.c index 173c438..46a2e37 100644 --- a/src/arithmeticAddition.c +++ b/src/arithmeticAddition.c @@ -3,6 +3,7 @@ #include #include +// addition for two integer inputs (no decimal number) int* addition_integer(int num1, int num2) { if ((num2 > 0 && num1 > INT_MAX - num2) || (num2 < 0 && num1 < INT_MIN - num2)) { return NULL; @@ -12,18 +13,21 @@ int* addition_integer(int num1, int num2) { return result; } +// addition for two double inputs (decimal number) double* addition_double(double num1, double num2) { double* result = malloc(sizeof(double)); *result = num1+num2; return result; } +// addition for two float inputs (decimal number) float* addition_float(float num1, float num2) { float* result = malloc(sizeof(float)); *result = num1+num2; return result; } +// addition for two long inputs (no decimal number) long* addition_long(long num1, long num2) { long* result = malloc(sizeof(long)); *result = num1+num2; From 54be43dd7b708356e8188f5fa06793457e3cd033 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Fri, 9 Feb 2024 16:25:50 +0100 Subject: [PATCH 145/155] Added test for different input in input handler --- test/test_inputHandler.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/test_inputHandler.c b/test/test_inputHandler.c index 5cf92c7..e7bff29 100644 --- a/test/test_inputHandler.c +++ b/test/test_inputHandler.c @@ -15,4 +15,11 @@ void test_inputHandler_returntwoforinputminus(void) { int result; result = getOperationIdBySymbol('-'); TEST_ASSERT_EQUAL_INT(expectedResult, result); -} \ No newline at end of file +} + +void test_inputHandler_returnoneforinputplus(void) { + int expectedResult = 1; + int result; + result = getOperationIdBySymbol('+'); + TEST_ASSERT_EQUAL_INT(expectedResult, result); +} From 7b3854c20195f45d23bd8f39526fbce2092bc053 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Fri, 9 Feb 2024 16:27:38 +0100 Subject: [PATCH 146/155] Implemented input handler test for valid method --- test/test_inputHandler.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test_inputHandler.c b/test/test_inputHandler.c index e7bff29..72dfd24 100644 --- a/test/test_inputHandler.c +++ b/test/test_inputHandler.c @@ -23,3 +23,10 @@ void test_inputHandler_returnoneforinputplus(void) { result = getOperationIdBySymbol('+'); TEST_ASSERT_EQUAL_INT(expectedResult, result); } + +void test_inputHandler_returnzeroforinvalidinput(void) { + int expectedResult = 0; + int result; + result = isOperationIdValid(0); + TEST_ASSERT_EQUAL_INT(expectedResult, result); +} From 07e2db5698093db634eea689edc486a00306bd57 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Fri, 9 Feb 2024 16:32:58 +0100 Subject: [PATCH 147/155] Added final test for input handler --- test/test_inputHandler.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test_inputHandler.c b/test/test_inputHandler.c index 72dfd24..4b4f874 100644 --- a/test/test_inputHandler.c +++ b/test/test_inputHandler.c @@ -30,3 +30,10 @@ void test_inputHandler_returnzeroforinvalidinput(void) { result = isOperationIdValid(0); TEST_ASSERT_EQUAL_INT(expectedResult, result); } + +void test_inputHandler_returnoneifinputtoobig(void) { + int expectedResult = 1; + int result; + result = isNumberTooBig(300); + TEST_ASSERT_EQUAL_INT(expectedResult, result); +} \ No newline at end of file From bc4efb63bbaf390c77a22817ea2e2a112df4c866 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Fri, 9 Feb 2024 16:33:49 +0100 Subject: [PATCH 148/155] refactoring: Change to better 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 2114697..b938c82 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -38,8 +38,8 @@ double converter_sec_in_hour(double sec){ // Converts Days in Years double converter_days_to_years(double days){ - double time = days / 365; - return time; + double years = days / 365; + return years; } // convert Years in days From 0b58c8222f161639b584c3e64f8a82a5e495d26f Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Fri, 9 Feb 2024 16:34:26 +0100 Subject: [PATCH 149/155] refactoring: Change to better 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 b938c82..ce48b2f 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -32,8 +32,8 @@ double converter_hour_in_sec(double hour){ // Converts Seconds in Hours double converter_sec_in_hour(double sec){ - double time = sec / 60 / 60; - return time; + double hours = sec / 60 / 60; + return hours; } // Converts Days in Years From 699d55a1065968511fea6a02f57d4c8bbb5c66b8 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Fri, 9 Feb 2024 16:34:43 +0100 Subject: [PATCH 150/155] refactoring: Change to better 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 ce48b2f..578baab 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -26,8 +26,8 @@ double converter_min_to_hour(double min){ // Converts Hours in Seconds double converter_hour_in_sec(double hour){ - double time = hour * 60 * 60; - return time; + double secs = hour * 60 * 60; + return secs; } // Converts Seconds in Hours From 39b88136b70221eef5aac90598c66324f8534341 Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Fri, 9 Feb 2024 16:34:58 +0100 Subject: [PATCH 151/155] refactoring: Change to better 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 578baab..a82fab0 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -20,8 +20,8 @@ double converter_hour_to_min(double hour){ // Converts Minutes To Hours double converter_min_to_hour(double min){ - double time = min / 60; - return time; + double hours = min / 60; + return hours; } // Converts Hours in Seconds From 8120a3c4465b0dbec486f990764d7bd4e451178a Mon Sep 17 00:00:00 2001 From: Jonas Zitzmann Date: Fri, 9 Feb 2024 16:36:42 +0100 Subject: [PATCH 152/155] refactoring: Change to better 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 a82fab0..40a9403 100644 --- a/src/convert_time.c +++ b/src/convert_time.c @@ -14,8 +14,8 @@ double converter_min_to_sec(double min){ // Converts Hours to Minutes double converter_hour_to_min(double hour){ - double time = hour * 60; - return time; + double min = hour * 60; + return min; } // Converts Minutes To Hours From 2330458d3d27b5ff1496d6e53cadca8099018000 Mon Sep 17 00:00:00 2001 From: Eric Bagus Date: Fri, 9 Feb 2024 16:38:36 +0100 Subject: [PATCH 153/155] refactoring: realigned code and removed multiple comments --- src/convert_kg_to_ton.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/convert_kg_to_ton.h b/src/convert_kg_to_ton.h index cc38ea6..032dc7f 100644 --- a/src/convert_kg_to_ton.h +++ b/src/convert_kg_to_ton.h @@ -1,19 +1,7 @@ - #ifndef THEADMIRALS_CONVERT_KG_TO_TON_H #define THEADMIRALS_CONVERT_KG_TO_TON_H - - - // Convert kilograms to tons -// Parameters: -// kilograms: weight in kilograms -// Returns: -// The equivalent weight in tons - double kg_to_tons(double kilograms); - - - #endif //THEADMIRALS_CONVERT_KG_TO_TON_H From e6ae03f33b60824edcb45ce4ddc0e852b488cca6 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Fri, 9 Feb 2024 16:39:35 +0100 Subject: [PATCH 154/155] refactoring: changed description mistake --- 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 4237094..bf56016 100644 --- a/src/convert_M_in_KM.c +++ b/src/convert_M_in_KM.c @@ -1,6 +1,6 @@ #include "convert_M_in_KM.h" -// convert length for double metre into kilometers +// convert length for double metre into kilometre double meter_to_kilometer(double meter) { return meter / 1000.0; } From 7eb4a20bfcf83a407bf2aa1abcf053f693e0cc23 Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Fri, 9 Feb 2024 16:40:52 +0100 Subject: [PATCH 155/155] refactoring: changed description mistake --- 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 bf56016..4980a96 100644 --- a/src/convert_M_in_KM.c +++ b/src/convert_M_in_KM.c @@ -1,6 +1,6 @@ #include "convert_M_in_KM.h" -// convert length for double metre into kilometre +//convert length for double metre into kilometre double meter_to_kilometer(double meter) { return meter / 1000.0; }