Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi there can you help me with the following question please answer all the questions I need it to be answered in Erlang programming language.

Hi there can you help me with the following question please answer all the questions I need it to be answered in Erlang programming language. n the text editor of your choosing create a file lab05.erl and write function definitions described below make sure you use the exact same names as indicated in function descriptions. Instead of exporting each function one by one, use command -compile(export_all) at the top of your file that will export all functions together. Download the file lab05_tests.erl, add Erlang unit test library to it, and as you work on your solutions, write unit tests for your functions (unit tests for the first three functions are provided in the test file and for the last 2 functions in this description note that copying and pasting from the description may introduce invisible characters in which case it is better to re-type the tests). 1. Function money that that takes two tuples, where each tuple represents a money object (each tuple consists of 2 values: dollars and cents) and calculates and returns a new tuple that constitutes the addition of the incoming money objects(dollars + dollars, cents + cents). Assume valid positive integers will be passed and do NOT error check. Normalize the values, i.e. if the cents addition results in a value > 99, adjust dollars and cents properly (hint: to pattern match a function on a tuple consisting of 2 elements, you can use functionName ( {X, Y} ) -> type of a syntax) 2. Function isOlder that takes two dates (each date is a 3-int tuple dd, mm, yyyy) and evaluates to true or false. It evaluates to true if the first argument is a date that comes before the second argument (e.g. 30/3/2012 comes before 1/4/2012, hence a person born on 30/3/2012 is older). (If two dates are the same, the result is false.). Assume the user of your function will enter valid input. Think about how you can use relational operators on entire tuples to simplify processing instead of writing nested ifs 3. Function findCeiling that takes a list of numbers and returns the modified list constructed by applying the function ceiling to each incoming list element. For example, if original list contains [1.9, 2.1, 3.5] , then the resulting list will contain [2.0, 3.0, 4.0]; you are NOT allowed to use ++ or built-in functions or list comprehension (you should use the cons operator | to build the new list; you are allowed to use math:ceil though) 4. Function myMin that takes a list and returns its minimum value use tail recursion to find list minimum and return an atom empty_list if a list is empty; you are NOT allowed to use built-in functions; add appropriate test cases to the test file that use assertEqual macro 5. Function removeDiv3 that takes a list of numbers and returns the original list with all values divisible by 3 removed, e.g. if the original list contains [0, 1, 2, -3, 6], then [1, 2] is returned; you are NOT allowed to use built-in functions or list comprehension; add appropriate test cases to the test file that use true matching pattern (i.e. the other method that does NOT use assertEqual) 6. Function calculateBill that takes a list of tuples, where a tuple is of the form name, price, tax_rate, and returns a list of tuples, where each tuple is of the form name, total

where total = price + price * tax_amount add appropriate test cases to the test file 7. Function generate takes three ints as arguments and generates a list of integers from arg1 to arg2 (inclusive) in increments indicated by arg3, e .g. if arg1 = 3, arg2 = 8, and arg 3 = 2, then the function returns [3, 5, 7]. If arg1 > arg2, returns an empty list; assume arg3 will be a valid number; you are NOT allowed to use built-in functions or list comprehension; add appropriate test cases to the test file 8. Function getnth that takes a list and an int n and returns the nth element of the list, where the head of the list is the 1st element. You are only allowed to use list functions hd and tl in your solution no other built-in functions are allowed. If the list is empty or n is invalid, return a tuple: {error, no_such_element} add the following test cases to the test file: getnth_1_test() -> {error, no_such_element} = lab05:getnth( [ ], 2). getnth_2_test() -> {error, no_such_element} = lab05:getnth( ["hello", "there"], 3). getnth_3_test() -> {error, no_such_element} = lab05:getnth( ["hello", "there"], 0). getnth_4_test() -> "there" = lab05:getnth( ["hello", "there"], 2). getnth_5_test() -> "there" = lab05:getnth( ["hello", "there", "where"], 2). getnth_6_test() -> "where" = lab05:getnth( ["hello", "there", "where"], 3). getnth_7_test() -> "where" = lab05:getnth( ["hello", "there", "where", "here"], 3). 9. Function repeat that takes a list of integers and a list of nonnegative integers and returns a list that repeats the integers in the first list according to the numbers indicated by the second list; add the following test cases to the test file these test files also illustrate the logic of repetition to be followed repeat_1_test() -> [2, 2, 2, 2, 3] = lab05:repeat([1, 2, 3], [0, 4, 1]). repeat_2_test() -> [ ] = lab05:repeat( [ ], [0, 4, 1]). repeat_3_test() -> [ ] = lab05:repeat( [1, 2, 3], [ ]). repeat_4_test() -> [4,4] = lab05:repeat( [4,5,6], [2]). The test file

image text in transcribed

money 1 test() > PassertEqual({8, 30), labes:money({3, 20}, {5, 10})). money_2_test() > PassertEqual({9, }, labes:money({3, 20}, {5, 80})). money_3_test() -> PassertEqual({9, 98}, labe5 money({3, 99}, {5, 99})). isolder_1_test() -> false = labes: isolder({10, 3, 2016}, {10, 3, 2016}). isolder_2_test() => Tabe5: isolder({10, 3, 2016}, {11, 3, 2016}). true = isolder_3_test() -> true = labos: isolder([10, 1, 2016}, {10, 2, 2016}). isolder_4_test() => false = labos: isolder({10, 3, 2016}, {11, 2, 2016}). isolder_5_test() -> true = lab05:isolder({10, 12, 2015}, 10, 12, 2016}). isolder_6_test() -> true = Labo5: isolder({11, 12, 2015}, {10, 12, 2016}). isolder_7_testo -> true labo5 isolder({12, 11, 2016}, {12, 10, 2017}). isolder_8_testo -> true = labos:isolder({12, 10, 2016}, {11, 3, 2017]). findCeil_1_test() -> [] = lab05:findceiling(1) findCeil_2_testo -> [2.0, 3.0, 4.0, -1.9] = labo:findCeiling([1.9, 2.1, 3.5, -1.3] findceil_3_testo -> [2.0] = lab05:FindCeiling(12]). findcell_4_test() > [2.0, 3.0, 4.0) Lab05findceiling 12. 2.4, 3.3]). money 1 test() > PassertEqual({8, 30), labes:money({3, 20}, {5, 10})). money_2_test() > PassertEqual({9, }, labes:money({3, 20}, {5, 80})). money_3_test() -> PassertEqual({9, 98}, labe5 money({3, 99}, {5, 99})). isolder_1_test() -> false = labes: isolder({10, 3, 2016}, {10, 3, 2016}). isolder_2_test() => Tabe5: isolder({10, 3, 2016}, {11, 3, 2016}). true = isolder_3_test() -> true = labos: isolder([10, 1, 2016}, {10, 2, 2016}). isolder_4_test() => false = labos: isolder({10, 3, 2016}, {11, 2, 2016}). isolder_5_test() -> true = lab05:isolder({10, 12, 2015}, 10, 12, 2016}). isolder_6_test() -> true = Labo5: isolder({11, 12, 2015}, {10, 12, 2016}). isolder_7_testo -> true labo5 isolder({12, 11, 2016}, {12, 10, 2017}). isolder_8_testo -> true = labos:isolder({12, 10, 2016}, {11, 3, 2017]). findCeil_1_test() -> [] = lab05:findceiling(1) findCeil_2_testo -> [2.0, 3.0, 4.0, -1.9] = labo:findCeiling([1.9, 2.1, 3.5, -1.3] findceil_3_testo -> [2.0] = lab05:FindCeiling(12]). findcell_4_test() > [2.0, 3.0, 4.0) Lab05findceiling 12. 2.4, 3.3])

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_2

Step: 3

blur-text-image_3

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

(9) What am I doing to develop the poor performers?

Answered: 1 week ago