TABLE OF CONTENTS
Lab 7 of 7: Coding in Functional and Logic Programming Languages (50 points)
Lab Overview
Scenario/Summary
Download the Week 7 Lab and complete all the questions listed on the page. You will notice that the readings, including lessons, the examples we worked on during the lesson, and other audio and visual aids provided, will help you tackle this week’s lab. Remember to use the weekly discussion related to the lab and the Course Q & A Forum in the Introduction and Resources module for additional help. Be specific and state the problem you are having clearly, including what you have done to resolve it, in the discussion.
Deliverables
Please save the completed Word document using the following naming convention. Save it personalized as CEIS420_LastName_FirstName_iLab7.
Required Software
Microsoft Word
Access the software at https://lab.devry.edu (Links to an external site.).
Lab Steps
STEP 1: Complete Lab
• Download the Week 7 Lab (Links to an external site.) to prepare for your deliverable this week.
• Complete the code for Part A.
• Answer the questions for Part A.
• Complete the code for Part B.
• Take screenshots using ALT-PrtScrn and paste them into the lab report.
• Answer the questions for Part C.
Grading Rubric
Category Points % Description
Part A: Functional Programming in Scheme 25 50 Create a Scheme function.
Part B: Functional Programming Versus Object-Oriented Programming 20 40 Comparing function language versus OOP language.
Part C: Analyzing Functional Programming Versus Object-Oriented Programming 5 10 Analyzing function programming versus OOP programming.
Total 50 100
Week 7 Lab—Functional Programming Versus Object-Oriented Programming
Scenario
In this week’s lab, you will look at functional programming in scheme and compare it to object- oriented programming.
Rubric
Point distribution for this activity:
Lab Activity
Document Points possible Points received
Part A 25
Part B 20
Part C 5
Total Points 50
Part A: Functional Programming in Scheme
Use a scheme interpreter online (or download an interpreter). https://repl.it/repls/DetailedHightechChemistry
We will look at two different functions in scheme and compare them to an OOP language.
1. A famous algorithm for sorting a list is called quicksort. Type in the following code for quick sort into the scheme interpreter.
(define qsort
(lambda (l)
(let ((lesser ‘()))
(let ((greater ‘()))
(cond
((null? l) ‘())
(else (map (lambda (ele)
(if (> (car l) ele)
(set! lesser (cons ele lesser))
(set! greater (cons ele greater)))) (cdr l))
(append (qsort lesser) (cons (car l) (qsort greater))))
)))))
To run this code, pick run at the top of the screen.
Then type in the function name and a set of numbers as below so that scheme will sort them. For example: (qsort ‘(1 2 5 8 0 4 3))
Add different numbers than above and paste a screenshot showing it working to sort the list.
2. Another famous function that adds up the previous two numbers to create a list is called the Fibonacci sequence.
Write this code in scheme to create a Fibonacci sequence.
(define (fib n)
(if (< n 2) n (+ (fib (- n 1))
(fib (- n 2)))))
What is the result of the 10th element? And the 15th element?
(fib 10)
Answer: ______________________
(fib 15)
Answer: ______________________
Part B:
1. To examine the differences between the code, we will implement the same code in Java, C++ or C#.
Example Java Code:
Qsort class:
class Qsort {
/* This function takes last element and places it in the correct position in the sorted array. Then places smaller elements to the left and greater to the right
*/
int partition(int arr[], int low, int high)
{
int pivot = arr[high];
int i = (low-1); // index of smaller element
for (int j=low; j
low –> Starting index,
high –> Ending index */
void sort(int arr[], int low, int high)
{
if (low < high)
{
/* pi is partitioning index, arr[pi] is
now at right place */
int pi = partition(arr, low, high);
// Recursively sort elements before
// partition and after partition
sort(arr, low, pi-1);
sort(arr, pi+1, high);
}
}
}
Quicksort class (including main):
public class Quicksort {
public static void main(String[] args) {
int arr[] = {1, 2, 5, 8, 0, 4, 3};
int n = arr.length;
Qsort ob = new Qsort();
ob.sort(arr, 0, n-1);
System.out.println(“sorted array”);
printArray(arr);
}
static void printArray(int arr[])
{
int n = arr.length;
for (int i=0; i
* You can also use 2CO option if you want to purchase through Credit Cards/Paypal but make sure you put the correct billing information otherwise you wont be able to receive any download link.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at [email protected].
* As soon as the payment is received, download link of the solution will automatically be sent to the address used in selected payment method.
* Please check your junk mails as the download link email might go there and please be patient for the download link email. Sometimes, due to server congestion, you may receive download link with a delay.
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at [email protected] and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side. Afterall, we are humans.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.
* In case of any query, please donot hesitate to contact us at [email protected].
* MOST IMPORTANT Please use the tutorials as a guide and they need NOT to be used for any submission. Just take help from the material.
******************************************** Good Luck ***************************************************
Any personal information received will only be used to fill your order. We will not sell or redistribute your information to anyone.
We will try our best to resolve the issue and if still persists we can discuss for a refund in case its required.