Assignment Instructions 1) Create a file called arrayDemo.html. This file should
ID: 3743376 • Letter: A
Question
Assignment Instructions 1) Create a file called arrayDemo.html. This file should contain a form that has both a reset button and submit button. You should have inputs for: number of rows, number of columns, min random value, and max random value. These values should be passed to the file you must create in step 2 Create a file called arrayDemo.php This file should have php code embedded inside of html code such that the server will return an 2) 3) lly created) to the browser (client). 4) Your php code should do the following a. Fll a 2D array with the correct number of rows and columns (from part 1) between the values specified in part 1. Print the values of the array in a Table Process the data in the array in the following manner. Create a 2nd table and print the following information. Make sure to label data with proper column headers: b. c. i. The sum of each row of data ii. The average of the each row of data The standard deviation of each row of data (https://www.mathsisfun.com/data/standard-deviation-formulas.html) Process the data in the following manner. Create a 3re table and print the following information. For a given row of data, print 2 rows in your table d. i. In the first row print the original value from your 2D array ii. In the following row, print the string "positive" if the value is>0, or the string "negative" if the element isExplanation / Answer
ArrayDemo.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="arrayDemo.php" method="POST">
<p>Number of Rows: <input type="text" name="rows" /></p>
<p>Number of Columns: <input type="text" name="columns" /></p>
<p>Min random number: <input type="text" name="min_rand" /></p>
<p>Max random number: <input type="text" name="max_rand" /></p>
<p><input type="submit" value="Submit" />
<input type="reset" value="Reset" /></p>
</form>
</body>
</html>
arrayDemo.php
<?php
if(isset($_POST['rows']) && isset($_POST['columns']) && isset($_POST['min_rand']) && isset($_POST['max_rand'])){
$rows = $_POST['rows'];
$columns = $_POST['columns'];
$min_rand = $_POST['min_rand'];
$max_rand = $_POST['max_rand'];
echo "<h1>Your Array<h1>";
echo "<div>Your array size is: $rows x $columns</div>";
echo "<div>Your min. value is: $min_rand</div>";
echo "<div>Your max. value is: $max_rand</div>";
$arr = array();
for($i=0; $i<$rows; $i++){
$arr[$i] = array();
for($j=0; $j<$columns; $j++){
array_push($arr[$i], rand($min_rand, $max_rand));
}
}
echo "<table border='1px'>";
for($i=0; $i<$rows; $i++){
echo "<tr>";
for($j=0; $j<$columns; $j++){
echo "<td>$arr[$i][$j]</td>";
}
echo "</tr>";
}
echo "</table>";
echo "<table border='1px'";
echo "<tr><th>Row</th><th>Sum</th><th>Avg</th><th>Std Dev</th></tr>";
for($i=0; $i<$rows; $i++){
$sum = 0;
$avg = 0;
$stdDev = 0;
for($j=0; $j<$columns; $j++){
$sum += $arr[$i][$j];
}
$avg = $sum/$columns;
for($j=0; $j<$columns; $j++){
$stdDev += ($arr[$i][$j]-$avg)*($arr[$i][$j]-$avg);
}
$stdDev /= ($columns-1);
$stdDev = sqrt($stdDev);
echo "<tr><td>$i</td><td>$sum</td><td>".number_format($avg, 3)."</td><td>".number_format($stdDev, 3)."</td></tr>";
}
echo "</table>";
echo "<table border='1px'>";
for($i=0; $i<$rows; $i++){
echo "<tr>";
for($j=0; $j<$columns; $j++){
echo "<td>$arr[$i][$j]</td>";
}
echo "</tr>";
echo "<tr>";
for($j=0; $j<$columns; $j++){
echo "<td>";
if($arr[$i][$j]==0)
echo "zero";
else if($arr[$i][$j]<0)
echo "negative";
else
echo "positive";
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
echo "<a href="./arrayDemo.html">Click here to return</a>"
}
else{
header("Location: arrayDemo.html");
}
?>
Let me know if you have any clarifications. Thank you...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.