All pastes #1945934 Raw Edit

Unnamed

public text v1 · immutable
#1945934 ·published 2010-09-21 16:53 UTC
rendered paste body
<html>
    <head>
        <title>SET OF OPERATIONS</title>
     </head>
     <body>
	    <form method=POST>
        <?php
			 echo '<h1 align="center">SET OF OPERATIONS</h1>';
		     echo '<b>Crated by:</b><br>';
			 			 echo '<b>Mark Lasco</b><br>';
			 echo '<b>Renzi Vidal</b><br>';
		     echo '<font align="left">REMINDER: In inputting sets, pls. use comma after a
                             number except the last number!</font><br><br>';

		     echo '<input type="text" name="set1" maxlength="30">'.'&nbsp;&nbsp;'.
			                 '<b>SET A</b><br>';
			 echo '<input type="text" name="set2" maxlength="30">'.'&nbsp;&nbsp;'.
			                 '<b>SET B</b><br>';
		     echo '<input type="text" name="set3" maxlength="60">'.'&nbsp;&nbsp;'.
			                 '<b>UNIVERSAL SET </b><br><br>';
		?>
		     <input type="submit" value="process"><br>
			     <?php
				     error_reporting(0);
						 //POST DECLARATIONS
					     $a=$_POST["set1"];
						 $b=$_POST["set2"];
						 $c=$_POST["set3"];
						     //spliting commas/separators
							 $split_1=$a;
							 $split_a=explode(",", $split_1);
							 $split_2=$b;
							 $split_b=explode(",", $split_2);
							 $split_3=$c;
							 $split_c=explode(",", $split_3);
								     //unique characters
							         $unique_a=array_unique($split_a);
								     $unique_b=array_unique($split_b);
								     $unique_c=array_unique($split_c);
									     //sort sets
										 sort($unique_a);
										 sort($unique_b);
										 sort($unique_c);
										     //merge set a and b
											 function array_union($unique_a,$unique_b){
							                 return;
											 }
											 //containers
										     $seta=$unique_a;
											 $setb=$unique_b;
											 $setc=$unique_c;

										     //operations
											 $union=array_merge($seta,$setb);
											 $union=array_unique($union);
											 $new=array_unique($setc);
											 //control operator for validity
											if($union==$new){

												 //operations
												 $inter=array_intersect($seta,$setb);
												 $comp1=array_diff($new,$seta);
												 $comp2=array_diff($new,$setb);
												 $diff1=array_diff($seta,$setb);
												 $diff2=array_diff($setb,$seta);

												 //implodes
												 $op_1= implode (',' ,$union);
												 $op_2= implode (',' ,$inter);
												 $op_3= implode (',' ,$comp1);
												 $op_4= implode (',' ,$comp2);
												 $op_5=implode (',' ,$diff1);
												 $op_6=implode(',' ,$diff2);

												 //counts
												 $count_a=count($seta);
												 $count_b=count($setb);
												 $count_c=count($union);
												 $count_d=count($inter);
												 $count_e=count($comp1);
												 $count_f=count($comp2);
												 $count_g=count($diff1);
												 $count_h=count($diff2);

												 //outputs
												 //basic set operations

												 echo '<br><b align="left">BASIC SET OPERATIONS:</b><br>';
												 echo '<br><b>UNION OF A & B: </b>'.'{'.$op_1.'}'.'<br>';
												 if($op_2==0){
											         echo '<br><b>INTERSECTION OF A & B:
															     </b><font>{0}</font>'.$op_2.'<br>';
												 }
												 else {
													 echo '<br><b>INTERSECTION OF A & B: </b>'.'{'.$op_2.
																     '}'.'<br>';
												 }
												 echo '<br><b>COMPLEMENT OF A: </b>'.'{'.$op_3.'}'.'<br>';
												 echo '<br><b>COMPLEMENT OF B: </b>'.'{'.$op_4.'}'.'<br>';
												 echo '<br><b>A - B: </b>'.'{'.$op_5.'}'.'<br>';
												 echo '<br><b>B - A: </b>'.'{'.$op_6.'}'.'<br>';
												//counts
												 echo  '<br><br><b align="left">COUNTS:</b><br>';
												 echo '<br><b>| A |: </b>'.$count_a.'<br>';
												 echo '<br><b>| B |: </b>'.$count_b.'<br>';
												 echo '<br><b>| A UNION B |: </b>'.$count_c.'<br>';
												 echo '<br><b>| INTERSECTION OF A & B |: </b>'.$count_d.'<br>';
												 echo '<br><b>| COMPLEMENT OF A |: </b>'.$count_e.'<br>';
												 echo '<br><b>| COMPLEMENT OF B |: </b>'.$count_f.'<br>';
												 echo '<br><b>| A - B |: </b>'.$count_g.'<br>';
												 echo '<br><b>| B - A |: </b>'.$count_h.'<br>';
											}
											//end of control operator for validity
											else {
												echo '<br><b>INVALID UNIVERSAL SET!</b>';
									         }
				?>
		</form>
	</body>
</html>