#Recursion Factorial computing #Joel Lee 5/1/21
//////////////////////////////////////////////////////////////////////////////////////////////////// Coding Project • If you choose to code, you will write small code that displays the major difference between two languages in two different paradigms. Avoid codes like hello world or greatest of two/three numbers. Program or codes that are Acceptable: o Program to check if a string is palindrome or not. o Reverse words in a given String. o Program for n-th Fibonacci number o Program for factorial of a number o Program to print all Prime numbers in an Interval. o Searching and Sorting Programs Submission guidelines: o The codes should be well commented. Comment effectively so that it is easier to understand. For each concept, include a description. o You can submit the codes in a zip file on blackboard. § ReadMe file: Mention the programming language and compilers used. o You can also code your program in GitHub. In the blackboard submit URL to your GitHub account.
//////////////////////////////////////////////////////////////////////////////////////////////////// #In this project I will be comparing the difference in programming paradigms between Java and C++ Each code is supplied above and is well commented using recursion.
Java Factorial Computing using Recursion DesrciptionIf you look at the way the syntax is written for java it is very similar to c++ but there are key diferences.Java, unlike c++ the language can be interpreted and/or compiled.In the code we first start with a class named Factorial Example, then we start recursion that uses a static integer, unlike the c++ program you have to change the value in the code to figure out the factorial. Recursion is discussed further below. To initialize integers like I and fact, it is very similar to c++ but when it comes to the print statement it's very annoying compared to c++ cout. We call a function "Factorial(number)" like this in java. So for java, you need a class for a program to compile instead of for c++ where you only need a function in order to compile.Java also has generics where the main purpose of those is to provide a type-safe container. To add to that Java also has arbitrary custom metadata to classes from an annotation processing tool.
C++ Factorial Computing using Recursion DesricptionJust like java the code is somewhat similar to java but there are some differences. C++ is not memory safe which causes a lot of memory errors and crashes to take place in the execution of the code. C++ doesn't support threads as Java does. Also, C++ has full pointer support, unlike java which has limited pointer support. If you look at the code we start in the code in main which is different from java. we set an integer n that takes the positive integer to be factored. We then call the factorial function below which is using recursion then spitting the factorial back in a print statement which is very different from the java print statement it's less of a hassle. But anyways c++ supports scope resolution operators where java doesn't even have these types of operators. C++ also has destructors that java doesn't have which I didn't use for this project but I could but I find them to be necessary for this kind of small code project. But furthermore, the data types of java and c++ are very similar. The recursion factor is similar to each other that the only thing that is really ideally the same. C++ also has compile-time templates which are more extensive support for generic programming and metaprogramming.
You are probably wondering what is recursion? Recursion is the process of repeating items in a self-similar way. So in both programs, we call the function inside of its self which is called a recursive call of the function. My choice of using recursion is it makes this factorial computing more reasonable for memory and includes less code when doing it normally it just shows how good recursion can actually be.
Thank you -Bestwishes Joel Lee