Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A. What This Assignment Is About: Lists Control structures (conditions and loops) Define Functions Recursive Calls Data structures B. Use the following Guidelines Give identifiers

A. What This Assignment Is About:

Lists

Control structures (conditions and loops)

Define Functions

Recursive Calls

Data structures

B. Use the following Guidelines

Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.).

Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.

Use white space and newlines (enters) to make your program more readable.

C. Instructions

Code the following functions in a single lisp file named homework.lisp

1. Provide a heading (in comments) which includes: (1) the assignment number, (2) its author

your name, and (3) descriptions of what this program is doing.

2. In a comment, describe what the following code do when it is executed; also, provide an equivalent method/function foo in Java or C/C++

image text in transcribed

3. In a comment, describe what the following code does when it is executed; also, provide an equivalent method/function myPrint in Java or C/C++ image text in transcribed

4. Write an iterative function that calculate the factorial of a positive integer and return the result. The function should be equivalent to this Java code.

public static double factorial (double x) {

double total = 1; for (double i=0; i

total = total * (1 + i);

 return total; 

}

5. Write a recursive function that calculate the factorial of a positive integer and return the result. The function should be equivalent to this Java code.

public static double recurfact (double y) { if (n

 return 1; else 

return n * recurfact (n-1);

}

6. Write a function, named times, that takes a list and returns the number of times the symbol 'a' occurs in it. Note: do not count a's that might occur in a sublist within the list.

7. Write a recursive function that returns the Fibonacci number where the Fibonacci sequence is defined as

 fib(0)=0, fib(1)=1 and fib(n)=fib(n-1)+fib(n-2) for n > 1. 
 examples: n = 0 1 2 3 4 5 6 7 8 9 ... fib(n) = 0 1 1 2 3 5 8 13 21 34 ... 

8. Write a function, named great, that takes 3 numbers and returns the greater of the three.

9. Write a function, named sum, that takes an integer n and returns the summation of n and all

positive integers preceding it; e.g., passing 4 will return 10, which is 1+2+3+4.

10.In a comment, describe what the following code do when it is executed; explain each line and whether the result is a symbol or a list

Define a function test that runs all of the above functions (items 4, 5, 6, 7, 8) as follows. Replace PUT YOUR NAME HERE for your name.

image text in transcribed

The output of calling test should look like this:

CSE 240 Assignment 4. PUT YOUR NAME HERE.

1485715964481761497309522733620825737885569961284688766942216863704985

393094065876545992131370884059645617234469978112000000000000000000000

1485715964481761497309522733620825737885569961284688766942216863704985

393094065876545992131370884059645617234469978112000000000000000000000

1

21

9

10

D. Grading Criteria

File have the name requested, contains header information and follow the guidelines defined in section B. There are adequate comments to explain every method. The function test is included as requested in item 10.

for correctly describe function foo and provide equivalent code in Java or C/C++ for correctly describe function myPrint and provide equivalent code in Java or C/C++ 10 pts for function factorial (iterative function that calculate factorial) for function recurfact (recursive function that calculate factorial) for function times for function fib (recursive function that calculate Fibonacci numbers) for function great for function sum for correctly describe the code in question 10 (11 lines must be described). Be sure to explain setq, quote, print, car, cdr, and append.

(defun foo (a b) C* a b) running foo (print(foo 2 3)) running foo again (print(foo 4 6)) running foo again (print(foo 5 7))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions