diff --git a/.gitignore b/.gitignore index dce188f..236b96f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ -.DS_Store -.swp +*.DS_Store +*.vscode +a.out +build/ +*.DSYM diff --git a/build-project.sh b/build-project.sh index 43a0588..837fe14 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,5 +1,54 @@ +trap 'echo "Interrupted"; + rm main; + cp employeeLogin.c.bak employeeLogin.c; + cp mainMenu.c.bak mainMenu.c; + cp createEmployeeAccount.c.bak createEmployeeAccount.c; + cp _file_information.h.bak _file_information.h; + rm employeeLogin.c.bak; + rm mainMenu.c.bak; + rm createEmployeeAccount.c.bak; + rm _file_information.h.bak; + cd ..; + rm -r build; exit' SIGINT + clear +ceedling test:all +rm -r build/ + + cd src/ -gcc main.c -o main + +sed '/John Doe/,$d' employeesCredentialsList.txt > temp.txt +mv temp.txt employeesCredentialsList.txt + +sed '/Name : John/,$d' employeesData.txt > temp.txt +mv temp.txt employeesData.txt + +# backup files +for file in employeeLogin.c mainMenu.c createEmployeeAccount.c _file_information.h; do + cp "$file" "$file.bak" +done + + +# remove 'src/' +for file in employeeLogin.c createEmployeeAccount.c _file_information.h; do + sed -i 's/src\///g' "$file" +done + + +gcc mainMenu.c error.c createEmployeeAccount.c showGeneralInfoEmployee.c employeeLogin.c createCustomer.c helperFunctions.c loginCustomer.c customerMenu.c main.c calculatorAdd.c calculatorDivide.c calculatorFactorial.c calculatorGetUserInput.c calculatorGetUserInputFactorial.c calculatorMultiply.c calculatorSubtract.c displayMenuCalculator.c checkLoanEligibility.c currencyExchange.c currentCustomerAccountBalance.c depositMoney.c displayDisclaimer.c interestCalculator.c requestLoan.c sendMoney.c updateCustomerAccountBalance.c withdrawMoney.c -o main ./main rm main + +# restore backups +for file in employeeLogin.c mainMenu.c createEmployeeAccount.c _file_information.h; do + cp "$file.bak" "$file" +done + +# remove backups +for file in employeeLogin.c.bak mainMenu.c.bak createEmployeeAccount.c.bak _file_information.h.bak; do + rm "$file" +done + + +cd .. diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..b9be31d --- /dev/null +++ b/project.yml @@ -0,0 +1,126 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:tests/** + - -:tests/support + - +:tests/** + - -:tests/support + :source: + - src/createCustomer.* + - src/customerLogin.* + - src/helperFunctions.* + - src/error.* + - src/createEmployeeAccount.* + - src/employeeLogin.* + - src/mainMenu.* + - src/showGeneralInfoEmployee.* + - src/calculatorAdd.* + - src/calculatorDivide.* + - src/calculatorFactorial.* + - src/calculatorGetUserInput.* + - src/calculatorGetUserInputFactorial.* + - src/calculatorMultiply.* + - src/calculatorSubtract.* + - src/displayMenuCalculator.* + - src/requestLoan.* + - src/checkLoanEligibility.* + - src/currenczExchange.* + - src/currentCustomerAccountBalance.* + - src/depositMoney.* + - src/displayDisclaimer.* + - src/sendMoney.* + :support: + - tests/support + - tests/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/.vscode/c_cpp_properties.json b/src/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..5a5047e --- /dev/null +++ b/src/.vscode/c_cpp_properties.json @@ -0,0 +1,21 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "windowsSdkVersion": "10.0.19041.0", + "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "windows-msvc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/src/CustomerData.txt b/src/CustomerData.txt new file mode 100644 index 0000000..41693a1 --- /dev/null +++ b/src/CustomerData.txt @@ -0,0 +1,69 @@ +1234=example +ID=1234 +forename=Test +Surname=Testermann +password=example +balance=150.5 + +1235=example +ID=1235 +forename=Test +Surname=Testermann +password=example +balance=290 + +1236=example +ID=1236 +forename=Test +Surname=Testermann +password=example +balance=194.5 + +1237=example +ID=1237 +forename=Test +Surname=Testermann +password=example +balance=340 + +1238=example +ID=1238 +forename=Test +Surname=Testermann +password=example +balance=1200 + +1666=example +ID=1237 +forename=Test +Surname=Testermann +password=example +balance=340 + +1327=example +ID=1238 +forename=Test +Surname=Testermann +password=example +balance=1200 +2189837=1234 +ID=2189837 +Forename=Mark +Surname=Karlsen +Password=1234 +Balance=50.0000€ + +6984947=okdsjhasdjhksdj +ID=6984947 +Forename=Karl +Surname=Marx +Password=okdsjhasdjhksdj +balance=610 + +7765335=123 +ID=7765335 +Forename=Friedrich +Surname=Moller +Password=123 +balance=858.2 + diff --git a/src/_file_information.h b/src/_file_information.h new file mode 100644 index 0000000..9334868 --- /dev/null +++ b/src/_file_information.h @@ -0,0 +1,2 @@ +#define MAX_LENGTH 200 +#define CUSTOMER_DATA_FILE "src/CustomerData.txt" diff --git a/src/calculatorAdd.c b/src/calculatorAdd.c new file mode 100644 index 0000000..99c892a --- /dev/null +++ b/src/calculatorAdd.c @@ -0,0 +1,12 @@ +#include "calculatorAdd.h" + + +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + +float calculatorAdd(float num1,float num2) +{ + return num1+num2; +} + diff --git a/src/calculatorAdd.h b/src/calculatorAdd.h new file mode 100644 index 0000000..30411f8 --- /dev/null +++ b/src/calculatorAdd.h @@ -0,0 +1,3 @@ +#include +#include +float calculatorAdd(float num1,float num2); diff --git a/src/calculatorDivide.c b/src/calculatorDivide.c new file mode 100644 index 0000000..86e0a5c --- /dev/null +++ b/src/calculatorDivide.c @@ -0,0 +1,11 @@ +#include "calculatorDivide.h" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + +float calculatorDivide(float num1, float num2) +{ + return num1 / num2; +} + diff --git a/src/calculatorDivide.h b/src/calculatorDivide.h new file mode 100644 index 0000000..2958a72 --- /dev/null +++ b/src/calculatorDivide.h @@ -0,0 +1,3 @@ +#include +#include +float calculatorDivide(float num1, float num2); \ No newline at end of file diff --git a/src/calculatorFactorial.c b/src/calculatorFactorial.c new file mode 100644 index 0000000..e95fd11 --- /dev/null +++ b/src/calculatorFactorial.c @@ -0,0 +1,18 @@ +#include "calculatorFactorial.h" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + +int calculatorFactorial(int num) //implement recursion. The function calls itself so many times, till the breaking condition is fulfilled. +{ + if (num == 0) //breaking condition + { + return 1; + } + else + { + return num * calculatorFactorial(num - 1); //If its not breaking condition, then multiply the number with the same function implemented on the previous number. Eventually it will reach breaking condition. + } +} + diff --git a/src/calculatorFactorial.h b/src/calculatorFactorial.h new file mode 100644 index 0000000..7d2fafa --- /dev/null +++ b/src/calculatorFactorial.h @@ -0,0 +1,3 @@ +#include +#include +int calculatorFactorial(int num); diff --git a/src/calculatorGetUserInput.c b/src/calculatorGetUserInput.c new file mode 100644 index 0000000..0882efa --- /dev/null +++ b/src/calculatorGetUserInput.c @@ -0,0 +1,26 @@ +#include "calculatorGetUserInput.h" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + +int allowOnly() //int allowOnly() is helpful for indirectly testing void calculatorGetUserInput(). +{ + const int a = 1; + if(a == 1) //Just a random constant which has a role in testing + { + return 1; + } +} + +void calculatorGetUserInput(float *num1, float *num2) +{ + if (allowOnly() == 1) //only if int allowOnly() returns 1, void calculatorGetUserInput will display the desired output. + { + printf("number1: "); + scanf("%f", num1); + printf("number2: "); + scanf("%f", num2); + } +} + + diff --git a/src/calculatorGetUserInput.h b/src/calculatorGetUserInput.h new file mode 100644 index 0000000..96909c3 --- /dev/null +++ b/src/calculatorGetUserInput.h @@ -0,0 +1,5 @@ +#include +#include +void calculatorGetUserInput(float *num1, float *num2); +int allowOnly(); +//const int a = 1; //Just a random constant which has a role in testing diff --git a/src/calculatorGetUserInputFactorial.c b/src/calculatorGetUserInputFactorial.c new file mode 100644 index 0000000..40ab76a --- /dev/null +++ b/src/calculatorGetUserInputFactorial.c @@ -0,0 +1,22 @@ +#include "calculatorGetUserInputFactorial.h" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + +int allowWhen()// int allowWhen() is helpful for indirectly unittesting void calculatorGetUserInputFactorial() +{ + //ufc is unitTestConstant, which has a role in unittesting void calculatorGetUserInputFactorial() + const int utc = 1; + if(utc == 1) + return 1; +} + +void calculatorGetUserInputFactorial(int *num) +{ + if(allowWhen() == 1)//Only when int allowWhen() returns 1, void calculatorGetUserInputFactorial() will display desired Output + { + printf("num: "); + scanf("%d", num); + } +} + diff --git a/src/calculatorGetUserInputFactorial.h b/src/calculatorGetUserInputFactorial.h new file mode 100644 index 0000000..17eccac --- /dev/null +++ b/src/calculatorGetUserInputFactorial.h @@ -0,0 +1,4 @@ +#include +#include +int allowWhen(); +void calculatorGetUserInputFactorial(int *num); \ No newline at end of file diff --git a/src/calculatorMultiply.c b/src/calculatorMultiply.c new file mode 100644 index 0000000..42e1763 --- /dev/null +++ b/src/calculatorMultiply.c @@ -0,0 +1,10 @@ +#include "calculatorMultiply.h" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + +float calculatorMultiply(float num1, float num2) +{ + return num1 * num2; +} + diff --git a/src/calculatorMultiply.h b/src/calculatorMultiply.h new file mode 100644 index 0000000..32ecad9 --- /dev/null +++ b/src/calculatorMultiply.h @@ -0,0 +1,3 @@ +#include +#include +float calculatorMultiply(float num1, float num2); \ No newline at end of file diff --git a/src/calculatorSubtract.c b/src/calculatorSubtract.c new file mode 100644 index 0000000..d460458 --- /dev/null +++ b/src/calculatorSubtract.c @@ -0,0 +1,12 @@ +#include "calculatorSubtract.h" + +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + +float calculatorSubtract (float num1, float num2) +{ + return num1 - num2; +} + + diff --git a/src/calculatorSubtract.h b/src/calculatorSubtract.h new file mode 100644 index 0000000..6794377 --- /dev/null +++ b/src/calculatorSubtract.h @@ -0,0 +1,4 @@ +#include +#include + +float calculatorSubtract(float num1, float num2); \ No newline at end of file diff --git a/src/checkLoanEligibility.c b/src/checkLoanEligibility.c new file mode 100644 index 0000000..e3ba64c --- /dev/null +++ b/src/checkLoanEligibility.c @@ -0,0 +1,30 @@ +#include "checkLoanEligibility.h" +#include "_file_information.h" + +bool checkLoanEligibility(int user_id) { + + // Eligible only when user is present in CustomerDataFile + + bool keep_reading = true; + bool eligibility = false; + char buffer[MAX_LENGTH]; + + FILE *file = fopen(CUSTOMER_DATA_FILE, "r"); + + while(keep_reading) { + fgets(buffer, MAX_LENGTH, file); + + if (feof(file)) { + keep_reading = false; + } + if(user_id == atoi(buffer)) { + eligibility = true; + keep_reading = false; + } + + } + + fclose(file); + return eligibility; + +} \ No newline at end of file diff --git a/src/checkLoanEligibility.h b/src/checkLoanEligibility.h new file mode 100644 index 0000000..4415c60 --- /dev/null +++ b/src/checkLoanEligibility.h @@ -0,0 +1,10 @@ +#ifndef CHECKLOANELIGIBILITY_H_ +#define CHECKLOANELIGIBILITY_H_ + +#include +#include +#include + +bool checkLoanEligibility(int user_id); + +#endif \ No newline at end of file diff --git a/src/createCustomer.c b/src/createCustomer.c new file mode 100644 index 0000000..9d3a93a --- /dev/null +++ b/src/createCustomer.c @@ -0,0 +1,129 @@ +#include "createCustomer.h" +/*Code written by Julius Philipp Engel, fdai7057*/ +int generateID() +{ + srand(clock()); + const int MIN = 1000000, MAX = 9000001; + int pseudoRandomIDForCustomer = (rand() % MAX) + MIN; + return pseudoRandomIDForCustomer; +} + +void collectCustomerProperties() +{ + customer_t instance; + instance.forename = calloc(15+1,sizeof(char)); + instance.surname = calloc(15+1,sizeof(char)); + instance.password = calloc(20+1,sizeof(char)); + instance.ID = generateID(); + int letterCounter = 0; + int letterMaximum = 15; + int errorResult = 0; + char userInput=' '; + bool inputTooLong = false, foundComma = false; + printf("To create a new user, enter the information required below.\n"); + printf("Enter forename (max. 15 letters):\n"); + while(letterCounter=letterMaximum){ + inputTooLong = true; + break; + } + } + if(inputTooLong){ + errorResult = errorMessage(-7); + if(errorResult==-7) exit(-1); + } + else{ + *(instance.forename+letterCounter) = '\0'; + letterCounter = 0; + } + if(!isLetterOfAlphabet(instance.forename)){ + errorResult = errorMessage(-10); + exit(-1); + } + printf("Enter surname (max. 15 letters):\n"); + while(letterCounter=letterMaximum){ + inputTooLong = true; + break; + } + } + if(inputTooLong){ + errorResult = errorMessage(-8); + if(errorResult==-8) exit(-1); + }else{ + *(instance.surname+letterCounter) = '\0'; + letterCounter = 0; + } + if(!isLetterOfAlphabet(instance.surname)){ + errorResult = errorMessage(-11); + if(errorResult==-11) exit(-1); + } + printf("Enter password (max. 20 letters):\n"); + letterMaximum = 20; + while(letterCounter=letterMaximum){ + inputTooLong = true; + break; + } + } + if(inputTooLong){ + errorResult=errorMessage(-9); + if(errorResult==-9) exit(-1); + }else{ + *(instance.password+letterCounter) = '\0'; + } + + letterCounter = 0; + printf("Enter balance (max. 10 digits):\n"); + char *balanceCharacters = calloc(10+1+1+1,sizeof(char)); + letterMaximum = 10; + while(letterCounter<=letterMaximum && (userInput=getchar())!='\n'){ + *(balanceCharacters+letterCounter) = userInput; + ++letterCounter; + if(letterCounter>letterMaximum){ + inputTooLong = true; + break; + } + } + if(inputTooLong){ + errorResult = errorMessage(-12); + if(errorResult==-12) exit(-1); + }else{ + if(!foundComma){ + *(balanceCharacters+letterCounter) = '.'; + ++letterCounter; + *(balanceCharacters+letterCounter) = '0'; + ++letterCounter; + } + *(balanceCharacters+letterCounter) = '\0'; + } + if(!everyCharacterIsDigit(balanceCharacters)){ + puts("You have entered a character that is not a number. This is not allowed. Aborting!"); + exit(-1); + } + instance.balance = balanceToDouble(balanceCharacters); + printf("Account successfully created. Your ID is: %d. Note it somewhere!\n",instance.ID); + customer_t *referenceToCustomerInstance = &instance; + writeCustomerPropertiesToFile(referenceToCustomerInstance); +} + +void writeCustomerPropertiesToFile(customer_t *referenceToCustomerInstance) +{ + FILE *customerData = fopen("CustomerData.txt","a"); + int errorResult = 0; + if(customerData!=NULL){ +fprintf(customerData,"%s\nID=%d\nForename=%s\nSurname=%s\nPassword=%s\nBalance=%.4f€\n\n", +generateCheckString(referenceToCustomerInstance->ID, referenceToCustomerInstance->password),referenceToCustomerInstance->ID,referenceToCustomerInstance->forename,referenceToCustomerInstance->surname,referenceToCustomerInstance->password, referenceToCustomerInstance->balance); + fclose(customerData); + } + else{ + errorResult = errorMessage(-6); + if(errorResult==-6) exit(-1); + } +} diff --git a/src/createCustomer.h b/src/createCustomer.h new file mode 100644 index 0000000..1b87870 --- /dev/null +++ b/src/createCustomer.h @@ -0,0 +1,13 @@ +#ifndef CREATE_CUSTOMER_H +#define CREATE_CUSTOMER_H +#include +#include +#include +#include +#include "customerProperties.h" +#include "helperFunctions.h" +#include "error.h" +int generateID(); +void collectCustomerProperties(); +void writeCustomerPropertiesToFile(customer_t *); +#endif diff --git a/src/createEmployeeAccount.c b/src/createEmployeeAccount.c new file mode 100644 index 0000000..db75883 --- /dev/null +++ b/src/createEmployeeAccount.c @@ -0,0 +1,234 @@ + +#include "createEmployeeAccount.h" +#include "employeeLogin.h" + + +bool isValidEmployeeID(const char* employeeId,const int maximumStringLength) +{ + int employeeIdLength = strlen(employeeId); + /* looping through the employeeId string until a space is found to return false or true otherwise*/ + for(int i=0;i= minimumLength && letterFound && numberFound && symbolFound) + { + return true; + } + ++stringpointer; + } + + return false; + +} + +bool isValidName(char* name,const int minimalLength) +{ + int nameLength = strlen(name); + if(nameLength < minimalLength) + { + return false; + } + + for(int i = 0;imaximalAdressLength || strlen(street)maximalAdressLength || strlen(city) 999) + { + validHouseNumber = false; + } + if(postalCode<1000 || postalCode > 99000) + { + validpostalCode = false; + } + return (validStreet && validCity && validHouseNumber && validpostalCode); +} + +int StringLengthCounter(char* string) +{ + int characterCounter = 0; + int i = 0; + while(string[i] !='\0') + { + characterCounter++; + ++i; + } + string[characterCounter] = '\0'; + return characterCounter; +} + +/*changed the string parameters to constants as an indicator that the function doesnt modify them*/ + +bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber) +{ + FILE* employeesDatalist; + employeesDatalist = fopen("src/employeesData.txt","a"); + if(employeesDatalist == NULL) + { + printf("Error : could not find file"); + fclose(employeesDatalist); + return false; + } + else + { + fprintf(employeesDatalist,"\n\nName : %s\nLast name : %s\nAdress : %s\nPhone number : %s",name,lastName,adress,phoneNumber); + fclose(employeesDatalist); + return true; + } +} + +bool verifyPassword(char* enteredPassword,char* Confirmation) +{ + return !(strcmp(enteredPassword,Confirmation)); +} + + +bool createNewEmployee(char* employeeId, char* employeePassword) +{ + FILE* employeesFile; + employeesFile = fopen("src/employeesCredentialsList.txt","a"); + + if(employeesFile == NULL) + { + printf("Error: could not find the list of Employees"); + fclose(employeesFile); + return false; + } + + fprintf(employeesFile,"\n%s %s\n",employeeId,employeePassword); + fclose(employeesFile); + + return true; +} + + +void getNewEmployeeCredentials() +{ + employeedata *data = (employeedata*)malloc(sizeof(employeedata)); + char employeeId[maxLength]; + char employeePassword[maxLength]; + char passwordVerfication[maxLength]; + char street[maximalAdressLength]; + char city[maximalAdressLength]; + int houseNumber; + char houseNumberString[10]; + int postalCode; + char postalCodeString[10]; + + printf("please enter your wished Id :\n"); + /*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/ + scanf(" %[^\n]s",employeeId); + employeeId[maxLength] = '\0'; + + printf("\nplease enter your wished Password :\n"); + scanf(" %[^\n]s",employeePassword); + employeePassword[strlen(employeePassword)] = '\0'; + + printf("\nplease confirm your Password :\n"); + scanf(" %[^\n]s",passwordVerfication); + passwordVerfication[strlen(employeePassword)] = '\0'; + + if(verifyPassword(passwordVerfication,employeePassword) && isValidPassword(employeePassword,minPasswordLength) && isValidEmployeeID(employeeId,maxLength)) + { + printf("\n\nplease enter your first name\n"); + scanf(" %[^\n]s",data->firstName); + + printf("\n\nplease enter your last name\n"); + scanf(" %[^\n]s",data->lastName); + + if(isValidName(data->firstName,minimumNameLength) && isValidName(data->lastName,minimumNameLength)) + { + printf("\n\nplease enter your adress\n"); + scanf(" %[^\n]s",data->address); + + printf("\n\nplease enter your Phone number\n"); + scanf(" %[^\n]s",data->phoneNumber); + if(isValidPhoneNumber(data->phoneNumber)) + { + createNewEmployee(employeeId,employeePassword) ? + printf("\n\n Account created successfully !\n\n") : + printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n"); + storeEmployeeData(data->firstName,data->lastName,data->address,data->phoneNumber); + } + else + { + printf("\nInvalid phone number!\n"); + } + } + else + { + printf("the given name contains unwanted characters(spaces, symbols,numbers)"); + } + + } + else + { + printf("\nError! one of these conditions is not met in your input.\n"); + printf("\n-The entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol.\n"); + printf("\n-The entered ID should contain a maximum of 20 letters.\n"); + printf("\n-The verification password should match with the entered password.\n"); + } +} + diff --git a/src/createEmployeeAccount.h b/src/createEmployeeAccount.h new file mode 100644 index 0000000..e9321f4 --- /dev/null +++ b/src/createEmployeeAccount.h @@ -0,0 +1,39 @@ +#ifndef CREATEEMPLOYEEACCOUNT_H_ +#define CREATEEMPLOYEEACCOUNT_H_ + +#include +#include +#include +#include +#include + +#define minPasswordLength 5 +#define minimumNameLength 4 +#define maxLength 21 +#define validNumberLength 14 +#define maximalAdressLength 20 +#define minimalAdressLength 3 + +struct employeesInformations +{ + char firstName[15]; + char lastName[15]; + char address[100]; + char phoneNumber[15]; +}; +typedef struct employeesInformations employeedata; + +bool isValidEmployeeID(const char* employee, int maximumLength); +bool isValidPassword( char* password, int minimumLength); +bool isValidName(char* name,int minimalLength); +bool isValidPhoneNumber(char *phoneNumber); +bool isValidAdress(char *street,char* city,int houseNumber,int postalCode); +bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber); +bool verifyPassword(char* enteredPassword,char* passwordConfirmation); +bool createNewEmployee(char* employeeId, char* employeePassword); + +int StringLengthCounter(char* string); + +void getNewEmployeeCredentials(); + +#endif \ No newline at end of file diff --git a/src/currencyExchange.c b/src/currencyExchange.c new file mode 100644 index 0000000..83bf372 --- /dev/null +++ b/src/currencyExchange.c @@ -0,0 +1,20 @@ +#include "currencyExchange.h" + +float convert(float euro, int newCurrencyCode) { + switch(newCurrencyCode) { + case CURRENCY_CODE_USD: + return ( euro * USD_RATE_OF_ONE_EURO ); + + case CURRENCY_CODE_GBP: + return ( euro * GBP_RATE_OF_ONE_EURO ); + + case CURRENCY_CODE_JAPANESE_YEN: + return ( euro * JAPANESE_YEN_RATE_OF_ONE_EURO ); + + case CURRENCY_CODE_CHINESE_YUAN: + return ( euro * CHINESE_YUAN_RATE_OF_ONE_EURO ); + + } + + return -1; +} \ No newline at end of file diff --git a/src/currencyExchange.h b/src/currencyExchange.h new file mode 100644 index 0000000..49208aa --- /dev/null +++ b/src/currencyExchange.h @@ -0,0 +1,18 @@ +#ifndef CURRENCYEXCHANGE_H_ +#define CURRENCYEXCHANGE_H_ + +#include + +#define USD_RATE_OF_ONE_EURO 1.07 +#define GBP_RATE_OF_ONE_EURO 0.89 +#define JAPANESE_YEN_RATE_OF_ONE_EURO 140.9 +#define CHINESE_YUAN_RATE_OF_ONE_EURO 7.29 + +#define CURRENCY_CODE_USD 1 +#define CURRENCY_CODE_GBP 2 +#define CURRENCY_CODE_JAPANESE_YEN 3 +#define CURRENCY_CODE_CHINESE_YUAN 4 + +float convert(float euro, int newCurrencyCode); + +#endif \ No newline at end of file diff --git a/src/currentCustomerAccountBalance.c b/src/currentCustomerAccountBalance.c new file mode 100644 index 0000000..e7335a0 --- /dev/null +++ b/src/currentCustomerAccountBalance.c @@ -0,0 +1,65 @@ +#include "currentCustomerAccountBalance.h" +//#include "_file_information.h" + + +float fetchBalanceFromBalanceString(char balance_String[MAX_LENGTH]) { + float balance = 0; + char *token = strtok(balance_String, "="); // separates string to two parts + while (token != NULL) { + if (atoi(token) != 0) { + balance = atof(token); // converts string to float + break; + } + token = strtok(NULL, "="); + } + return balance; +} + +float readFileAndGetAvailableBalance(FILE *file, char stringID[MAX_LENGTH]) { + float balance = 0; + bool keep_reading = true; + char buffer[MAX_LENGTH]; + char balance_String[MAX_LENGTH]; + + while(keep_reading) { + fgets(buffer, MAX_LENGTH, file); + if (feof(file)) { + keep_reading = false; + } + else if(strstr(buffer, stringID)) { + for (int i = 0; i < 4; i++) { + fgets(buffer, MAX_LENGTH, file); + } + strcpy(balance_String, buffer); + balance = fetchBalanceFromBalanceString(balance_String); + keep_reading = false; + } + + } + return balance; +} + +float getAvailableAccountBalance(int user_id) { + float availableBalance = 0; + char stringID[MAX_LENGTH] = "ID="; + char user_id_as_string[MAX_LENGTH]; + + sprintf(user_id_as_string, "%d", user_id); // converts user_id to string + strcat(stringID, user_id_as_string); + // Now stringID is "ID=user_id" + + FILE *file = fopen(CUSTOMER_DATA_FILE, "r"); + if(file == 0) { + printf("Error: customer data file cannot be opened!\n"); + return 0; + } + else { + availableBalance = readFileAndGetAvailableBalance(file, stringID); + } + + + fclose(file); + + return availableBalance; + +} \ No newline at end of file diff --git a/src/currentCustomerAccountBalance.h b/src/currentCustomerAccountBalance.h new file mode 100644 index 0000000..36bb66e --- /dev/null +++ b/src/currentCustomerAccountBalance.h @@ -0,0 +1,16 @@ +#ifndef CurrentCustomerAccountBalance_H +#define CurrentCustomerAccountBalance_H + + +#include +#include +#include +#include + +#include "_file_information.h" + +float getAvailableAccountBalance(int user_id); +float fetchBalanceFromBalanceString(char balance_String[MAX_LENGTH]); +float readFileAndGetAvailableBalance(FILE *file, char stringID[MAX_LENGTH]); + +#endif \ No newline at end of file diff --git a/src/customerMenu.c b/src/customerMenu.c new file mode 100644 index 0000000..c75e666 --- /dev/null +++ b/src/customerMenu.c @@ -0,0 +1,78 @@ +#include "customerMenu.h" +#include "sendMoney.h" +#include "withdrawMoney.h" +#include "depositMoney.h" + + +int customerChoiceForMenuItem(int numberOfMenuItem, unsigned int *ptr) +{ + int returnStatus = 0; + int ID = *ptr; + switch(numberOfMenuItem){ + case 1: + puts("You have chosen to send money.\n"); + returnStatus = 1; + sendMoney(ID); + break; + case 2: + puts("You have chosen to withdraw money.\n"); + returnStatus = 2; + withdraw(ID); + break; + case 3: + puts("You have chosen to deposit money.\n"); + returnStatus = 3; + depositMoney(ID); + break; + case 4: + puts("You have chosen to request a loan.\n"); + returnStatus = 4; + requestLoan(); + break; + default: + puts("Invalid input."); + returnStatus = -1; + } + return returnStatus; +} + +void showAllMenuEntries(unsigned int *ptr) +{ + + int userDecision = 0; + + puts("\n\n"); + puts("CUSTOMER MENU"); + + puts("\n"); + puts("Select between (1-4):"); + puts("\n\n\n"); + + puts("->->->1. send money<-<-<-"); + puts("\n\n\n"); + + puts("->->->2. withdraw money<-<-<-"); + puts("\n\n\n"); + + puts("->->->3. deposit money<-<-<-"); + puts("\n\n\n"); + + puts("->->->4. request loan<-<-<-"); + puts("\n\n\n"); + + puts("Your decision: "); + scanf("%d",&userDecision); + customerChoiceForMenuItem(userDecision, ptr); +} + +void menu(unsigned int *ptr) +{ + if(ptr==NULL){ + puts("Invalid pointer. Aborting!"); + exit(-1); + }else{ + puts("Welcome!"); + printf("Your ID is: %u\n", *ptr); + showAllMenuEntries(ptr); + } +} diff --git a/src/customerMenu.h b/src/customerMenu.h new file mode 100644 index 0000000..9590d9f --- /dev/null +++ b/src/customerMenu.h @@ -0,0 +1,7 @@ +#include +#include +#include "customerProperties.h" +#include "requestLoan.h" +int customerChoiceForMenuItem(int, unsigned int *pointer); +void showAllMenuEntries(unsigned int *pointer); +void menu(unsigned int *pointer); \ No newline at end of file diff --git a/src/customerProperties.h b/src/customerProperties.h new file mode 100644 index 0000000..39661d1 --- /dev/null +++ b/src/customerProperties.h @@ -0,0 +1,11 @@ +#ifndef CUSTOMER_PROPERTIES_H +#define CUSTOMER_PROPERTIES_H +typedef struct Customer +{ + unsigned int ID; + char *IDAsString; + char *password; + char *forename, *surname; + double balance; +}customer_t; +#endif diff --git a/src/depositMoney.c b/src/depositMoney.c new file mode 100644 index 0000000..21587c2 --- /dev/null +++ b/src/depositMoney.c @@ -0,0 +1,71 @@ +#include "depositMoney.h" +#include "updateCustomerAccountBalance.h" +#include "currentCustomerAccountBalance.h" + +void askToTryAgain(bool afterError, int customerID){ + printf("\n"); + char choice; + printf("%s [y] yes [n] no: ", afterError ? "Would you like to try again?" : "Would you like to make another deposit?"); + scanf(" %c", &choice); + if (choice == 'y') { + depositMoney(customerID); + } + + +} + +bool depositMoney(int customerID){ + float availableAccountBalance = getAvailableAccountBalance(customerID); + if (availableAccountBalance < 0) { + printf("\nCould not retrieve account balance. Please contact staff.\n"); + return false; + } + + printf("\nPlease enter the amount you want to deposit: "); + float amountToDeposit = 0; + scanf("%f", &amountToDeposit); + + if (amountToDeposit < 0) { + printf("\nInvalid input."); + askToTryAgain(true, customerID); + return false; + } + else if (amountToDeposit < MINIMUM_DEPOSIT_AMOUNT) { + printf("\nThe amount you entered is lower than the minimum amount."); + askToTryAgain(true, customerID); + return false; + } + + if (updateAvailableAccountBalance(customerID, availableAccountBalance + amountToDeposit)) { + printf("\nYou have successfully deposited %.2f. New account balance is %.2f", amountToDeposit, availableAccountBalance + amountToDeposit); + askToTryAgain(false, customerID); + return true; + } + else { + printf("\nSomething went wrong. Please contact staff."); + return false; + } +} + + +bool depositSpecificAmount(int customerID, float amount){ + + float availableAccountBalance=getAvailableAccountBalance(customerID); + + if(amount>0){ + if(updateAvailableAccountBalance(customerID, availableAccountBalance+amount)){ + return true; + }else{ + return false; + } + } + return false; +} + +/* +int main(){ + depositSpecificAmount(1234,5000); + //depositMoney(1234); + return 0; +} +*/ diff --git a/src/depositMoney.h b/src/depositMoney.h new file mode 100644 index 0000000..c06d44f --- /dev/null +++ b/src/depositMoney.h @@ -0,0 +1,9 @@ +#include +#include "customerProperties.h" +#include +#define MINIMUM_DEPOSIT_AMOUNT 5 + + +bool depositMoney(int customerID); +void askToTryAgain(bool afterError, int customerID); +bool depositSpecificAmount(int customerID, float amount); \ No newline at end of file diff --git a/src/displayDisclaimer.c b/src/displayDisclaimer.c new file mode 100644 index 0000000..a324e93 --- /dev/null +++ b/src/displayDisclaimer.c @@ -0,0 +1,20 @@ +#include "displayDisclaimer.h" + +void displayDisclaimer(){ + printf(" W E L C O M E T O \n"); + printf(" .______ .___ ___. _______.\n"); + printf(" | _ \\ | \\/ | / |\n"); + printf(" | |_) | | \\ / | | (----`\n"); + printf(" | _ < | |\\/| | \\ \\ \n"); + printf(" | |_) | | | | | .----) | \n"); + printf(" |______/ |__| |__| |_______/ \n"); + printf(" \n"); + printf("B A N K M A N A G E M E N T S Y S T E M\n"); + printf(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:\n"); + printf("Created by Atharva, Can, Haytham, Julius, Shivam, and Yahya for AI1001.\n"); +} + +// int main(){ +// displayDisclaimer(); +// return 1; +// } \ No newline at end of file diff --git a/src/displayDisclaimer.h b/src/displayDisclaimer.h new file mode 100644 index 0000000..7043974 --- /dev/null +++ b/src/displayDisclaimer.h @@ -0,0 +1,7 @@ +#ifndef DISPLAYDISCLAIMER_H_ +#define DISPLAYDISCLAIMER_H_ +#include + +void displayDisclaimer(); + +#endif \ No newline at end of file diff --git a/src/displayMenuCalculator.c b/src/displayMenuCalculator.c new file mode 100644 index 0000000..d797a69 --- /dev/null +++ b/src/displayMenuCalculator.c @@ -0,0 +1,88 @@ +#include "displayMenuCalculator.h" +#include "calculatorGetUserInput.h" +#include "calculatorGetUserInputFactorial.h" +#include "calculatorAdd.h" +#include "calculatorSubtract.h" +#include "calculatorMultiply.h" +#include "calculatorDivide.h" +#include "calculatorFactorial.h" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + +int operation1 = 1; +int operation2 = 2; +int operation3 = 3; +int operation4 = 4; +int operation5 = 5; + +int check() +{ + const int rConst = 1; // RandomConstant created for indirectly testing void displayMenuCalculator() + if(rConst == 1)// RandomConstant created for indirectly testing void displayMenuCalculator() + { + return 1; + } +} + +void displayMenuCalculator(char x) //Displays the correct output, only when x is c. +{ + float num1, num2, answer; //Created for storing numbers for addition, subtraction, multiplication and division and the final answer. + int num; //Created specially for calculatorFactorial() + int choose; + + if(x == 'c') //calculator can be activated by adding 'c' in void displayMenuCalculator() + { + if(check() == 1) + { //The Main Menu of the calculator + printf(" %d. Add\n", operation1); + printf(" %d. Subtract\n", operation2); + printf(" %d. Multiply\n", operation3); + printf(" %d. Divide\n", operation4); + printf(" %d. Factorial\n", operation5); + + printf("Enter your choice: "); // Takes the choice of operations from the user + scanf("%d", &choose); // Saves the choice + + switch (choose) + { //takes user's choice and calls operation-functions accordingly + case 1: + calculatorGetUserInput(&num1, &num2); + answer = calculatorAdd(num1, num2); + printf("Answer: %f\n", answer); + break; + + case 2: + calculatorGetUserInput(&num1, &num2); + answer = calculatorSubtract(num1, num2); + printf("Answer: %f\n", answer); + break; + + case 3: + calculatorGetUserInput(&num1, &num2); + answer = calculatorMultiply(num1, num2); + printf("Answer: %f\n", answer); + break; + + case 4: + calculatorGetUserInput(&num1, &num2); + answer = calculatorDivide(num1, num2); + printf("Answer: %f\n", answer); + break; + + case 5: + calculatorGetUserInputFactorial(&num); //Created specially for factorial which gets a number from user. + answer = calculatorFactorial(num); + printf("Answer: %f\n", answer); + break; + + default: + printf("Invalid choice\n"); + return; + } + } + } +} + + + diff --git a/src/displayMenuCalculator.h b/src/displayMenuCalculator.h new file mode 100644 index 0000000..a2ad61d --- /dev/null +++ b/src/displayMenuCalculator.h @@ -0,0 +1,4 @@ +#include +#include +int check(); //int check() is helpful for indirectly testing void displayMenuCalculator() +void displayMenuCalculator(char x); //Displays the correct output, only when x is c. \ No newline at end of file diff --git a/src/docs.txt b/src/docs.txt new file mode 100644 index 0000000..c76de12 --- /dev/null +++ b/src/docs.txt @@ -0,0 +1,14 @@ +char *stringConcatenation(char string_1*, char string_2*): + +This function takes two char pointers. In this function a new string is created. This new string is the concatenation of string_1 and string_2. The size of the new string is the length of string_1 plus the length of string_2 plus one for '\0'. This function is needed when creating an unique check string for a customer. + +char *to_string(int number): + +This function takes an integer variable as its argument. It returns an string that contains the digits of number. For example to_string(176) would return "176\0". This function is needed to write data in form of characters into the customer file. + + +char *generateCheckString(int customerID, char *password): + +The purpose of this function is to generate a string that is needed when a user wants to login. This string is searched for in the customer-data file and if it is found, the login is successful. This function is needed when a new user is created because then it is written in the file for the first time. +The format of the returned string is [ID]=[PASSWORD]. +For example generateCheckString(177,"tree") would return "177=tree\0". diff --git a/src/employeeLogin.c b/src/employeeLogin.c new file mode 100644 index 0000000..3d70358 --- /dev/null +++ b/src/employeeLogin.c @@ -0,0 +1,139 @@ +#include "mainMenu.h" +#include "employeeLogin.h" +#include "showGeneralInfoEmployee.h" + + +bool employeesAccess(char* employeesAccessCode) +{ + + return !(strcmp(employeesAccessCode,employeeAccessKey)); + +} + +int checkEmployeeCredentials(char *inputUsername, char *inputPassword) +{ + + char* listUsername = malloc(credentialLength * sizeof(char*)); + char* listPassword = malloc(credentialLength * sizeof(char*)); + + FILE* employeeList = fopen("src/employeesCredentialsList.txt","r"); + + if(employeeList == NULL ) + { + printf("file does not exist"); + exit(1); + } + else + { + /*loop that checks if the two strings seperated by space exist in the employee list*/ + + while (fscanf(employeeList, "%s %s", listUsername, listPassword) != EOF) + { + + if (!(strcmp(inputUsername, listUsername)) && !(strcmp(inputPassword, listPassword))) + { + fclose(employeeList); + return 1; + } + else if(!(strcmp(inputUsername, listUsername)) && strcmp(inputPassword, listPassword)) + { + fclose(employeeList); + return 2; + } + } + fclose(employeeList); + return 0; + } + + free(inputUsername); + free(inputPassword); +} + +void getEmployeeAccessCode() +{ + char accessCode[10]; + + int remainingAttempts = 10; + + printf("\n\nPlease enter the Access key : "); + + while(remainingAttempts > 0) + { + scanf("%s",accessCode); + + + if(employeesAccess(accessCode)) + { + printf("\n\nAccess granted!\n\n"); + + loginAsEmployee(); + break; + + } + + else if(!(employeesAccess(accessCode))) + { + printf("\n\nAccess key didnt match! try again !\n\n"); + --remainingAttempts; + } + + if(remainingAttempts == 0) + { + printf("you've reached the maximum number of tries!\nplease contact an employee of a high clearance(2 or higher) \n\n"); + } + } + +} + +void getEmployeeCredentials(char* inputUsername,char* inputPassword) +{ + printf("Enter username: "); + scanf("%s", inputUsername); + + printf("Enter password: "); + scanf("%s", inputPassword); +} + +void loginAsEmployee() +{ + int counter=3; + char* username = malloc(credentialLength * sizeof(char*)); + char* password = malloc(credentialLength * sizeof(char*)); + + while(counter>0) + { + getEmployeeCredentials(username, password); + + int checkCredentials = checkEmployeeCredentials(username,password); + + + if(checkCredentials == 0) + { + printf("\n\nUser not found\n\n"); + } + else if(checkCredentials == 2) + { + printf("\n\nWrong Informations !\nyou have %d tries left\n\n",counter-1); + --counter; + } + else + { + printf("\n\nUser Approved\n\n"); + showGeneralInfoEmployee(username, password); + break; + } + } + + if(counter==0) + { + + printf("you used up all of the tries! account locked\nPlease contact an employee of higher clearance !\n\n"); + + } + + free(username); + free(password); + +} + + diff --git a/src/employeeLogin.h b/src/employeeLogin.h new file mode 100644 index 0000000..ca918a7 --- /dev/null +++ b/src/employeeLogin.h @@ -0,0 +1,19 @@ +#ifndef EMPLOYEELOGIN_H_ +#define EMPLOYEELOGIN_H_ + +#define employeeAccessKey "DF9E9A8B5E" +#define credentialLength 20 + +#include + +bool employeesAccess(char* employeesAccessCode); +int checkEmployeeCredentials(char* username , char* password); + +void getEmployeeAccessCode(); +void getEmployeeCredentials(char* username, char* password); +void loginAsEmployee(); + + +#endif + + diff --git a/src/employeesCredentialsList.txt b/src/employeesCredentialsList.txt new file mode 100644 index 0000000..839287a --- /dev/null +++ b/src/employeesCredentialsList.txt @@ -0,0 +1,20 @@ +Atharva Atharvafdai7514 + +Can BlooMaskfdlt3817 + +Haytham TimoDLfdai7207 + +Julius Insertcatfdai7057 + +Mohamed MDfdai6618 + +Shivam Schivam007fdlt3781 + + + + + + + + + diff --git a/src/employeesData.txt b/src/employeesData.txt new file mode 100644 index 0000000..ac19002 --- /dev/null +++ b/src/employeesData.txt @@ -0,0 +1,52 @@ +Name : Atharva +Last name : Naik +Adress : Fulda,leipzigerstrasse,1 +Phone number : +4964169865172 + + +Name : Can +Last name : Hacioglu +Adress : Fulda,leipzigerstrasse,2 +Phone number : +4915973325487 + + +Name : Haytham +Last name : Daoula +Adress : Fulda,leipzigerstrasse,3 +Phone number : +4995435870169 + + +Name : Julius +Last name : Engel +Adress : Fulda,leipzigerstrasse,4 +Phone number : +4939172972187 + + +Name : Mohamed +Last name : Dahi +Adress : Fulda,leipzigerstrasse,5 +Phone number : +4921865106647 + + +Name : Shivam +Last name : Chaudhary +Adress : Fulda,leipzigerstrasse,6 +Phone number : +4918756871384 + + + + + + + + + + + + + + + + + + diff --git a/src/error.c b/src/error.c new file mode 100644 index 0000000..f9b6251 --- /dev/null +++ b/src/error.c @@ -0,0 +1,59 @@ +#include "error.h" + +int errorMessage(int errorCode) +{ + int returnValue=0; + switch(errorCode){ + case -1: + // puts("Login not successful."); + returnValue = -1; + break; + case -2: + // puts("Maximum number of attempts reached."); + returnValue = -2; + break; + case -3: + // puts("No menu entry available for this number."); + returnValue = -3; + break; + case -4: + // puts("CustomerData.* not found. Make sure that you've created an user account before logging in for the first time. Without users there is no file. Aborting!"); + returnValue = -4; + break; + case -5: + // puts("You should be at least 18 years old to create a bank account!"); + returnValue = -5; + break; + case -6: + // puts("Error when trying to open a file to create a customer account."); + returnValue = -6; + break; + case -7: + // puts("Forename too long. (length > 15 characters) Aborting!"); + returnValue = -7; + break; + case -8: + // puts("Surname too long. (length > 15 characters) Aborting!"); + returnValue = -8; + break; + case -9: + // puts("Password too long. (length > 20 characters) Aboring!"); + returnValue = -9; + break; + case -10: + // puts("You have entered an invalid character [ä,ö,ü, special characters] for your forename. This is not allowed. Aborting!"); + returnValue = -10; + break; + case -11: + // puts("You have entered an invalid character [ä,ö,ü, special characters] for your surname. This is not allowed. Aborting!"); + returnValue = -11; + break; + case -12: + // puts("You entered too many digits."); + returnValue = -12; + break; + default: + return returnValue; + } + return returnValue; +} diff --git a/src/error.h b/src/error.h new file mode 100644 index 0000000..867964a --- /dev/null +++ b/src/error.h @@ -0,0 +1,3 @@ +#include +#include +int errorMessage(int); diff --git a/src/helperFunctions.c b/src/helperFunctions.c new file mode 100644 index 0000000..2f61921 --- /dev/null +++ b/src/helperFunctions.c @@ -0,0 +1,151 @@ +#include "helperFunctions.h" +/*Code written by Julius Philipp Engel, fdai7057*/ + +char *stringConcatenation(char *string_1, char *string_2) +{ + int lengthStringOne = strlen(string_1); + int lengthStringTwo = strlen(string_2); + + if(lengthStringOne==0||lengthStringTwo==0){ + printf("Empty strings are not allowed. Aborting.\n"); + exit(-1); + //call error(); + } + + const int totalLength = lengthStringOne + lengthStringTwo + 1; + char *result = calloc(totalLength, sizeof(char)); + int i,j; + for(i=0,j=0;i0){ + ++len; + number /= 10; + } + char *str = calloc(len+1, sizeof(char)); + for(int i=0,j=len-1;i=1&&exponent==0) return 1; + else{ + unsigned int result = 1, counter = 0; + while(counter='0'&&*(string+i)<='9') && *(string+i)!='.'){ + onlyDigits = false; + break; + } + } + return onlyDigits; +} + +bool isLetterOfAlphabet(char *string){ + bool everyCharIsInAlphabet = true; + for(int i=0;*(string+i)!='\0';++i){ + if(!(*(string+i)>='A'&&*(string+i)<='Z') && !(*(string+i)>='a'&&*(string+i)<='z')){ + everyCharIsInAlphabet = false; + break; + } + } + return everyCharIsInAlphabet; +} + +unsigned int toUnsignedInteger(char *ID) +{ + if(everyCharacterIsDigit(ID)){ + unsigned int result = 0; + int IDLength = strlen(ID); + for(int i=0, j = IDLength - 1;i + +void calculateYearlyInterest(); +void calculateMonthlyInterest(); +void askForSavingGoal(float principalAmount, float accInterestPerYear); +float initiateInterest(float principalAmount, float interest, float time); +void troubleshoot(int errorCode); +#endif \ No newline at end of file diff --git a/src/lineReplacer.h b/src/lineReplacer.h new file mode 100644 index 0000000..c3ee57b --- /dev/null +++ b/src/lineReplacer.h @@ -0,0 +1,11 @@ +#ifndef LINEREPLACER_H_ +#define LINEREPLACER_H_ + +#include +#include +#include +#include + +void replaceLineInFile(const char* file_name, int line, const char* new_line); //replaces the line at "line" on the file "file_name", with the new line "new_line". + +#endif \ No newline at end of file diff --git a/src/loginCustomer.c b/src/loginCustomer.c new file mode 100644 index 0000000..bc84e19 --- /dev/null +++ b/src/loginCustomer.c @@ -0,0 +1,88 @@ +#include "loginCustomer.h" + +bool checkLogin(bool loginSuccessful) +{ + return (loginSuccessful) ? true : false; +} + +void collectCustomerDataForLogin(int attempts) +{ + customer_t c; + c.IDAsString = calloc(15+1, sizeof(char)); + c.password = calloc(20+1, sizeof(char)); + int digitCharacterFromUser, passwordCharacterFromUser; + int IDLengthCounter = 0, passwordLengthCounter = 0; + int errorResult = 0; + const int IDMaxLength = 16, passwordMaxLength = 21; + printf("Enter ID:\n"); + while((digitCharacterFromUser=getchar())!='\n'&&IDLengthCounter='0'&&digitCharacterFromUser<='9'){ + *(c.IDAsString+IDLengthCounter) = digitCharacterFromUser; + } + else{ + printf("Character entered is not a digit. Aborting.\n"); + exit(-1); + } + ++IDLengthCounter; + } + *(c.IDAsString+IDLengthCounter) = '\0'; + if(IDLengthCounter>=IDMaxLength){ + printf("ID entered is too long. Aborting.\n"); + exit(-1); + } + printf("Enter password:\n"); + while((passwordCharacterFromUser=getchar())!='\n'&&passwordLengthCounter=passwordMaxLength){ + printf("Password entered is too long. Aborting.\n"); + exit(-1); + } + bool loginSuccessful = loginCustomer(&c); + unsigned int value = toUnsignedInteger(c.IDAsString); + free(c.IDAsString); + free(c.password); + if(loginSuccessful) { + int *ptr = &value; + menu(ptr); + }else if(!loginSuccessful && attempts < MAX_LOGIN_ATTEMPTS){ + printf("You have %d attempts left.\n", MAX_LOGIN_ATTEMPTS - attempts); + collectCustomerDataForLogin(++attempts); + }else{ + errorResult = errorMessage(-2); + if(errorResult==-2) exit(-1); + } +} + +bool loginCustomer(customer_t *c) +{ + bool foundCustomerEntryInFile = false; + unsigned int IDAsNumber = toUnsignedInteger(c->IDAsString); + char *searchForThisString = generateCheckString(IDAsNumber,c->password); + char *lineFromCustomerFile = calloc(40,sizeof(char)); + int errorResult = 0; + FILE *readCustomerFile = fopen("CustomerData.txt", "r"); + if(readCustomerFile==NULL){ + errorResult = errorMessage(-4); + if(errorResult==-4) exit(-1); + } + while((fscanf(readCustomerFile,"%s",lineFromCustomerFile)!=EOF)){ + if(strcmp(searchForThisString,lineFromCustomerFile)==0){ + foundCustomerEntryInFile = true; + break; + } + } + free(lineFromCustomerFile); + if(checkLogin(foundCustomerEntryInFile)){ + printf("Login successful.\n"); + fclose(readCustomerFile); + return foundCustomerEntryInFile; + }else{ + errorResult = errorMessage(-1); + } + fclose(readCustomerFile); + return foundCustomerEntryInFile; +} diff --git a/src/loginCustomer.h b/src/loginCustomer.h new file mode 100644 index 0000000..b9d2b17 --- /dev/null +++ b/src/loginCustomer.h @@ -0,0 +1,15 @@ +#ifndef LOGIN_CUSTOMER_H +#define LOGIN_CUSTOMER_H +#include +#include +#include +#include +#include "createCustomer.h" +#include "customerMenu.h" +#include "error.h" +#include "customerProperties.h" +#define MAX_LOGIN_ATTEMPTS 3 +bool checkLogin(bool); +void collectCustomerDataForLogin(int); +bool loginCustomer(customer_t *); +#endif diff --git a/src/main.c b/src/main.c index a3a8e04..f13161e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,13 @@ -#include -int main(){ -return 0; +#include "mainMenu.h" +#include "employeeLogin.h" +#include"showGeneralInfoEmployee.h" + +void runBankManagementSystem() +{ + ageInput(); } + +int main() +{ + runBankManagementSystem(); +} \ No newline at end of file diff --git a/src/mainMenu.c b/src/mainMenu.c new file mode 100644 index 0000000..d3cee12 --- /dev/null +++ b/src/mainMenu.c @@ -0,0 +1,152 @@ +#include "mainMenu.h" +#include "employeeLogin.h" +#include "createEmployeeAccount.h" +#include "createCustomer.h" +#include "error.h" +#include "displayMenuCalculator.h" + + + +bool agePermission(int age) +{ + + return age >= 18; + +} + +bool checkIfInteger(char* userInput) +{ + + char *endPointer; + + /*the endPointer points to the first non-integer character signaled to stop conversion*/ + + strtol(userInput, &endPointer, 10); + + return !(endPointer == userInput || *endPointer != '\0'); + +} + +bool chooseOption(int choiceInput) +{ + + return !(choiceInput < 1 || choiceInput > 6); + +} + +void ageInput() +{ + + char* userInput = malloc(20*sizeof(char*)); + char* userInputPointer; + int input, ctr=0; + long age; + printf("\nPlease specify your age : "); + while((input=getchar())!='\n'){ + *(userInput+ctr) = input; + ++ctr; + } + *(userInput+ctr) = '\0'; + while (true) + { + /*the userInput string is changed to a number with the strtol function*/ + + age = strtol(userInput,&userInputPointer,10); + + if((checkIfInteger(userInput))&& (agePermission(age))) + { + + printf("Access granted!\n\n\n\n"); + + showMenu(); + + menuInput(); + + break; + + } + + else if((checkIfInteger(userInput)) && !(agePermission(age))) + { + errorMessage(-5); + break; + + } + + else + { + printf("input invalid! try again!\n"); + + scanf("%s",userInput); + + } + + + } +} + +void menuInput() +{ + char choiceInput[20]; + char* choiceInputPointer; + int selection, input, ctr = 0; + + while((input=getchar())!='\n'){ + choiceInput[ctr] = input; + ++ctr; + } + choiceInput[ctr] = '\0'; + + selection = strtol(choiceInput, &choiceInputPointer, 10); + + while (!checkIfInteger(choiceInput) || !chooseOption(selection)) + { + printf("Input invalid! try again!\n"); + ctr = 0; + while((input=getchar())!='\n'){ + choiceInput[ctr] = input; + ++ctr; + } + choiceInput[ctr] = '\0'; + selection = strtol(choiceInput, &choiceInputPointer, 10); + } + switch(selection) + { + case 1 : collectCustomerDataForLogin(0); + break; + + case 2 : collectCustomerProperties(); + break; + + case 3 : getEmployeeAccessCode(); + break; + + case 4 : getNewEmployeeCredentials(); + break; + + case 5 : displayMenuCalculator('c'); + break; + + case 6 : printf("\e[1;1H\e[2J"); + printf("\nsee you next time !\n\n"); + break; + } +} + + +void showMenu() +{ + + printf("\t\t\t\t\t\t\t Welcome to Bank Manager!"); + printf("\n\n\n\n\t\t\t\t\t\tPlease select one of the following functions!"); + printf("\n\n\n\n\t\t\t\t\t\t ->Login as an existing costumer."); + printf("\n\n\t\t\t\t\t\t ->Register as a new costumer."); + printf("\n\n\t\t\t\t\t\t ->Login as an Employee."); + printf("\n\n\t\t\t\t\t\t ->Register as an Employee."); + printf("\n\n\t\t\t\t\t\t ->Calculator"); + printf("\n\n\t\t\t\t\t\t\t\t ->Exit.\n"); + printf("\n\n\n\n\n Selection :\n"); + +} + + diff --git a/src/mainMenu.h b/src/mainMenu.h new file mode 100644 index 0000000..1fd5011 --- /dev/null +++ b/src/mainMenu.h @@ -0,0 +1,22 @@ +#ifndef MAINMENU_H_ +#define MAINMENU_H_ + +#include +#include +#include +#include +#include "loginCustomer.h" + +#define credentialLength 20 + +bool agePermission(int age); +bool checkIfInteger(char* userInput); +bool chooseOption(int choiceInput); + +void ageInput(); +void menuInput(); +void showMenu(); +void menuInput(); + +#endif + diff --git a/src/requestLoan.c b/src/requestLoan.c new file mode 100644 index 0000000..1398db6 --- /dev/null +++ b/src/requestLoan.c @@ -0,0 +1,29 @@ +#include "requestLoan.h" +const int a = 1; +int option1 = 1000; +int option2 = 2500; +int option3 = 5000; +char currency[] = "Euro"; +int allow() //int allow() is helpful for indirectly testing void requestLoan() +{ + if (a == 1) + { + return 1; + } +} + + +void requestLoan() +{ + if (allow() == 1) //only if int allow() returns 1, void requestLoan() will display the desired output + { + printf(" Please select a loan Package: \n"); + printf(" \n"); + printf(" \n"); + printf(" %d %s\n", option1, currency); + printf(" %d %s\n", option2, currency); + printf(" %d %s\n", option3, currency); + } +} + + diff --git a/src/requestLoan.h b/src/requestLoan.h new file mode 100644 index 0000000..e94f2c9 --- /dev/null +++ b/src/requestLoan.h @@ -0,0 +1,5 @@ +#include +#include + +void requestLoan(); +int allow(); \ No newline at end of file diff --git a/src/sendMoney.c b/src/sendMoney.c new file mode 100644 index 0000000..63fdf95 --- /dev/null +++ b/src/sendMoney.c @@ -0,0 +1,112 @@ +#include "sendMoney.h" +#include "depositMoney.h" +#include "withdrawMoney.h" +#include "currencyExchange.h" +#include "currentCustomerAccountBalance.h" +#include "updateCustomerAccountBalance.h" + + + +void showBalance(int customerID){ + float balance=getAvailableAccountBalance(customerID); + printf("\n:.:.:.:.:.:"); + printf("\nYour current balance is %.2f.\n",balance); + printf(":.:.:.:.:.:\n"); +} + +float askToConvert(float input, int customerID){ + char c; + char symbol[]=""; + int id; + float converted; + printf("\nWould you like to convert the amount from € to another currency?[y] yes [any] no\n"); + scanf(" %c",&c); + if(c=='y'||c=='Y'){ + printf("\nPlease select from one of the following currencties to convert to:"); + printf("\n[1] USD"); + printf("\n[2] GBP"); + printf("\n[3] YEN"); + printf("\n[4] YUAN\n"); + scanf("%d",&id); + + if(id>0&&id<5){ + converted=convert(input,id); + }else{ + return 0; + } + switch(id){ + case 1: + symbol[0]='$'; + break; + case 2: + symbol[0]='P'; + break; + case 3: + symbol[0]='Y'; + break; + case 4: + symbol[0]='X'; + break; + } + printf("\nYou have successfuly transfered %.2f%s to [%d]",converted, symbol,customerID); + return converted; + }else{ + return 0; + } +} + +void askToShowBalance(int customerID){ + char c; + printf("\nWould you like to see your remaining balance? [y] yes [any] no\n"); + scanf(" %c",&c); + if(c=='y' || c=='Y'){ + showBalance(customerID); + } + return; +} +bool sendMoney(int customerID) { + float available_account_balance = getAvailableAccountBalance(customerID); + float amount_to_send; + int recipient_id; + + showBalance(customerID); + printf("\nHow much would you like to send?\n"); + scanf("%f", &amount_to_send); + if (amount_to_send > 0 && amount_to_send < available_account_balance) { + printf("\nYour input was %.2f€. Please enter the recipient id.\n", amount_to_send); + scanf("%d", &recipient_id); + if (recipient_id > 1000) { + bool recipient_exists = checkCustomerExists(recipient_id); + if (recipient_exists) { + if (recipient_id == customerID) { + printf("\nYou cannot send money to yourself. Aborting. \n"); + return false; + } else { + if (withdrawSpecificAmount(customerID, amount_to_send)) { + if (depositSpecificAmount(recipient_id, amount_to_send)) { + askToConvert(amount_to_send, recipient_id); + askToShowBalance(customerID); + return true; + } else { + printf("\nSomething went wrong with the transfer. Please contact staff."); + } + } + } + } else { + printf("\nThis ID is not from a customer of our bank. A transfer fee of %.2f€ will be taken.\n", TRANSFER_FEE); + if (withdrawSpecificAmount(customerID, amount_to_send + TRANSFER_FEE)) { + askToConvert(amount_to_send, recipient_id); + askToShowBalance(customerID); + return true; + } + } + } else { + printf("\nThe ID you have entered is not valid. Aborting. \n"); + } + } else { + // error + return false; + } + return false; +} + diff --git a/src/sendMoney.h b/src/sendMoney.h new file mode 100644 index 0000000..df64387 --- /dev/null +++ b/src/sendMoney.h @@ -0,0 +1,14 @@ +#ifndef SENDMONEY_H +#define SENDMONEY_H +#include +#include +#include +#include + +#define TRANSFER_FEE 0.8 +void showBalance(int customerID); +float askToConvert(float input, int customerID); +void askToShowBalance(int customerID); +bool sendMoney(int customerID); + +#endif // SENDMONEY_H diff --git a/src/showGeneralInfoEmployee.c b/src/showGeneralInfoEmployee.c new file mode 100644 index 0000000..66b7b1d --- /dev/null +++ b/src/showGeneralInfoEmployee.c @@ -0,0 +1,131 @@ +#include "showGeneralInfoEmployee.h" + +//int checkUser() is helpful for unittesting showGeneralInfoEmployee() +int checkUser(char username[length], char password[length]) +{ + if(strcmp(username,"Atharva")==0 && strcmp(password,"Atharvafdai7514")==0) + { + return 1; + } + + if(strcmp(username,"Can")==0 && strcmp(password,"BlooMaskfdlt3817")==0) + { + return 2; + } + + if(strcmp(username,"Haytham")==0 && strcmp(password,"TimoDLfdai7207")==0) + { + return 3; + } + + if(strcmp(username,"Julius")==0 && strcmp(password,"Insertcatfdai7057")==0) + { + return 4; + } + + if(strcmp(username,"Mohamed")==0 && strcmp(password,"MDfdai6618")==0) + { + return 5; + } + + if(strcmp(username,"Shivam")==0 && strcmp(password,"Schivam007fdlt3781")==0) + { + return 6; + } + + else + { + return 0; + } +} + + +void showGeneralInfoEmployee(char id[length], char password[length]) +{ + // "If Statements" check, whether the username and password match. + + if(checkUser(id, password) == 1) + { + printf(" Welcome Atharva\n"); + printf(" Clearance: 3\n"); + printf(" Welcome Atharva\n"); + printf(" Clearance: 3\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + } + + if(checkUser(id, password) == 2) + { + printf(" Welcome Can\n"); + printf(" Clearance: 3\n"); + printf(" Welcome Can\n"); + printf(" Clearance: 3\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review new customer applications.\n"); + } + + if(checkUser(id, password) == 3) + { + printf(" Welcome Haytham\n"); + printf(" Clearance: 2\n"); + printf(" Welcome Haytham\n"); + printf(" Clearance: 2\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + } + + if(checkUser(id, password) == 4) + { + printf(" Welcome Julius\n"); + printf(" Clearance: 2\n"); + printf(" Welcome Julius\n"); + printf(" Clearance: 2\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + } + + if(checkUser(id, password) == 5) + { + printf(" Welcome Mohamed\n"); + printf(" Clearance: 1\n"); + printf(" Welcome Mohamed\n"); + printf(" Clearance: 1\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + printf(" ->Terminate account.\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + printf(" ->Terminate account.\n"); + } + + if(checkUser(id, password) == 6) + { + printf(" Welcome Shivam\n"); + printf(" Clearance: 1\n"); + printf(" Welcome Shivam\n"); + printf(" Clearance: 1\n"); + printf("\n"); + printf("\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + printf(" ->Terminate account.\n"); + printf(" ->Review new customer applications.\n"); + printf(" ->Review loan applications.\n"); + printf(" ->Terminate account.\n"); + } + +} + diff --git a/src/showGeneralInfoEmployee.h b/src/showGeneralInfoEmployee.h new file mode 100644 index 0000000..65165f1 --- /dev/null +++ b/src/showGeneralInfoEmployee.h @@ -0,0 +1,12 @@ +#ifndef SHOWGENERALINFOEMPLOYEE_H +#define SHOWGENERALINFOEMPLOYEE_H + +#include +#include +#include + +#define length 20 + +int checkUser(char username[length], char password[length]); +void showGeneralInfoEmployee(char id[length], char password[length]); +#endif // SHOWGENERALINFOEMPLOYEE_H diff --git a/src/updateCustomerAccountBalance.c b/src/updateCustomerAccountBalance.c new file mode 100644 index 0000000..900928e --- /dev/null +++ b/src/updateCustomerAccountBalance.c @@ -0,0 +1,169 @@ +#include "updateCustomerAccountBalance.h" +#include "lineReplacer.h" +#include "_file_information.h" + +void troubleShoot(int errorCode){ + printf("Error! The requested operation was terminated because of an issue. Here are some details about the error:\n---------------\n"); + + switch(errorCode){ + case 0: + printf("Requested file could not be opened. Are you sure it exists or that the program has the required permissions?"); + break; + case 1: + printf("A temporary file could not be generated. Are you sure the bank management system has the required authorization to create new files?"); + break; + case 2: + printf("Replacement of the old file failed. Are you sure the bank management system has the required authorization to delete files?"); + break; + case 3: + printf("Renaming of a file failed. Are you sure the bank management system has the required authorization to rename files?"); + break; + case 4: + printf("Could not find the customer. Please contact customer support."); + break; + } +} + +void replaceLineInFile(const char* file_name, int line, const char* new_line){ + FILE* file = fopen(file_name, "r"); + if (file == NULL) { + troubleShoot(0); + return; + } + char current_string[1024]; + int current_line = 1; + char *temp_file_name = "temp.txt"; + FILE* temp_file = fopen(temp_file_name, "w"); + if (temp_file == NULL) { + troubleShoot(1); + fclose(file); + return; + } + while (fgets(current_string, sizeof(current_string), file) != NULL) { + if (current_line == line) { + fprintf(temp_file, "%s", new_line); + fputs("\n", temp_file); + } else { + fprintf(temp_file, "%s", current_string); + } + current_line++; + } + fclose(file); + fclose(temp_file); + if(remove(file_name)!=0){ + troubleShoot(2); + } // Remove the original file + if(rename(temp_file_name, file_name)!=0){ + troubleShoot(3); + } // Rename the temp file to the original file +} + +void replaceBalanceInString(float replacementBalance, int currentLine) { + char newBalanceLine[MAX_LENGTH] = "balance="; + char balance_as_string[MAX_LENGTH]; + sprintf(balance_as_string, "%g", replacementBalance); //converts replacement balance to string + strcat(newBalanceLine, balance_as_string); + replaceLineInFile(CUSTOMER_DATA_FILE,currentLine,newBalanceLine); +} + +bool updateAvailableAccountBalance(int user_id, float newBalance){ + bool keep_reading = true; + bool customer_found=false; + char buffer[MAX_LENGTH]; + char stringID[MAX_LENGTH] = "ID="; + char user_id_as_string[MAX_LENGTH]; + char balance_String[MAX_LENGTH]; + int currentLine=0; + + sprintf(user_id_as_string, "%d", user_id); // converts user_id to string + strcat(stringID, user_id_as_string); + + FILE *file = fopen(CUSTOMER_DATA_FILE, "r+"); + if (file == NULL) { + troubleShoot(0); + return false; + } + while(keep_reading) { + fgets(buffer, MAX_LENGTH, file); + currentLine++; + if (feof(file)) { + keep_reading = false; + } + else if(strstr(buffer, stringID)) { //found the customer + + for (int i = 0; i < 4; i++) { + fgets(buffer, MAX_LENGTH, file); + } + + strcpy(balance_String, buffer); + currentLine+=4; + keep_reading = false; + customer_found=true; + } + + } + + fclose(file);; + if(customer_found){ + replaceBalanceInString(newBalance,currentLine); + return true; + }else{ + troubleShoot(4); + } + return false; + +} +bool checkCustomerExists(int customerID){ + bool keep_reading = true; + bool customer_found=false; + char buffer[MAX_LENGTH]; + char stringID[MAX_LENGTH] = "ID="; + char user_id_as_string[MAX_LENGTH]; + char balance_String[MAX_LENGTH]; + int currentLine=0; + + sprintf(user_id_as_string, "%d", customerID); // converts user_id to string + strcat(stringID, user_id_as_string); + + FILE *file = fopen(CUSTOMER_DATA_FILE, "r+"); + if (file == NULL) { + return false; + } + while(keep_reading) { + fgets(buffer, MAX_LENGTH, file); + currentLine++; + if (feof(file)) { + keep_reading = false; + } + else if(strstr(buffer, stringID)) { //found the customer + + for (int i = 0; i < 4; i++) { + fgets(buffer, MAX_LENGTH, file); + } + + strcpy(balance_String, buffer); + currentLine+=4; + keep_reading = false; + customer_found=true; + } + + } + + fclose(file);; + if(customer_found){ + return true; + }else{ + return false; + } + return false; + +} + +//traditional testing section +/* +int main(int argc, char *argv[]) +{ + updateAvailableAccountBalance(1327,70); + return 0; +} +*/ diff --git a/src/updateCustomerAccountBalance.h b/src/updateCustomerAccountBalance.h new file mode 100644 index 0000000..5b056f4 --- /dev/null +++ b/src/updateCustomerAccountBalance.h @@ -0,0 +1,15 @@ +#ifndef UpdateCustomerAccountBalance_H +#define UpdateCustomerAccountBalance_H + +#include +#include +#include +#include + + + +bool updateAvailableAccountBalance(int user_id, float newBalance); +bool checkCustomerExists(int customerID); +void replaceBalanceInString(float replacementBalance, int currentLine); + +#endif \ No newline at end of file diff --git a/src/withdrawMoney.c b/src/withdrawMoney.c new file mode 100644 index 0000000..cfea08b --- /dev/null +++ b/src/withdrawMoney.c @@ -0,0 +1,102 @@ +#include "withdrawMoney.h" +#include "updateCustomerAccountBalance.h" +#include "currentCustomerAccountBalance.h" + + +void notifyCustomer(float amountToWithdraw, float remainingAccountBalance, int user_id) { + char c; + + printf("You have successfully withdrawn %.2f €.\n", amountToWithdraw); + printf("Remaining account balance: %.2f €\n\n", remainingAccountBalance); + printf("Would you like to do another withdrawal? [y] yes [any] no\n"); + scanf(" %c", &c); + + if (c=='y'||c=='Y') { + withdraw(user_id); + }else{ + return; + } +} + +float initiateWithdraw(float amountToWithdraw, float availableAccountBalance) { + float remainingAccountBalance = (availableAccountBalance - amountToWithdraw); + + return remainingAccountBalance; +} + +bool withdraw(int user_id) { + float amountToWithdraw; + char tryDifferentAmount; + float remainingAccountBalance; + bool updateSuccess = false; + + float availableAccountBalance = getAvailableAccountBalance(user_id); + + printf("\n:.:.:.:.:.:"); + printf("\nYour current balance is %.2f.\n",availableAccountBalance); + printf(":.:.:.:.:.:\n"); + + printf("Enter amount to withdraw: "); + scanf("%f", &amountToWithdraw); + + + if (amountToWithdraw > 0) { + if (amountToWithdraw <= availableAccountBalance) { + + if(amountToWithdraw>MAX_AMOUNT){ + printf("\nYou cannot withdraw more than %d€.",MAX_AMOUNT); + return false; + } + + remainingAccountBalance = initiateWithdraw(amountToWithdraw, availableAccountBalance); + updateSuccess = updateAvailableAccountBalance(user_id, remainingAccountBalance); + if( updateSuccess ) { + notifyCustomer(amountToWithdraw, remainingAccountBalance, user_id); + } + else { + printf("Some error occured! Sorry for the inconvenience caused.\n"); + } + return updateSuccess; + + } + else { + printf("You don't have sufficient money to withdraw. Do you want to try different amount?\n[y]: Yes, any other key : exit"); + scanf("%c", &tryDifferentAmount); + if (tryDifferentAmount == 'Y' || tryDifferentAmount == 'y') { + withdraw(user_id); + } + else { + //showAllMenuEntries(); + return false; + } + } + } + else { + printf("Invalid Input! Please try again.\n"); + withdraw(user_id); + } + return false; +} + +bool withdrawSpecificAmount(int user_id, float amountToWithdraw) { + float remainingAccountBalance; + + float availableAccountBalance = getAvailableAccountBalance(user_id); + + if (amountToWithdraw > 0) { + if (amountToWithdraw <= availableAccountBalance) { + remainingAccountBalance = initiateWithdraw(amountToWithdraw, availableAccountBalance); + if (updateAvailableAccountBalance(user_id, remainingAccountBalance)) { + return true; + } + } + } + + return false; +} + + +// int main(){ +// withdraw(1234); +// return 1; +// } diff --git a/src/withdrawMoney.h b/src/withdrawMoney.h new file mode 100644 index 0000000..2303078 --- /dev/null +++ b/src/withdrawMoney.h @@ -0,0 +1,14 @@ +#ifndef WITHDRAWMONEY_H_ +#define WITHDRAWMONEY_H_ + +#include +#include + +#define MAX_AMOUNT 10000 + +bool withdraw(int user_id); +float initiateWithdraw(float amountToWithdraw, float availableAccountBalance); +void notifyCustomer(float amountToWithdraw, float remainingAccountBalance, int user_id); +bool withdrawSpecificAmount(int user_id, float amountToWithdraw); + +#endif \ No newline at end of file diff --git a/team.md b/team.md index 02580e9..f0e0a28 100644 --- a/team.md +++ b/team.md @@ -1,9 +1,6 @@ -# Bankmanagement-System - -- Can Hacioglu, Fdlt3817 +- Can Hacioglu, fdlt3817 - Atharva Kishor Naik, fdai7514 - Julius Philipp Engel, fdai7057 - Shivam Chaudhary, fdlt3781 - Mohamed Yahya Dahi, fdai6618 -- Haytham Daoula, fdai7207 - +- Haytham Daoula, fdai7207 \ No newline at end of file diff --git a/tests/support/.gitkeep b/tests/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_CreateCustomer.c b/tests/test_CreateCustomer.c new file mode 100644 index 0000000..4b48a74 --- /dev/null +++ b/tests/test_CreateCustomer.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include "../src/helperFunctions.c" +#include "../src/error.c" +#include "../src/createCustomer.c" + +void setUp(){} +void tearDown(){} + +void test_generateID(){ + + const int test_values = USHRT_MAX; + + /*initialize blocks by calling generateID()*/ + int *numbers = calloc(test_values, sizeof(int)); + for(int i=0;i +#include +#include +#include "../src/error.c" + +void setUp(){} +void tearDown(){} + + +void test_error() +{ + /*arrange*/ + srand(time(0)); + int bound = 1000; + int invalidErrorCodes_1[bound]; + int invalidErrorCodesLarge_2[bound]; + int invalidErrorCodesLargest_3[bound]; + + int validErrorCodeUnsuccessfulLogin[bound]; + int validErrorCodeMaximumNumberOfAttempts[bound]; + int validErrorCodeNoMenuEntryForNumber[bound]; + /*new test cases*/ + int validErrorCodeNoCustomerDataFile[bound]; + int validErrorCodeTooYoung[bound]; + int validErrorCodeCreatingFile[bound]; + int validErrorCodeForenameTooLong[bound]; + int validErrorCodeSurnameTooLong[bound]; + int validErrorCodePasswordTooLong[bound]; + + int validErrorCodeInvalidCharacterForename[bound]; + int validErrorCodeInvalidCharacterSurname[bound]; + int validErrorCodeTooManyDigits[bound]; + + + for(int i=0;i +#include "../src/loginCustomer.c" +#include "../src/customerMenu.c" +#include "../src/helperFunctions.c" +#include "../src/requestLoan.c" +#include "../src/error.c" +#include "../src/sendMoney.c" +#include "../src/withdrawMoney.c" +#include "../src/depositMoney.c" +#include "../src/currencyExchange.c" +#include "../src/updateCustomerAccountBalance.c" +#include "../src/currentCustomerAccountBalance.c" + +void setUp(){}; +void tearDown(){}; +void test_checkLogin() +{ + /*arrange*/ + bool expected_test_values_compute_to_true[] = {4==4,true==true, 1==1, false==false, 'z'=='z', '='=='=',0x1A==0x1A}; + int length_1 = sizeof(expected_test_values_compute_to_true)/sizeof(bool); + + bool expected_test_values_compute_to_false[] = {4!=4,true==false,1==0,false==true,'z'=='x','!'==')',0x1A==0x2B}; + int length_2 = sizeof(expected_test_values_compute_to_false)/sizeof(bool); + + /*act and assertions*/ + for(int i=0;i<7;++i) { + TEST_ASSERT_TRUE(checkLogin(expected_test_values_compute_to_true[i])); + } + for(int i=0;i<7;++i){ + TEST_ASSERT_FALSE(checkLogin(expected_test_values_compute_to_false[i])); + } +} diff --git a/tests/test_calculatorAdd.c b/tests/test_calculatorAdd.c new file mode 100644 index 0000000..88a58aa --- /dev/null +++ b/tests/test_calculatorAdd.c @@ -0,0 +1,122 @@ +#ifdef TEST + +#include "unity.h" + +#include "../src/calculatorAdd.c" + + + +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test1_calculatorAdd(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 26.24; + num2 = 23.22; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test2_calculatorAdd(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 56.24; + num2 = 233.22; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test3_calculatorAdd(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 1226.24; + num2 = 323.22; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test4_calculatorAdd(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 2623.24; + num2 = 2323.22; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test5_calculatorAdd(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 2435.24; + num2 = 23423.22; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test6_calculatorAdd(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 4534.24; + num2 = 2221.22; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test7_calculatorAdd(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 26322.24; + num2 = 2332.222; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test8_calculatorAdd(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 26132.24; + num2 = 2331122.222; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test9_calculatorAdd(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 6322.24; + num2 = 21232.2322; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test10_calculatorAdd(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 1234.456; + num2 = 654.4321; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +#endif // TEST diff --git a/tests/test_calculatorDivide.c b/tests/test_calculatorDivide.c new file mode 100644 index 0000000..7016ac1 --- /dev/null +++ b/tests/test_calculatorDivide.c @@ -0,0 +1,117 @@ + +#include "unity.h" + +#include "../src/calculatorDivide.c" + +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test1_calculatorDivide(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 26.24; + num2 = 23.22; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test2_calculatorDivide(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 2236.24; + num2 = 2123.22; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test3_calculatorDivide(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 623.2; + num2 = 23.22; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test4_calculatorDivide(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 234.7; + num2 = 124.2; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test5_calculatorDivide(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 26207.2; + num2 = 278.23; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test6_calculatorDivide(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 111; + num2 = 21; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test7_calculatorDivide(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 167; + num2 = 23.22; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test8_calculatorDivide(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 26124; + num2 = 23022; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test9_calculatorDivide(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 1234; + num2 = 4321; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test10_calculatorDivide(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 2345; + num2 = 123.7; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} \ No newline at end of file diff --git a/tests/test_calculatorFactorial.c b/tests/test_calculatorFactorial.c new file mode 100644 index 0000000..8aaf6b0 --- /dev/null +++ b/tests/test_calculatorFactorial.c @@ -0,0 +1,79 @@ +#include "unity.h" + +#include "../src/calculatorFactorial.c" + +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test1_calculatorFactorial(void) +{ + int num, actual, expected; //Arrange + num = 1; + expected = 1; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert +} + +void test2_calculatorFactorial(void) +{ + int num, actual, expected; //Arrange + num = 0; + expected = 1; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert +} + +void test3_calculatorFactorial(void) +{ + int num, actual, expected; //Arrange + num = 3; + expected = 6; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert +} + +void test4_calculatorFactorial(void) +{ + int num, actual, expected; //Arrange + num = 5; + expected = 120; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert +} + +void test5_calculatorFactorial(void) +{ + int num, actual, expected; //Arrange + num = 8; + expected = 40320; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert +} + +void test6_calculatorFactorial(void) +{ + int num, actual, expected; //Arrange + num = 11; + expected = 39916800; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert +} + +void test7_calculatorFactorial(void) +{ + int num, actual, expected; //Arrange + num = 10; + expected = 3628800; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert +} diff --git a/tests/test_calculatorGetUserInput.c b/tests/test_calculatorGetUserInput.c new file mode 100644 index 0000000..89bb6f6 --- /dev/null +++ b/tests/test_calculatorGetUserInput.c @@ -0,0 +1,25 @@ + + +#include "unity.h" + +#include "../src/calculatorGetUserInput.c" + +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_calculatorGetUserInput_NeedToImplement(void) +{ + int actual, expected; //Arrange + expected = 1; + actual = allowOnly(); //Act + TEST_ASSERT_EQUAL_INT(expected, actual);//Assert +} diff --git a/tests/test_calculatorGetUserInputFactorial.c b/tests/test_calculatorGetUserInputFactorial.c new file mode 100644 index 0000000..8d54310 --- /dev/null +++ b/tests/test_calculatorGetUserInputFactorial.c @@ -0,0 +1,27 @@ +#ifdef TEST + +#include "unity.h" + +#include "../src/calculatorGetUserInputFactorial.c" + +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_calculatorGetUserInputFactorial(void) +{ + int actual, expected; //Arrange + expected = 1; + actual = allowWhen(); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert +} + +#endif // TEST diff --git a/tests/test_calculatorMultiply.c b/tests/test_calculatorMultiply.c new file mode 100644 index 0000000..339d3ec --- /dev/null +++ b/tests/test_calculatorMultiply.c @@ -0,0 +1,120 @@ +#ifdef TEST + +#include "unity.h" + +#include "../src/calculatorMultiply.c" + +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test1_calculatorMultiply(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 26.24; + num2 = 23.22; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test2_calculatorMultiply(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 56.24; + num2 = 233.22; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test3_calculatorMultiply(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 1226.24; + num2 = 323.22; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test4_calculatorMultiply(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 2623.24; + num2 = 2323.22; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test5_calculatorMultiply(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 2435.24; + num2 = 23423.22; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test6_calculatorMultiply(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 4534.24; + num2 = 2221.22; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test7_calculatorMultiply(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 26322.24; + num2 = 2332.222; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test8_calculatorMultiply(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 26132.24; + num2 = 2331122.222; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test9_calculatorMultiply(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 6322.24; + num2 = 21232.2322; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test10_calculatorMultiply(void) +{ + float num1, num2, actual ,expected; //Arrange + num1 = 1234.456; + num2 = 654.4321; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +#endif // TEST diff --git a/tests/test_calculatorSubtract.c b/tests/test_calculatorSubtract.c new file mode 100644 index 0000000..323e932 --- /dev/null +++ b/tests/test_calculatorSubtract.c @@ -0,0 +1,121 @@ +#ifdef TEST + +#include "unity.h" + +#include "../src/calculatorSubtract.c" + +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + + +void test1_calculatorSubtract(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 123.211; + num2 = 112.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test2_calculatorSubtract(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 13.21; + num2 = 112.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test3_calculatorSubtract(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 12231.211; + num2 = 1122.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test4_calculatorSubtract(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 113453.211; + num2 = 11254.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test5_calculatorSubtract(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 12133.211; + num2 = 112.231; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test6_calculatorSubtract(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 1133.201; + num2 = 11221.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test7_calculatorSubtract(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 12213.2211; + num2 = 111.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test8_calculatorSubtract(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 16213.711; + num2 = 1214.2251; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test9_calculatorSubtract(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 1933.611; + num2 = 1432.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +void test10_calculatorSubtract(void) +{ + float num1, num2, actual, expected; //Arrange + num1 = 1233.811; + num2 = 1121.131; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert +} + +#endif // TEST diff --git a/tests/test_checkLoanEligibility.c b/tests/test_checkLoanEligibility.c new file mode 100644 index 0000000..008b4ae --- /dev/null +++ b/tests/test_checkLoanEligibility.c @@ -0,0 +1,57 @@ +#ifdef TEST + +#include "unity.h" +#include "../src/checkLoanEligibility.c" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_checkLoanEligibilitySuccess(void) { + + /* Arrange */ + + int user_id[3] = {1234, 1327, 1666}; // user_ids from file for testing + + bool result[3]; + + /* Act */ + + for (int i = 0; i < 3; i++) { + result[i] = checkLoanEligibility(user_id[i]); + } + + /* Assert */ + + for (int i = 0; i < 3; i++) { + TEST_ASSERT_TRUE(result[i]); // Pass if user_id is found in the file + } +} + +void test_checkLoanEligibilityFailure(void) { + + /* Arrange */ + + int user_id[3] = {12314, 127, 166}; // Random wrong user_ids + + bool result[3]; + + /* Act */ + + for (int i = 0; i < 3; i++) { + result[i] = checkLoanEligibility(user_id[i]); + } + + /* Assert */ + + for (int i = 0; i < 3; i++) { + TEST_ASSERT_FALSE(result[i]); // Pass if the returned result is false + } +} + + +#endif // TEST \ No newline at end of file diff --git a/tests/test_createEmployeeAccount.c b/tests/test_createEmployeeAccount.c new file mode 100644 index 0000000..410b0d9 --- /dev/null +++ b/tests/test_createEmployeeAccount.c @@ -0,0 +1,304 @@ + +#include "unity.h" + +#include "../src/createEmployeeAccount.c" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_isValidEmployeeID(void) +{ + //test case 0 + /*Arrange*/ + + char* validEmployeeId [] = {"Atharva","Can","Haytham","Julius","Mohamed","Shivam","Fizz","Buzz","JohnDoe","Foobar","waz","Objectoriented","INSTITUTIONALISATIOL","Intercommunicational","1234","1.6"}; + int validStringLengths = 20; + bool validEmployeeIdExpected = true; + + /*Act and Assert*/ + + for(int i=0; i<15; i++) + { + bool validEmployeeIdResult = isValidEmployeeID(validEmployeeId[i],validStringLengths); + TEST_ASSERT_EQUAL(validEmployeeIdExpected,validEmployeeIdResult); + } +} + +void test_isNotValidEmployeeID(void) +{ + //test case 1 + /*Arrange*/ + + char* invalidEmployeeId [] = {"Atha rva","Ca n","Geschwindigkeitsbegrenzungen","1234 15","John Doe","fizz Fuzz"}; + int invalidStringLengths = 20; + bool invalidEmployeeIdExpected = false; + + /*Act and Assert*/ + + for(int i=0; i<6; i++) + { + bool invalidEmployeeIdResult = isValidEmployeeID(invalidEmployeeId[i],invalidStringLengths); + TEST_ASSERT_EQUAL(invalidEmployeeIdExpected,invalidEmployeeIdResult); + } + +} + +void test_validEmployeePassword(void) +{ + /*Arrange*/ + + char* validPassword [] = {"Atharva.123","02.September.2023","fdai7207.","array[20]","malloc(20*sizeof(int))","12.2E1234"}; + int minimalLength = 8; + bool validPasswordexpectation = true; + bool validPasswordResult[6]; + + /*Act and Assert*/ + + for(int i=0; i<6; i++) + { + validPasswordResult[i] = isValidPassword(validPassword[i],minimalLength); + TEST_ASSERT_EQUAL(validPasswordexpectation,validPasswordResult[i]); + } + +} + +void test_invalidEmployeePassword(void) +{ + /*Arrange*/ + + char* invalidPassword [] = {"fizzbuzzio","02.09.2023",".^^_*+/-.","RTX4050ti","Can","github.com/bankmanagement-system"}; + int minimalLength = 8; + bool invalidPasswordexpected = false; + bool invalidPasswordResult[6]; + + /*Act and Assert*/ + + for(int i=0; i<6; i++) + { + invalidPasswordResult[i] = isValidPassword(invalidPassword[i],minimalLength); + TEST_ASSERT_EQUAL(invalidPasswordexpected,invalidPasswordResult[i]); + } + +} + +void test_verifyPasswordSuccess() +{ + /*Arrange*/ + + char* passwordsAndVerifications[][2] = { + {"Atharva123.","Atharva123."}, + {"fdai.7207","fdai.7207"}, + {"fizz.buzz132","fizz.buzz132"}, + {"23.March.1999","23.March.1999"}, + {"John.doe99","John.doe99"}, + {"foo/bar2","foo/bar2"}, + {"fizz+3buzz","fizz+3buzz"}, + {"gitlab2.com","gitlab2.com"}, + {"4test:all","4test:all"}, + {"WS-2023","WS-2023"} + }; + + bool expectation = true; + + /*Act and Assert*/ + + for(int i=0; i<10; i++) + { + bool result = verifyPassword(passwordsAndVerifications[i][0],passwordsAndVerifications[i][1]); + TEST_ASSERT_EQUAL(expectation,result); + } +} + +void test_verifyPasswordFailure() +{ + /*Arrange*/ + + char* passwordsAndVerifications[][2] = { + {"Atharva123.","Atharva123"}, + {"fdai.7207","fdai.72"}, + {"fizz.buzz132","invalidPassword"}, + {"23.March.1999","23.May.1999"}, + {"John.doe99","Jane.doe99"}, + {"foo/bar2","foo*bar3"}, + {"fizz+3buzz","fizz-3buzz"}, + {"gitlab2.com","github.com"}, + {"4test:all","4ceedlingtest:all"}, + {"WS-2023","SS-2023"} + }; + + bool expectation = false; + + /*Act and Assert*/ + + for(int i=0; i<10; i++) + { + bool result = verifyPassword(passwordsAndVerifications[i][0],passwordsAndVerifications[i][1]); + TEST_ASSERT_EQUAL(expectation,result); + } + +} + +void test_employeesDataStoringSuccess(void) +{ + /*Arrange*/ + char* data[][4] ={ + {"John","Doe","fulda,leipzigerstr12","+4926428421469"}, + {"Jane","Done","fulda,leipzigerstr13","+4932517359874"}, + {"Foo","Bar","fulda,leipzigerstr14","+4913598765315"}, + {"Mustermann","Mustermanpass","fulda,leipzigerstr16","+4938197853812"} + }; + bool creationExpectation = true; + + /*Act and Assert*/ + + for(int i=0;i<4;i++) + { + bool creationResult = storeEmployeeData(data[i][0],data[i][1],data[i][2],data[i][3]); + TEST_ASSERT_EQUAL(creationExpectation,creationResult); + } + +} + +void test_employeeCreatedSuccessfully(void) +{ + /*Arrange*/ + char* potentialEmployees[][2] = { + {"John", "Doe"}, + {"Fizz", "Buzz"}, + {"Jane", "Doe"}, + {"Foo", "Bar"}, + {"MusterMann", "MusterManPassword"}, + {"MusterFrau", "MusterFrauPassword"} + }; + + bool expected = true; + bool result; + + /*Act and Assert*/ + + for(int i=0; i<6;i++) + { + result = createNewEmployee(potentialEmployees[i][0],potentialEmployees[i][1]); + TEST_ASSERT_EQUAL(expected,result); + } + +} + +void test_validName(void) +{ + /*Arrange*/ + + char* validNames[] = {"John","Jane","Fizz","Fooo","Atharva","Cahn","Julius","Haytham","Mohamed","Shivam"}; + int minimalLength = 4; + bool validNamesExpectation = true; + + /*Act and Assert*/ + + for(int i = 0;i<10;i++) + { + bool validNamesResult = isValidName(validNames[i],minimalLength); + TEST_ASSERT_EQUAL(validNamesExpectation,validNamesResult); + } + +} + +void test_invalidName(void) +{ + /*Arrange*/ + + char* invalidNames[] = {"Jo hn","Jane.","Fizz36","Foo8","Ath,arva","C .a1n","Jul.3ius","H613 aytham","Moh35gta.med","S-+h ivam"}; + int minimalLength = 4; + bool invalidNamesExpectation = false; + + /*Act and Assert*/ + + for(int i = 0;i<10;i++) + { + bool invalidNamesResult = isValidName(invalidNames[i],minimalLength); + TEST_ASSERT_EQUAL(invalidNamesExpectation,invalidNamesResult); + } + +} + +void test_validPhoneNumber(void) +{ + /*Arrange*/ + char* validPhoneNumbers[] = {"+4903584736198","+4912345678912","+4987541024534","+4932145784236","+4987264287139"}; + bool validPhoneNumbersExpectation = true; + + /*Act and Assert*/ + for(int i =0;i<5;i++) + { + bool validPhoneNumbersResult = isValidPhoneNumber(validPhoneNumbers[i]); + TEST_ASSERT_EQUAL(validPhoneNumbersExpectation, validPhoneNumbersResult); + } +} + +void test_isValidAdressSuccess(void) +{ + /*Arrange*/ + char* validCityAndStreet[][2] = { + {"LeipzigerStrasse","Hannover"}, + {"HannauerLandStra","Frankfurt"}, + {"HenirichStrasse","Berlin"}, + {"MAgdeburgerStrasse","Fulda"}}; + + int validHouseNumberAndPostalCode[][2] = { + {112,36879}, + {365,36897}, + {16,12354}, + {998,9999}}; + bool expectation = true; + + /*Act and Assert*/ + for(int i=0;i<4;i++) + { + bool validAdress = isValidAdress(validCityAndStreet[i][0],validCityAndStreet[i][1],validHouseNumberAndPostalCode[i][0],validHouseNumberAndPostalCode[i][1]); + TEST_ASSERT_EQUAL(expectation,validAdress); + } + +} +void test_isValidAdressFailure(void) +{ + /*Arrange*/ + char* invalidCityAndStreet[][2] = { + {"LeipzigerStrassehvjhb","log"}, + {"HannauerLandStranl","fiz"}, + {"bob","foo"}, + {"..","bar"}}; + + int invalidHouseNumberAndPostalCode[][2] = { + {-10,-1}, + {-1,10}, + {0,999}, + {99815,65}}; + bool expectation = false; + + /*Act and Assert*/ + for(int i=0;i<4;i++) + { + bool invalidAdress = isValidAdress(invalidCityAndStreet[i][0],invalidCityAndStreet[i][1],invalidHouseNumberAndPostalCode[i][0],invalidHouseNumberAndPostalCode[i][1]); + TEST_ASSERT_EQUAL(expectation,invalidAdress); + } + +} +void test_invalidPhoneNumber(void) +{ + /*Arrange*/ + char* invalidPhoneNumbers[] = {"+490358473619812","+6112345678912","+498754","-4932145784236","123"}; + bool invalidPhoneNumbersExpectation = false; + + /*Act and Assert*/ + for(int i =0;i<5;i++) + { + bool invalidPhoneNumbersResult = isValidPhoneNumber(invalidPhoneNumbers[i]); + TEST_ASSERT_EQUAL(invalidPhoneNumbersExpectation,invalidPhoneNumbersResult); + } + +} + diff --git a/tests/test_currencyExchange.c b/tests/test_currencyExchange.c new file mode 100644 index 0000000..0c3096e --- /dev/null +++ b/tests/test_currencyExchange.c @@ -0,0 +1,58 @@ +#ifdef TEST + +#include "unity.h" +#include "../src/currencyExchange.c" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_convert(void) { + + /* Arrange */ + + int length = 10; + float euro[] = {34, 233, 400, 100, 45, 344, 767.32, 122, 435, 899}; + + float expectedUSD[length]; + float expectedGBP[length]; + float expectedYEN[length]; + float expectedYUAN[length]; + + float resultUSD[length]; + float resultGBP[length]; + float resultYEN[length]; + float resultYUAN[length]; + + for (int i = 0; i < length; i++) { + expectedUSD[i] = euro[i] * USD_RATE_OF_ONE_EURO; + expectedGBP[i] = euro[i] * GBP_RATE_OF_ONE_EURO; + expectedYEN[i] = euro[i] * JAPANESE_YEN_RATE_OF_ONE_EURO; + expectedYUAN[i] = euro[i] * CHINESE_YUAN_RATE_OF_ONE_EURO; + } + + /* Act */ + + for (int i = 0; i < length; i++) { + resultUSD[i] = convert(euro[i], CURRENCY_CODE_USD); + resultGBP[i] = convert(euro[i], CURRENCY_CODE_GBP); + resultYEN[i] = convert(euro[i], CURRENCY_CODE_JAPANESE_YEN); + resultYUAN[i] = convert(euro[i], CURRENCY_CODE_CHINESE_YUAN); + } + + /* Assert*/ + + for (int i = 0; i < length; i++) { + TEST_ASSERT_EQUAL_FLOAT(expectedUSD[i], resultUSD[i]); + TEST_ASSERT_EQUAL_FLOAT(expectedGBP[i], resultGBP[i]); + TEST_ASSERT_EQUAL_FLOAT(expectedYEN[i], resultYEN[i]); + TEST_ASSERT_EQUAL_FLOAT(expectedYUAN[i], resultYUAN[i]); + } +} + + +#endif // TEST \ No newline at end of file diff --git a/tests/test_currentCustomerAccountBalance.c b/tests/test_currentCustomerAccountBalance.c new file mode 100644 index 0000000..ca5c2b2 --- /dev/null +++ b/tests/test_currentCustomerAccountBalance.c @@ -0,0 +1,87 @@ +#ifdef TEST + +#include +#include "unity.h" +#include "../src/currentCustomerAccountBalance.c" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_fetchBalanceFromBalanceString(void) { + + /* Arrange */ + + char balanceString[5][100] = { + "balance=0", + "balance=100", + "balance=200", + "balance=300", + "balance=400" + }; + + /* Act */ + + float balance = 0; + float result[5]; + float expected[5]; + + for (int i = 0; i < 5; i++) { + result[i] = fetchBalanceFromBalanceString(balanceString[i]); + } + + /* Assert */ + + for (int i = 0; i < 5; i++) { + expected[i] = balance; + balance += 100; + } + + for (int i =0; i < 5; i++) { + TEST_ASSERT_EQUAL_FLOAT(expected[i],result[i]); + } + + +} + + +void test_checkFileOpen(void) { + + /* Act and assert */ + + FILE *file = fopen(CUSTOMER_DATA_FILE, "r"); + + TEST_ASSERT_TRUE(file); + + fclose(file); +} + +void test_failOpenFile(void) { + + /* Act and assert */ + + FILE *file = fopen("false_file_name", "r"); + + TEST_ASSERT_FALSE(file); + +} + +void test_getAvailableAccountBalance(void) { + + /* Act and assert */ + + int user_id = 1234; // Random user_id (because idea is to read the file and get a float value) + float max = FLT_MAX; + int result = getAvailableAccountBalance(user_id); + + TEST_ASSERT_TRUE(result < max); // Pass if function is successfully called and a float value (balance) is returned +} + + + + +#endif // TEST diff --git a/tests/test_depositMoney.c b/tests/test_depositMoney.c new file mode 100644 index 0000000..186ef28 --- /dev/null +++ b/tests/test_depositMoney.c @@ -0,0 +1,36 @@ +#include "unity.h" +#include "../src/currentCustomerAccountBalance.c" +#include "../src/depositMoney.c" +#include "../src/updateCustomerAccountBalance.c" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_depositSpecificAmount(void) { + + /* Arrange */ + + int length = 5; + int userIDs[] = {1234,1235,1236,1237,1238}; + float amountToDeposit[] = {200.5, 340, 244.5, 340, 1200}; + + bool result[length]; + + /* Act */ + + for (int i = 0; i < length; i++) { + result[i] = depositSpecificAmount( userIDs[i], amountToDeposit[i] ); + } + + /* Assert */ + + for (int i = 0; i < length; i++) { + TEST_ASSERT_TRUE(result[i]); + } + +} \ No newline at end of file diff --git a/tests/test_displayMenuCalculator.c b/tests/test_displayMenuCalculator.c new file mode 100644 index 0000000..5a9fd0c --- /dev/null +++ b/tests/test_displayMenuCalculator.c @@ -0,0 +1,31 @@ +#ifdef TEST + +#include "unity.h" + +#include "../src/displayMenuCalculator.c" +#include "../src/calculatorAdd.c" +#include "../src/calculatorDivide.c" +#include "../src/calculatorFactorial.c" +#include "../src/calculatorGetUserInput.c" +#include "../src/calculatorGetUserInputFactorial.c" +#include "../src/calculatorMultiply.c" +#include "../src/calculatorSubtract.c" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_displayMenuCalculator(void) +{ + int expected, actual; //Arrange + expected = 1; + actual = check(); //Act + TEST_ASSERT_EQUAL_INT(expected, actual);//Assert +} + + +#endif // TEST diff --git a/tests/test_employeeLogin.c b/tests/test_employeeLogin.c new file mode 100644 index 0000000..6626a37 --- /dev/null +++ b/tests/test_employeeLogin.c @@ -0,0 +1,147 @@ +#ifdef TEST + +#include "unity.h" + +#include "../src/employeeLogin.c" +#include "../src/showGeneralInfoEmployee.c" +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_SuccessfulLoginEmployee_(void) +{ + + //test case : 0 + + /*Arrange*/ + + char* validEmployeesCredentials[][2] = { + {"Atharva", "Atharvafdai7514"}, + {"Can", "BlooMaskfdlt3817"}, + {"Haytham", "TimoDLfdai7207"}, + {"Julius", "Insertcatfdai7057"}, + {"Mohamed", "MDfdai6618"}, + {"Shivam", "Schivam007fdlt3781"} + }; + /*Act and Assert*/ + + int expected[] = {1,1,1,1,1,1}; + + for(int i=0; i<6; i++) + { + + int result = checkEmployeeCredentials(validEmployeesCredentials[i][0], validEmployeesCredentials[i][1]); + + TEST_ASSERT_EQUAL_INT(expected[i],result); + + } + + + + +} + +void test_WrongInfosLoginEmployee(void) +{ + //test case : 1 + /*Arrange*/ + + char* wrongEmployeesCredentials[][2] = { + {"Atharva", "doe"}, + {"Can", "Bar"}, + {"Haytham", "buzz"}, + {"Julius", "fizz"}, + {"Mohamed", "muster"}, + {"Shivam", "TimoDL"} + }; + + /*Act and Assert*/ + + int expected[] = {2,2,2,2,2,2}; + + for(int i=0; i<6; i++) + { + + int result = checkEmployeeCredentials(wrongEmployeesCredentials[i][0], wrongEmployeesCredentials[i][1]); + + TEST_ASSERT_EQUAL_INT(expected[i],result); + + } + +} + + + + +void test_MissingLoginEmployee(void) +{ + + //test case : 2 + /*Arrange*/ + + char* missingEmployeesCredentials[][2] = { + {"Germany", "Berlin"}, + {"Italy", "Rome"}, + {"Belgium", "Bruxelle"}, + {"Swizerland", "Geneve"}, + {"Netherlands", "Amsterdam"}, + {"Sweden", "Stockholm"} + }; + + int expected[] = {0,0,0,0,0,0}; + + /*Act and Assert*/ + + for(int i=0; i<6; i++) + { + + int result = checkEmployeeCredentials(missingEmployeesCredentials[i][0], missingEmployeesCredentials[i][1]); + + TEST_ASSERT_EQUAL_INT(expected[i],result); + + } + + +} + +void test_validEmployeeAccessCode(void) +{ + //test case 0 + + /*Arrange*/ + + char validAccesscode[11] = "DF9E9A8B5E"; + + /*Act*/ + bool validAccessCodeResult = employeesAccess(validAccesscode); + + /*Assert*/ + + TEST_ASSERT_TRUE(validAccessCodeResult); + +} + +void test_invalidEmployeeAccessCode(void) +{ + //test case 1 + + /*Arrange*/ + + char* invalidAccessCode[] = {"15","foo","fizz","buzz","fizzbuzz","test","bankmanagement"}; + bool invalidCodeExpectation = false; + + /*Act and assert*/ + + for(int i=0;i<7;i++) + { + bool invalidCodeResults = employeesAccess(invalidAccessCode[i]); + TEST_ASSERT_EQUAL(invalidCodeExpectation,invalidCodeResults); + } + +} + +#endif // TEST diff --git a/tests/test_helperFunctions.c b/tests/test_helperFunctions.c new file mode 100644 index 0000000..0b42d1a --- /dev/null +++ b/tests/test_helperFunctions.c @@ -0,0 +1,213 @@ +#include +#include +#include +#include +#include "../src/helperFunctions.c" + +void test_calculateStringLength() +{ + char *testStrings[] = {"linux","table","book","men","woman","boy","girl","computer","old","new","water","fire","bright","dark","black","white"}; int expectedResults[] = {5,5,4,3,5,3,4,8,3,3,5,4,6,4,5,5}; + int numberOfValues= sizeof(expectedResults) / sizeof(int); + for(int i=0;i