Lab 0: Quadratic Equations ========================== Anthony Stark (1160611) This lab report was developed for the _Software Design and Architecture_ course (_Tc3003_), at the Tecnológico de Monterrey, Campus Estado de México. // The institution's name should always be in Spanish. :numbered: == Introduction The roots of a quadratic equation _ax_^2^ + _bx_ + _c_ = 0 can be computed using the quadratic formula, which is something you typically learn in high school: ************************************************************************ _x_ = (−__b__ ± sqrt(__b__^2^ − 4__ac__)) ÷ 2__a__ ************************************************************************ [NOTE] .INTERESTING NOTE ================================================================================ The quadratic formula is known in Mexico as ``el chicharronero'', because even the guy who sells _chicharrones_ (pork cracklings) knows how to use it. ================================================================================ In this lab report, I will demonstrate how to determine the number of real roots of a quadratic equation in the Ruby programming language <>. Section 2 consists of the code, section 3 discusses my testing, and lastly there are some concluding remarks. == Number of Real Roots of a Quadratic Equation In this part of the lab, I designed a function to compute how many real roots a quadratic equation has. This can be determined by computing the discriminant of the equation and then testing that discriminant <>. I broke the problem into those two parts: [source,ruby] --------------------------------------------------------- # How many real roots does ax^2+bx+c=0 have? def num_real_roots(a, b, c) num_real_roots_from_discriminant(discriminant(a, b, c)) end --------------------------------------------------------- The two auxiliary routines used by the above code straightforwardly reflect my memories from high school: [source,ruby] --------------------------------------- def discriminant(a, b, c) b ** 2 - 4 * a * c end def num_real_roots_from_discriminant(d) if d < 0 0 elsif d == 0 1 else 2 end end --------------------------------------- == Testing I tested the number of real-roots function using one simple example falling into each of the three cases. Note that I took care to use examples in which the three arguments were different from one another, to improve the chances of catching certain bugs. My function worked in all three cases, as shown below: [options="header", cols="2