Reference no: EM131295386
Programming Assignment: Getting your feet wet with Ruby
Overview
The key to working with Ruby is understanding the underlying protocol for the different data types. You will experience this in this assignment by implementing a set of functions that add additional functions for the array data type in Ruby. Note that you will need to write additional helper functions for each of these problems and that you should take advantage of predefined methods instead of trying to implement these functions by hand.
Problem 1
Create a Ruby script that defines a function occurrences(list,key) that takes an array list and object key and returns the number of elements in list that are equal to key. Include sufficient test code to test your program (either by hand or using Ruby's unit test framework).
Problem 2
Create a Ruby script that defines a function numSmaller(list,item) that takes an array list of size 1 or larger and integer item as parameters. It should return the number of elements in the list that are strictly less than item. Again, include sufficient test code for your solution.
Problem 3
Crate a Ruby script that defines a funciton secondSmallest(list) that takes an array and returns the position of the second smallest element in the list. In case the smallest entry occurs more than once, the second occurrance of the item would be considered the second smallest entry. For example, in the list [1,1,1,2,3] , the position returned would be 1.
Problem 4
Implement Selection Sort for Ruby arrays. Make certain to include both mutable and immutable versions of the sorting function (i.e. if you are using ssort for your function name, then you should implement a ssort!(list) and sort(list) versions of the functions.
Problem 5
A list can be recursively defined as: the empty list () a pair (value rest), where value is some value (which may be another list), and a list rest that is the rest of the list.
Define a class List in Ruby that implements this definition. Your class needs to provide three methods: (1) insert which inserts a value into a list, (2) delete which removes a value from the list, and (3) traverse which traverses and prints the values in a list.
Notes:
Use a Ruby arrays as your backing store for the list. Note that value can be any valid type in Ruby, including being another List. Remember that recursion is your friend.
Identify the forced and natural components in the output
: The circuit in Figure is in the zero state when the input vS (t) = 150u (t) is applied. If C = 0.022 μF and R = 82 kΩ, find vO(t) for t ≥ 0.- Identify the forced and natural components in the output.
|
How statistics be misleading to a decision-maker
: Why has risk modeling become pervasive in the security management professions? Why do you believe that MSRAM has become a favored Risk Management tool? Just because it was first?
|
Calculate the time value of money problems
: Calculate the following time value of money problems. What is the future value of 24 periodic payments of $4,620 each made at the beginning of each period and compounded at 8% per period? What would you pay for a $200,000 face value bond that matures..
|
Employment relationship from union member rights
: Describe the benefits have nonunion employees have gained in their employment relationship from union member rights?
|
Create a ruby script that defines a function
: Create a Ruby script that defines a function occurrences(list,key) that takes an array list and object key and returns the number of elements in list that are equal to key - Create a Ruby script that defines a function numSmaller(list,item) that t..
|
Find the devices capacitance
: The device undergoes a constant current discharge of iD = 3 mA.- After 1 hour, the voltage remaining on the capacitor is 3 V. Find the device's capacitance.
|
Female assistant manager
: Review "Clippings" on pages 607-608 of your textbook about the McDonald's strip search incident. Imagine a scenario that is not quite as egregious as the one referenced. Instead, imagine that a female assistant manager performed the same cavity se..
|
Explain how the attitude-rationalization condition
: Research the Bernie Madoff ponzi scheme case. Explain how the “attitude/rationalization” condition of the fraud triangle is incorporated into the scheme. What do you think are some of the challenges currently facing the public accounting profession?
|
Write a summary of a business or company
: Write a summary of a business or company i.e. related to the Chase Bank.
|