2. Introduction
Ruby Basics
Puts
Gets
Some basic math operations
“+”, “-”, “*”, “/”
Formatting and Advanced Math
Line formatting (right/left justification, centering)
Exponents, roots, the Math Object
3. Agenda
Review the Assignment 3 solution
Add formatting
to make interface and output more attractive
To make interface more intuitive
To make output more functional
Advanced Math
Exponents and Roots
Absolute and Modulus
Math::pi and rand
4. Formatting
Example – our class average assignment
Preferred format/ line length of 60
Student Marks
Sam 75
Susan 78
George 87
Anne 92
Joe 67
_____ _____
Average 76.5
6. Ruby Math: Exponent and Root
Exponent
Notation a**b
a to the power of b
Example
Root
Using Math Object
Math.sqrt(val)
Using math formula
x**0.5
8. Ruby Math: Random & Pi
Random
Use: rand(max_val)
Result is zero based
Example
Math:Pi
Use Math::Pi*(val)
Example:Volume of a cylinder
IPO first?
9. Summary
Exponent (a**b)
Root (sqrt or a**b/c.to_f)
Absolute (abs)
Modulus (a%b)
Random (rand(x))
Pi (Math::PI)
10. Project 1: Calculator/Converter
Objectives
Apply mathematical formulas to real problems
Apply a programmatic approach to a solution
Apply basic ruby mathematical operations
Apply basic ruby formatting
Grading – in 3 parts
Due Date:Week of Nov 15
NextWeek: Part of class for project work,
problems, challenges, ideas