You are on page 1of 2

IME 624A: Computer Aided Decision Systems Assignment 2 Anirban Banerjee (15214261)

<html>
<head><title>FLAMES CALCULATOR</title></head>
<body>
<form action="" method="post">
<table width="30%" height="204" border="0" align="center" cellpadding="0" cellspacing="0"
style="background:#D2A5FF;">
<tr><th scope="col" colspan="2" bgcolor="#02323F" style="background: #02323F; color:
#FCFADF;">Flames Calculator</th></tr>
<tr align="center"><th scope="row">Enter Name 1</th><td><input type="text" name="name1"
autocomplete="off" style="padding:8px 0;width:200"></td></tr>
<tr align="center"><th scope="row">Enter Name 2</th><td><input type="text" name="name2"
autocomplete="off" style="padding:8px 0;width:200"></td></tr>
<tr><td align="right"><input type="submit" name="submit" value="Submit"><input type="hidden"
name="refresh" value=""></td><td align="left"><input type="submit" name="refresh" value="Refresh"
style="margin-left: 10px;"></td></tr>
</table>
</form>
</body>
</html>
<?php
$msg="";
if($_POST['refresh']=='Refresh'){$msg = NULL; $_POST['name1'] = NULL; $_POST['name2'] = NULL; }
if (isset($_POST['name1']) && isset($_POST['name2'])){
$name1 = $_POST['name1']; $name2 = $_POST['name2'];
if(isset($name1) && isset($name2)){
if($name1 == $name2){$msg="Both are same names";exit;}
else {
$flames = array('f','l','a','m','e','s');
for($i = 0; $i < strlen($name1); $i++){
for($j = 0; $j < strlen($name2); $j++)
if($name1[$i] == $name2[$j]){$name1[$i] = $name2[$j] = '#';break;}
}
$name1 = str_replace("#", "", $name1);
$name2 = str_replace("#", "", $name2);
$count = strlen($name1) + strlen($name2);
$flame = "flames";
while(strlen($flame)!= 1) {
$diff = $count%strlen($flame);
if($diff == 0) $diff=strlen($flame)-1;
else $diff--;
$flame[$diff] = "@";
list($f1,$f2)= preg_split("/@/",$flame);
$flame=$f2.$f1;
}
switch($flame){
case 'f': $msg = $_POST['name1'].'&nbsp;and&nbsp;'.$_POST['name2'].'&nbsp;are Friends.';break;
case 'l': $msg = $_POST['name1'].'&nbsp;and&nbsp;'.$_POST['name2'].'&nbsp;are Lovers.';break;
case 'a': $msg = $_POST['name1'].'&nbsp;and&nbsp;'.$_POST['name2'].'&nbsp;are Ancestors.';break;
case 'm': $msg = $_POST['name1'].'&nbsp;and&nbsp;'.$_POST['name2'].'&nbsp;are Married.';break;
case 'e': $msg = $_POST['name1'].'&nbsp;and&nbsp;'.$_POST['name2'].'&nbsp;are Enemy.';break;
case 's': $msg = $_POST['name1'].'&nbsp;and&nbsp;'.$_POST['name2'].'&nbsp;are Siblings.';break;
}
}
}echo '<table width="30%" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td><h2 style="text-
align: center;">'.$msg.'</h2></td></tr></table>';
}
?>
Challenges Encountered while developing the codes:
IME 624A: Computer Aided Decision Systems Assignment 2 Anirban Banerjee (15214261)
1. When the page is loaded first time, unset PHP variables shows error. Need to pre-assign unset variables with
NULL values without affecting the logic. Eg: Refresh HTML variable needs to be set all time using a hidden
input type variable.
2.