Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions ImperialDroid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<!Doctype html>
<html>
<head>
<title>ImperialDroid</title>
</head>
<body>
<h1><center>Imperialdroid Assignment</center></h1>
<?php
class ImperialDroid{

private $IDNumber;
private $droidType;
private $height;
private $weight;
private $manufacturer;

public static $droidClass = "Security";

function __construct($IDNumber,$droidType,$height,$weight,$manufacturer){
$this->IDNumber = $IDNumber;
$this->droidType = $droidType;
$this->height = $height;
$this->weight = $weight;
$this->manufacturer = $manufacturer;
}

function get_IDNumber(){
return $this->IDNumber;
}

function set_IDNumber($ID){
$this->IDNumber = $ID;
}

function get_droidType(){
return $this->droidType;
}

function set_droidType($dT){
$this->droidType = $dT;
}

function get_height(){
return $this->height;
}

function set_height($h){
$this->height = $h;
}

function get_weight(){
return $this->weight;
}

function set_weight($w){
$this->weight = $w;
}

function get_manufacturer(){
return $this->manufacturer;
}

function set_manufacturer($m){
$this->manufacturer = $m;
}

function reportStatus(){
echo "I am Imperial Droid ".$this->IDNumber." and all systems are functioning";
}

function movesToDestination($destination){
echo $this->IDNumber." moving to"."$destination";
}

function communicates($msg){
echo $msg;
}

function flysTransport(){
echo $this->IDNumber." flying Transport";
}

public static function compareDroids($d1,$d2){
$d= "";
if(strcmp($d1->get_IDNumber(),$d2->get_IDNumber())==0){
$d = $d1->get_IDNumber()." and ".$d2->get_IDNumber()." are the same";
}
else{
$d = $d1->get_IDNumber()." and ".$d2->get_IDNumber()." are different";
}
return $d;
}


}

$DR1= new ImperialDroid("ImperialDroid1",76,230,25,3);
$DR2= new ImperialDroid("ImperialDroid2",75,220,22,4);
echo"<h2>ID number: ".$DR1 -> get_IDNumber()."</h2>";
echo"<h2>ID number: ".$DR2 -> get_IDNumber()."</h2>";
echo"<h1>What can the ImperialDroid do?</h1>";
echo"<h3>".$DR1 -> reportStatus()."</h3>";
echo"<h3>".$DR1 -> movesToDestination(" Jersey City ")."</h3>";
echo"<h3>".$DR2 -> communicates(" Reporting to the duty")."</h3>";
echo"<h3>".$DR2 -> flysTransport()."</h3>";
echo"<h3>".ImperialDroid::compareDroids($DR1,$DR2)."</h3>";

?>
</body>
</html>
194 changes: 191 additions & 3 deletions PreetiLadwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,201 @@
</head>
<body>

<h1>This is my Assignment 1</h1>
<h1><center><i>This is my Assignment 1</i></center></h1>
<h2>Function for sumAll</h1>
<?php
$a=array(5,15,25);
echo array_sum($a);
$array=array(1,2,3,4,5);
echo array_sum($array);
?>

<h2>Function to count even number in an Array</h1>
<?php
function even($nums)
{
$evens = 0;

for ($i = 0; $i < sizeof($nums); $i++)
{
if ($nums[$i] % 2 == 0) $evens++;
}
return $evens;
}
echo "Number of even elements in an array: ". even([1,2,3,4,5,6,7,8,9,10] );
?>

<h2>Function to count odd number in an Array</h1>
<?php
function odd($nums)
{
$odds = 0;
for ($i = 0; $i < sizeof($nums); $i++)
{
if ($nums[$i] % 2 !== 0) $odds++;
}
return $odds;
}
echo "Number of odd elements in an array: ". even([1,2,3,4,5,6,7,8,9,10]);
?>

<h2>Function to count average number in an Array</h1>
<?php
function average($array) {
return array_sum($array) / count($array);
}
echo "Number of average elements in an array: ". average([1,2,3,4,5,6,7,8,9,10]);
?>

<h2>Function that accepts an array of numbers and returns the smallest number</h1>
<?php
echo "Number of average elements in an array: ". min([1,2,3,4,5,6,7,8,9,10]);
?>

<h2>Function that accepts an array of numbers and returns the largest number</h1>
<?php
echo "Number of average elements in an array: ". max([1,2,3,4,5,6,7,8,9,10]);
?>

<h2>Function that accepts an array of numbers and returns the range between the numbers</h1>
<?php
$arr = range(1,10);
foreach ($arr as $a) {
echo "\t". "$a";
}
?>

<h2>Function that accepts an array of numbers and returns the median of the numbers</h1>
<?php
function findMedian(&$a, $n)
{
sort($a);
if($n%2 != 0)
return (double)$a[$n / 2];
return (double)($a[($n - 1) / 2] + $a[$n / 2]) / 2.0;
}
$a = array(1, 4, 3, 9, 12, 3, 10);
$n = sizeof($a);
echo "Median = " . findMedian($a, $n);
?>

<h2>Function that accepts an array of numbers and returns the mean of the numbers</h1>
<?php
function findMean(&$a, $n)
{
$sum = 0;
for ($i = 0; $i < $n; $i++)
$sum += $a[$i];
return (double)$sum/(double)$n;
}
$a = array(1, 4, 3, 9, 12, 3, 10);
$n = sizeof($a);
echo "Mean = " . findMean($a, $n);
?>

<h2>Function that accepts an array of numbers and returns the mode of the numbers</h1>
<?php
function modes_of_array($arr) {
$values = array();
foreach ($arr as $v) {
if (isset($values[$v])) {
$values[$v] ++;
} else {
$values[$v] = 1;
}
}
arsort($values);
$modes = array();
$x = $values[key($values)];
reset($values);
foreach ($values as $key => $v) {
if ($v == $x) {
$modes[] = $key;
} else {
break;
}
}
return $modes;
}
print_r(modes_of_array([1.0, 1.0, 2.0, 2.0, 3, 4]));
?>

<h2>Function that accepts an array of numbers and returns the sample Variation of the numbers</h2>
<?php
function variance_sample ($a)
{
$the_variance = 0.0;
$the_mean = 0.0;
$the_array_sum = array_sum($a);
$number_elements = count($a);
$the_mean = $the_array_sum / $number_elements;
for ($i = 0; $i < $number_elements; $i++)
{
$the_variance = $the_variance + ($a[$i] - $the_mean) * ($a[$i] - $the_mean);
}
$sample_variance = $the_variance / ($number_elements - 1.0);
return $sample_variance;
}
$a = array(0, 1, 2, 3, 4, 5);
$the_variance = variance_sample ($a);
echo "a[0] = $a[0]<br>";
echo "a[1] = $a[1]<br>";
echo "a[2] = $a[2]<br>";
echo "a[3] = $a[3]<br>";
echo "a[4] = $a[4]<br>";
echo "a[5] = $a[5]<br>";
echo "the_sample_variance = $the_variance<br>";
?>

<h2>Function that accepts an array of numbers and returns the standard deviation of the numbers</h2>
<?php
function Stand_Deviation($arr)
{
$num_of_elements = count($arr);
$variance = 0.0;
$average = array_sum($arr)/$num_of_elements;
foreach($arr as $i)
{
$variance += pow(($i - $average), 2);
}
return (float)sqrt($variance/$num_of_elements);
}
$arr = array(2, 3, 5, 6, 7);
print_r(Stand_Deviation($arr));
?>

<h2>Euclidean 2D distance function </h2>
<?php
function eucDistance(array $x, array $y) {
return
array_sum(
array_map(
function($c, $d) {
return ($c - $d) ** 2;
}, $x, $y
)
) ** (1/2);
}
echo eucDistance([2,5], [6,33]);
?>

<h2>Interquartile range function</h2>
<?php
function median($a, $l, $r)
{
$n = $r - $l + 1;
$m = (int)(($n + 1) / 2) - 1;
return $m + $l;
}
function IQR($a, $m)
{
sort($a);
$mid_index = median($a, 0, $m);
$Q1 = $a[median($a, 0, $mid_index)];
$Q3 = $a[$mid_index + median($a, $mid_index + 1, $m)];
return ($Q3 - $Q1);
}
$a = array( 1, 19, 7, 6, 5, 9, 17);
echo IQR($a, $m);

?>
</body>
</html>
Binary file added PreetiLadwaAssignment2.zip
Binary file not shown.
31 changes: 31 additions & 0 deletions PreetiLadwaAssignment2/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>Assignment 03</title>
</head>

<body>

<h1>Enter a list of five number</h1>
<form method="post" action="results.php">

<label for="num1">First Number</label><br>
<input type="number" id="num1" name="num1"><br>

<label for="num2">Second Number:</label><br>
<input type="number" id="num2" name="num2"><br>

<label for="num3">Third Number:</label><br>
<input type="number" id="num3" name="num3"><br>

<label for="num4">Fourth Number:</label><br>
<input type="number" id="num4" name="num4"><br>

<label for="num5">Fifth Number:</label><br>
<input type="number" id="num5" name="num5"><br>

<input type="submit" value="Submit"/>

</form>
</body>
</html>
Loading