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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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