Question

Write the code in LISP that define a function(named area-circle) that would calculate (return) the area...

Write the code in LISP that define a function(named area-circle) that would calculate (return) the area of a circle when the radius of the circle is given as an argument.

The function should be able to be called as follows

(area-circle 10)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

(defun area-circle(rad)
   "Calculates area of a circle with given radius"

   (* pi rad rad)
)

(format t "~8f" (area-circle 10))

Screenshot:

(defun area-circle(rad) Calculates area of a circle with given radius HNMOCO (* pi rad rad) (format t -8f (area-circle 10

Output:

314.1593
Add a comment
Answer #2

;;;;;;;Writing a function which defines the area of circle while taking radius as its parameter

(defconstant PI 3.14) ;Here we define the value of pie as constant

(defun area-circle(radiuslength) ; Here the function is called with radius length as parameter

(terpri)

(format t "Radius of the circle is: ~5f"radiuslength) ; Displaying the radius length for ease of the user

(format t "~%Area of the circle is:~10f" (*PI * radiuslength * radiuslength))) ; Calculating the area of circle

(area-circle 10) ;Actually giving the value to the function,i.e.the radius length

;;;;;;;;;;;;;;;;;;Below is the output of the code we have just incorporated

==========================================================

Output:-

Radius of the circle is 10

Area of the circle is 314

Add a comment
Know the answer?
Add Answer to:
Write the code in LISP that define a function(named area-circle) that would calculate (return) the area...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a class declaration named Circle with a private member variable named radius.

    CODE IN C++Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159 * radius * radius. Add a default constructor the Circle class. The constructor should initialize the radius member to 0. Add an overloaded constructor to the Circle class. The constructor should accept an argument and assign radius...

  • Create a new file named spherevolume.py that does the following: Define a function named sphereVolume that...

    Create a new file named spherevolume.py that does the following: Define a function named sphereVolume that accepts a radius value as an argument and returns (not prints) the volume of a sphere with that radius. Write code to test your function with the following inputs: sphereVolume(2.0) // should return 33.510321638291124 or a number close to it. sphereVolume(5.0) // should return 523.5987755982989 or a number close to it.

  • Write a class declaration named Circle with a private member variable named radius.

     in C++ Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159*radius*radius. Add a default constructor to the Circle class. The constructor should initialize the radius member to 0. Add an overloaded constructor to the Circle class. The constructor should accept an argument and assign its value to the radius...

  • Define an interface named Shape with a single method named area that calculates the area of...

    Define an interface named Shape with a single method named area that calculates the area of the geometric shape:        public double area(); Next, define a class named Circle that implements Shape. The Circle class should have an instance variable for the radius, a constructor that sets the radius, an accessor and a mutator method for the radius, and an implementation of the area method. Define another class named Rectangle that implements Shape. The Rectangle class should have instance variables...

  • A. (C++) Write a class declaration named Circle, with a private member variable, radius. Write set...

    A. (C++) Write a class declaration named Circle, with a private member variable, radius. Write set and get functions to access the radius variable, and a function named get getArea which returns the area of the circle. The area is calculated as 3.14 * radius * radius. B. Write a constructor to the circle that accepts an argument and assign its value to the radius member variable. C. Add a static member variable that accounts for the currently active circle...

  • 1. Write a Lisp function called piece which takes a single argument x and implements the followin...

    1. Write a Lisp function called piece which takes a single argument x and implements the following piecewise linear function: piece(x) = x if 0 < x < 1 2. Write a Lisp function called intList which takes two integer arguments, a and b and returns the list of all integers from a to b (inclusive at both ends). For example, (intList 3 8) should return (345678) 1. Write a Lisp function called piece which takes a single argument x...

  • In Python beginner code: Write a function named even_div, that takes two arguments (you can safely...

    In Python beginner code: Write a function named even_div, that takes two arguments (you can safely assume that both arguments will always be non-zero integers). When this function is called, it should return how many times the first argument can be divided by the second argument, if it is evenly divisible (no remainder). If it is not evenly divisible, the function should return 0. Examples: even_div(5, 2) will return 0 (5 divided by 2 is 2.5, not evenly divisible) even_div(10,...

  • Please use C++. Write a class named Circle that has a double data member named radius...

    Please use C++. Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius....

  • Write a function that prints the area and circumference of a circle for a given radius....

    Write a function that prints the area and circumference of a circle for a given radius. Only the radius is passed to the function. The function does not return any values. The area is given by π r2 and the circumference is 2 π r.

  • Write a static method named middleValue that takes three int arguments, and returns an int. When...

    Write a static method named middleValue that takes three int arguments, and returns an int. When given three different argument values, the method should return the value that is numerically between the other two values. When given three values where two or more argument values are the same, then the function should return that value. Examples: middleValue(1, 2, 3) will return 2 middleValue(5, 2, 7) will return 5 middleValue(8, 4, 6) will return 6 middleValue(1, 2, 1) will return 1...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT