Create a ruby script that defines a function

Assignment Help C/C++ Programming
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.

Verified Expert

In this assignment ruby scripts are written for 5 problems. In problem 1, using ruby script the number of occurrences of the number in the list is written. In problem 2 the number of items that are less than the given value is returned. In problem 3 second smallest number in the list is returned. In problem 4 Selection sort program is implemented with both mutable and immutable version. In problem 5 various list operation such as insertion, deletion and traversal on the list is implemented.

Reference no: EM131295386

Questions Cloud

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.

Reviews

Write a Review

 

C/C++ Programming Questions & Answers

  Limitations of digital subscriber line

Part 1: What are some limitations of Digital subscriber line (DSL) technology? Part 2: What are some examples of improvements of asymmetric digital subscriber line 2 (ADSL2) beyond regular DSL?

  Prepare a c program that has this description

n is an integer, >= 0. x points to the first element of an int array with n position. p points to the first element of another int array array, also with n position.

  File extension of the stock details file

Which class of the .NET Framework should Hayley use to enable Sharon to view the file extension of the stock details file? Describe any four properties of the selected class.

  Implement a standard sorted linked list class

Write C++ Program:Implement a standard SORTED linked list class. Be sure to include constructor/copy constructor, destructor, and assignment operator overload.

  For this program reads the first 11 characters

E main for this program reads the first 11 characters from input, saving them. It then reads 26 short integers into |vals|, and passes them and the characters to EmbedWatermark, which subtly alters the contents of vals to contain the characters. A..

  Using songs.dat in our folder

Using songs.dat in our folder on the P: drive, construct a playlist of 10 random songs. Use a struct to hold the song data (name and time in seconds), and output the playlist (song name and time,

  Create a program that reads in two integers

Create a program that reads in two integers and then has a pointer point to the first variable and then to the second variable.

  Describe floyd''s algorithm finds the shortest paths

A shortest path between vertex a and b is a path with the minimum sum of weights of the edges on the path. Floyd's algorithm finds the shortest paths of all vertex pairs of a graph.

  Write program that takes number show number in power of 3

Write a program that takes a number between -121 and 121 and output that number in the format of power of 3 (1,3,9,27)

  Skills required by personnel working in information security

What skills are required by personnel working in information security? Write down some job titles in the field and come up with some required qualifications and some desirable qualifications.

  Deadlock recovery system for transactions

Assume you are responsible for architecting a deadlock recovery system for transactions. In the case that there is some dependency cycle that has produced a deadlock with n >= 2 transactions, how will your recovery system determine which transacti..

  Which pieces of information can be found in the ip header

There are eight network security questions. I have answered the questions however, I am unclear if I am correct. Please review and if I am wrong, please provide the correct answer along with your explanation.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd