- voltage.rb (demonstration)
- circle_area.rb (demonstration)
- answers.txt
- cone_vol.rb
- my_func.rb (time permitting)

Place these files in a `lab2` folder. Before leaving lab,
zip up this folder,
and hand it in.

- creating a lab2 directory
- Set up the .irbrc file and RubyLabs:

> /afs/cs/academic/class/15110-f12/bin/setup-rubylabs.sh - starting
`irb`within a terminal window - creating and using functions:
`voltage(i,r)`to calculate \(V = IR\)- using gedit to define a function in
`voltage.rb` - loading
`voltage.rb`files from irb `voltage`'s parameters and return values

- using gedit to define a function in
- math constants and print:
`circle_area(r)`to calculate \(A = \pi r^2 \)- Math.sqrt(x) and Math::PI
- returning a value from circle_area(r)
- using the return value
- printing a value instead of returning

Type each of the following expressions into

`irb`. What value do each of the following Ruby expressions evaluate to? Is that value an integer or a floating point?`100``29 % 4``2.5e2``3e5``3 * 10**5``15 + 35 * 2`

*Why is this different from*`(15 + 35) * 2`?`3 / 2 * 4.0``2 * 4.0 / 3`

*Why is this different from*`3 / 2 * 4.0`?`24 - 6 * 2 - 9`

*Is this different from*`((24 - 6) * 2) - 9`and/or`24 - ((6 * 2) - 9)`? Why?

Write your answers in the file

`answers.txt`. (Review Unit 2A lecture slides if necessary.)In

\[ V = \frac{1}{3}\pi r^2h\]`cone_vol.rb`, define a Ruby function`cone_vol(r,h)`that calculates and**returns**the volume of a cone with a radius`r`and height`h`. This can be calculated using the formula:Place in

`answers.txt`a copy of irb lines in which you call cone_vol(r,h) to compute the volume of cone with a radius and height of, respectively, 5 and 10, and irb shows you the result.Pick a mathematical formula that is used in your major. In a file called

`my_func.rb`, create a Ruby function that calculates some value using that formula.At the beginning of your

`my_func.rb`include a comment (one or more lines of English text that start with "#" and are ignored by`irb`) that describes the fomula the function computes and what units the parameters and results are in.