Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the text editor of your choosing create a file l ab04 . e rl and write function definitions that could be run from the

In the text editor of your choosing create a file lab04.erl and write function definitions that could be run from the shell make sure you use the exact same names (anything in italics) as indicated in function descriptions. Pay attention to directions that specify what syntactical mechanisms to use within the functions (the purpose of this lab is to make sure you are familiar with most of the basic Erlang syntax discussed this week).

1. Function coneArea that takes two arguments that represent the radius of the base of a right circular

cone and the height of that cone (in this order) and returns the surface area of that cone using the

following formula:

you do NOT have to guard against invalid input; use pi and square root defined in the math library

2. Function isDifferent that takes two arguments and returns false if these two values are the same

considering both the value and the type, i.e. if 5.0 and 5 are passed, the function should return true

because these two parameters have different data types; if 5 and 5 are passed, the function should

return false because these two parameters have the same value and data type

3. Function smallerOne that takes two arguments and returns the smaller one use the if statement

inside the function body; if elements have the same value, returns either one

4. Function displayProperty that takes two arguments and evaluates whether they are odd or even or

mixed. The function should print the following to the console:

the incoming arguments (use the format specifier that will be appropriate for either

floats or ints)

the message:

o Both are even if each one is an even number

o Both are odd if each one of them is an odd number

o One is odd, one is even if one of the arguments is odd and the other one is even To write a boolean expression inside an if, use parenthesis around expressions, e.g.

(X > 0) and (Y > 0). You may also solve this using nested ifs but then remember not to end a nested if with a period since the period indicates the end of a function.

In this function we are not interested in a return value, although Erlang always returns, so write it as if Erlang did not always return (i.e. do not worry what this function will return, focus on what it is to print.

5. Function planets that takes an argument and returns its equivalent gas planet from our Solar System

as an atom using a case expression, where:

for value 1 returns jupiter

for value 2 returns saturn

for value 3 returns uranus

for value 4 returns neptune

for an invalid value, returns no_match

6. Function planets2 that works in the exact same fashion as planets, except uses function level pattern

matching (several function clauses / headers) instead of a case expression inside a function.

7. Function mygcd that implements the recursive math formula provided below do NOT write any if

statements or case expressions inside the function body but rather use function level pattern

matching

When testing this function, mygcd(12, 6) should result in 6, mygcd(2, 6) should result in 2, and

mygcd(5, 5) should result in 5. If either m or n are <= 0, return an atom wrong_input

8. Function mySum that implements the following C code as recursion in Erlang:

int sum ( int boundary ) {

int i, sum = 0;

for(i = 1; i <= boundary; i++)

sum += i;

return sum;

}

You do NOT need to guard against invalid input

Function mySeries that takes 3 arguments: the value of the first term of the geometric sequence, the common ratio (multiplier), and the term number for which the function is to compute and return a

value. For example, if mySeries is called with 2, 3, 4, then it means that the geometric sequence is:

2, 6, 18, 54, and 54 should be returned. You do NOT need to guard against invalid input

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

How do books become world of wonder?

Answered: 1 week ago