Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

Difficulty: 2/10

Date added: 21th of July 2008

In this exercise you must refactor a class that is given as an example in reference [1]. You will learn how to think to correctly refactor a class and that literature does not always set a good examples.

A quadratic equation is an equation in the form 'ax^{2} + bx + c = 0'.
For which x or x's is this true? The number of solutions this equation has is
determined by the discrimant: D = b^{2} - 4ac. If D is smaller then
zero, the equation has no solutions. If D equals zero, the solution to the
equation is x = -b/2a. If D is bigger then zero, the solutions are x =
(-b-sqrt(D)) / (2a) and x = (-b+sqrt(D)) / (2a).

Below of a piece of code (from [1]) demonstrating a class to solve a quadratic equation. Can you refactor this class to follow good class design, member function design, function design and good thinking?

```
#include <cmath>
``` |

View the answer of this exercise.

- Leen Ammeraal. C++ (6th edition). ISBN: 90-395-1935-8. 2001

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

This page has been created by the tool CodeToHtml