| 1 |
<html> |
| 2 |
<head> |
| 3 |
<title>Quadratic Equation Solver</title> |
| 4 |
</head> |
| 5 |
<body> |
| 6 |
<?php |
| 7 |
|
| 8 |
/** Error reporting **/ |
| 9 |
error_reporting(E_ALL); |
| 10 |
|
| 11 |
/** Include path **/ |
| 12 |
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../Classes/'); |
| 13 |
|
| 14 |
?> |
| 15 |
<h1>Quadratic Equation Solver</h1> |
| 16 |
<form action="Quadratic.php" method="POST"> |
| 17 |
Enter the coefficients for the Ax<sup>2</sup> + Bx + C = 0 |
| 18 |
<table border="0" cellpadding="0" cellspacing="0"> |
| 19 |
<tr><td><b>A </b></td> |
| 20 |
<td><input name="A" type="text" size="8" value="<?php echo (isset($_POST['A'])) ? htmlentities($_POST['A']) : ''; ?>"></td> |
| 21 |
</tr> |
| 22 |
<tr><td><b>B </b></td> |
| 23 |
<td><input name="B" type="text" size="8" value="<?php echo (isset($_POST['B'])) ? htmlentities($_POST['B']) : ''; ?>"></td> |
| 24 |
</tr> |
| 25 |
<tr><td><b>C </b></td> |
| 26 |
<td><input name="C" type="text" size="8" value="<?php echo (isset($_POST['C'])) ? htmlentities($_POST['C']) : ''; ?>"></td> |
| 27 |
</tr> |
| 28 |
</table> |
| 29 |
<input name="submit" type="submit" value="calculate"><br /> |
| 30 |
If A=0, the equation is not quadratic. |
| 31 |
</form> |
| 32 |
|
| 33 |
<?php |
| 34 |
/** If the user has submitted the form, then we need to execute a calculation **/ |
| 35 |
if (isset($_POST['submit'])) { |
| 36 |
if ($_POST['A'] == 0) { |
| 37 |
echo 'The equation is not quadratic'; |
| 38 |
} else { |
| 39 |
/** So we include PHPExcel to perform the calculations **/ |
| 40 |
include 'PHPExcel/IOFactory.php'; |
| 41 |
|
| 42 |
/** Load the quadratic equation solver worksheet into memory **/ |
| 43 |
$objPHPExcel = PHPExcel_IOFactory::load('./Quadratic.xlsx'); |
| 44 |
|
| 45 |
/** Set our A, B and C values **/ |
| 46 |
$objPHPExcel->getActiveSheet()->setCellValue('A1', $_POST['A']); |
| 47 |
$objPHPExcel->getActiveSheet()->setCellValue('B1', $_POST['B']); |
| 48 |
$objPHPExcel->getActiveSheet()->setCellValue('C1', $_POST['C']); |
| 49 |
|
| 50 |
|
| 51 |
/** Calculate and Display the results **/ |
| 52 |
echo '<hr /><b>Roots:</b><br />'; |
| 53 |
|
| 54 |
$callStartTime = microtime(true); |
| 55 |
echo $objPHPExcel->getActiveSheet()->getCell('B5')->getCalculatedValue().'<br />'; |
| 56 |
echo $objPHPExcel->getActiveSheet()->getCell('B6')->getCalculatedValue().'<br />'; |
| 57 |
$callEndTime = microtime(true); |
| 58 |
$callTime = $callEndTime - $callStartTime; |
| 59 |
|
| 60 |
echo '<hr />Call time for Quadratic Equation Solution was '.sprintf('%.4f',$callTime).' seconds<br /><hr />'; |
| 61 |
echo ' Peak memory usage: '.(memory_get_peak_usage(true) / 1024 / 1024).' MB<br />'; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
?> |
| 66 |
|
| 67 |
</body> |
| 68 |
<html> |
| 69 |
|