Web
Web
9) PATTERN MATCHING
1
SIMPLE CALCULATOR
<!DOCTYPE html>
<html>
<head>
<title>Program</title>
<script type="text/javascript">
function update(value){
document.getElementById("display").value+=value;
}
function result(){
document.getElementById("display").value=eval(document.getElement
ById("display").value);
}
function reset(){
document.getElementById("display").value=" ";
}
</script>
</head>
<body>
<h1>SimpleCalculator</h1>
<form name="my form">
<table border=2>
2
<tr>
<td align="center">
<input type="text" id="display"/><br/>
</td>
</tr>
<tr>
<td>
<input type="button" name="7" value="7" onclick="update(7)"/>
<input type="button" name="8" value="8" onclick="update(8)"/>
<input type="button" name="9" value="9" onclick="update(9)"/>
<input type="button" name="+" value="+" onclick="update('+')"/>
<br/>
<input type="button" name="4" value="4" onclick="update(4)"/>
<input type="button" name="5" value="5" onclick="update(5)"/>
<input type="button" name="6" value="6" onclick="update(6)"/>
<input type="button" name="-" value="-" onclick="update('-')"/>
<br/>
<input type="button" name="1" value="1" onclick="update(1)"/>
<input type="button" name="2" value="2" onclick="update(2)"/>
<input type="button" name="3" value="3" onclick="update(3)"/>
<input type="button" name="*" value="*" onclick="update('*')"/>
<br/>
<input type="button" name="c" value="c" onclick="reset();"/>
3
<input type="button" name="0" value="0" onclick="update(0)"/>
<input type="button" name="=" value="=" onclick="result();"/>
<input type="button" name="/" value="/" onclick="update('/')"/>
</td>
</tr>
</table>
</form>
</body>
</html>
4
SQUARES AND CUBES
<html>
<head>
<title>program</title>
</head>
<body>
<h1>program to print square and cubes number</h1>
<table align="left" border="2">
<tr><th>number</th>
<th>square</th>
<th>cube</th>
</tr>
<script>
for(var a=0;a<=10;a++)
{
document.write("<tr><td>"+a+"</td><td>"+a*a+"</td><td>"+a*a*a+"
</td></tr>");
}
</script>
</table>
</body>
</html>
5
VOWEL AND REVERSE OF NUMBER
<!DOCTYPE html>
<html>
<head>
<title>Program 4A</title>
<script>
function vow(st) {
var pos;
pos = st.search(/[aeiou]/i);
if(pos<0)
/*alert("pattern not found\n");*/
document.write("pattern not found");
else
document.write("Position of the left most vowel is
"+(pos+1));
}
</script>
</head>
<body>
<h1>Displaying Leftmost Vowel</h1>
<form>
6
<p>Enter the text</p>
<input type="text" id="voweltext" /> <br/> <br/>
<input type="button" value="Click here"
onclick="vow(voweltext.value);" />
</form>
</body>
</html>
REVERSE OF NUMBER
<!DOCTYPE html>
<html>
<head>
<title>Program4b</title>
<script>
function rev(n) {
7
count++;
}
while(count<len)
{
rev=rev*10;
count++;
}
/*document.write("The Reverse number is:",rev);*/
alert("The Reverse number is:"+rev);
}
</script>
</head>
<body>
<h2>Reversing Number</h2>
<form>
<p>Enter a Number</p>
<input type="number" name="num" />
<input type="button" value="Reverse"
onclick="rev(num.value)";>
</form>
</body>
</html>
8
XML TO STORE STUDENT INFORMATION
9
<student>
<usn> <span> USN: </span> 1VI09CS070 </usn>
<name> <span> Name : </span>PRINYANKA </name>
<college> <span> College : </span>VIT </college>
<branch> <span> Branch : </span> CSE </branch>
<yoj> <span> YOJ : </span> 2020 </yoj>
<email> <span> email: </span> [email protected] </email>
</student>
</vtu>
prg.css
student { display : block;
padding : 5px; margin : 40px; border-style : dashed;
}
h1 { display : block; color : black; font-size : 30px;
}
vtu { display : block;
border-style : solid;
}
usn,name,college,branch,yoj,email { display : block;
color : pink;
font-size : 20px;
10
}
span { color : blue;
font-size : 20px;
}
11
TEXT GROWING AND SHRINKING
<!DOCTYPE html>
<html>
<head>
<title>PROGRAM 3</title>
</head>
<body>
<p id="text"></p>
<script>
var myVar=setInterval(Growing,100);
var myVar1=0;
var i=0;
function Growing(){
i=i+1;
document.body.style.fontSize="5px";
document.getElementById("text").innerHTML='Text-
Growing';
document.body.style.fontSize=parseFloat(document.body.style.fon
tSize)+(i*1.0)+"px";
document.body.style.color='red';
if(document.body.style.fontSize=='50px')
{
12
clearInterval(myVar);
i=1;
myVar=setInterval(Shrinking,100);
}
}
function Shrinking(){
document.getElementById("text").innerHTML='Text-
Shrinking';
document.body.style.fontSize=parseFloat(document.body.style.fontSize)
-(i*1.0)+"px";
document.body.style.color='blue';
if(document.body.style.fontSize=='5px')
{
clearInterval(myVar1);
myVar=setInterval(Shrinking,100);
}
}
</script>
</body>
</html>
13
DIGITAL CLOCK
<!DOCTYPE html>
<html>
<head>
<title>Digital Clock </title>
</head>
<body>
<h1>Digital Clock</h1>
<h3>
<?php
date_default_timezone_set("Asia/Kolkata");
echo "the time from the server is " .date("h:i:s");
header("refresh:1");
?>
</h3>
</body>
</html>
14
NUMBER OF VISITORS
<?php
$file='count.txt';
$count=strval(file_get_contents($file));
file_put_contents($file,$count+1);
echo("you are visitor number : ".$count);
?>
15
8 A) SIMPLE CALCULATOR
<!DOCTYPE html>
<html>
<head>
<title>simple calculator</title>
</head>
<body>
<?php
if(isset($_POST['opr'])) {
$txt1=$_POST['n1'];
$txt2=$_POST['n2'];
$oprnd=$_POST['opr'];
if($oprnd == "+")
$res=$txt1 + $txt2;
else if($oprnd == "-")
$res=$txt1 - $txt2;
else if($oprnd == "x")
$res=$txt1 * $txt2;
else if($oprnd == "/")
$res=$txt1 / $txt2;
}
16
?>
<h3> Simple Calculator </h3> <br />
<form method="post" action="prg8a.php">
Enter Number:
<input type="number" name="n1" value="<?php echo $txt1; ?>" />
<br /> <br />
Enter Number2:
<input type="number" name="n2" value="<?php echo $txt2; ?>" />
<br /><br />
Result:
<input type="number" name="res" value="<?php echo $res; ?>" />
<br /> <br />
<input type="submit" name="opr" value="+">
<input type="submit" name="opr" value="-">
<input type="submit" name="opr" value="x">
<input type="submit" name="opr" value="/">
</form>
</body>
</html>
17
8 B) TRANSPOSE OF MATRIX
<?php
$matrix =
array( array(4,
1, 2),
array(6, 3, 4)
);
$rowCount= count($matrix); //Provides the row count of matrix
$colCount = count($matrix[0]); //Provides the column count of matrix
echo "The input matrix is:<br \>";
18
{ for($c=0; $c < $rowCount; $c++)
{
echo $matrix[$c][$r]."\t";
}
echo "<br \>";
}
?>
19
8 C) MULTIPLICATION OF MATRIX
<?php
$a = Array(Array(1,2),Array(4,5));
$b = Array(Array(1,1),Array(1,1));
echo "The input matrix A is:<br\>";
for($r = 0; $r < 2; $r++) {
for($c=0; $c < 2; $c++)
{ echo $a[$r][$c]."\t";
}
echo "<br \>";
}
20
for($j=0; $j<2; $j++) {
$res[$i][$j]=0;
for($k=0; $k<2; $k++) {
$res[$i][$j]=$res[$i][$j]+($a[$i][$k]*$b[$k][$j]);
}
}
}
echo "<br /><br /> Matrix multiplication A x B : <br/>";
for($r = 0; $r < 2; $r++)
{ for($c=0; $c < 2; $c++) {
echo $res[$r][$c]."\t";
}
echo "<br \>";
}
?>
21
8 D) ADDITION OF TWO MATRIX
<?php
$a = Array(Array(1,2),Array(4,5));
$b = Array(Array(1,2),Array(2,7));
echo "The input matrix A is:<br \>";
for($r = 0; $r < 2; $r++) {
for($c=0; $c < 2; $c++)
{
echo $a[$r][$c]."\t";
}
echo "<br \>";
}
echo "<br /> The input matrix B is:<br \>";
for($r = 0; $r < 2; $r++) {
for($c=0; $c < 2; $c++)
{ echo $b[$r][$c]."\t";
}
echo "<br \>";
}
echo "<br /> Addition of matrices A + B is:<br \>";
for($i=0; $i<2; $i++) {
22
for($j=0; $j<2; $j++) {
echo $a[$i][$j]+$b[$i][$j]."\t";
}
echo "<br \>";
}
?>
23
PATTERN MATCHING
<?php
$states = "Mississippi Alabama Texas Massachusetts Kansas";
$statesArray = [];
$states1 = explode(' ',$states);
foreach($states1 as $state)
{ if(preg_match( '/xas$/',
($state)))
$statesArray[0] = ($state);
}
foreach($states1 as $state)
{ if(preg_match('/^k.*s$/i',
($state)))
$statesArray[1] = ($state);
}
foreach($states1 as $state)
{ if(preg_match('/^M.*s$/',
($state)))
$statesArray[2] = ($state);
}
foreach($states1 as $state)
24
{ if(preg_match('/a$/',
($state)))
$statesArray[3] = ($state);
}
echo "The extracted states are as follows: <br /> <br />";
foreach ( $statesArray as $element => $value ){
print( "statesArray[$element] = $value <br />");
}
?>
25
SELECTION SORT
prg10.html
<!DOCTYPE html>
<html>
<head>
<title>Selection sort</title>
</head>
<body>
<h1>Student Entry Form</h1>
<form action="prg10.php" method="post">
<table>
<tr>
<td>Student Id</td><td><input type="number" name="id" /></td>
</tr>
<tr>
<td>Name</td><td><input type="text" name="name" /></td>
</tr>
<tr>
<td>Age</td><td><input type="number" name="age" /></td>
</tr>
26
<tr>
<td>Mobile Number</td><td><input type="number" name="mob"
/></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Register" /></td>
<td><input type="reset" name="reset" value="Clear" /></td>
</tr>
</table>
</form>
</body>
</html>
prg10.php
<?php
$db=mysql_connect("localhost", "root", "") or error(mysql_error());
mysql_select_db("vemana") or error(mysql_error());
$id = $_POST[ 'id' ];
$name = $_POST[ 'name' ];
$age = $_POST[ 'age' ];
27
$mob = $_POST[ 'mob' ];
}
else{
echo "<script>alert('Error in insertion');</script>";
}
}
else {
echo "<script>alert('Invalid student ID');</script>";
}
?>
28
prg10a.php
<?php
$con=mysql_connect("localhost", "root", "") or error(mysql_error());
mysql_select_db("vemana") or error(mysql_error());
$i=0;
$id=array();
$q = mysql_query("SELECT * from saranya" ) or error( mysql_error() );
if(mysql_num_rows($q) > 0 ) {
print "<h3>Student Information before sorting </h3>";
print " <table border size=1>
<tr>
<th>Id</th>
<th>Name</th>
<th>Age</th>
<th>Mobile</th>
</tr>";
29
while($data=mysql_fetch_row($q)) {
$id[$i]=$data[0];
print "<tr>
<td>$data[0]</td>
<td>$data[1]</td>
<td>$data[2]</td>
<td>$data[3]</td>
</tr>";
$i++;
}
echo "</table>";
$id=sorting($id);
echo "<h3>Sorted Data</h3><br/> ";
echo "<table border='2'>
<th>USN</th> <th>NAME</th> <th>AGE</th> <th>MOBILE</th>";
for($k=0;$k<count($id);$k++) {
30
echo "<td>".$row['stdname']."</td>";
echo "<td>".$row['stdage']."</td>";
echo "<td>".$row['stdmob']."</td>";
echo "</tr>";
}
}
}
echo "</table>";
}
function sorting($list) {
$len=count($list);
$x=0;
$y=0;
for($y=0;$y<$len-1;$y++) {
$min=$y;
for($x=$y+1; $x< $len;$x++)
{ if($list[$x]<$list[$min]) {
$min=$x;
}
}
if($min!=$y) {
$temp=$list[$y];
$list[$y]=$list[$min];
31
$list[$min]=$temp;
}
}
return $list;
}
?>
32