Lab programs
Lab programs
Sl No Programs Page No
01 Write a Javascript to design a simple calculator to perform the following 2-6
operations: sum, product, difference and quotient.
02 Write a Javascript that calculates the squares and cubes of the numbers 7-8
from 0 to 10 and outputs HTML text that displays the resulting values in
an HTML table formats.
06 Write a php program to display number of visitors visiting the webpage. 17-18
07 Write a php program to display the digital clock with current time of the 19-20
server.
08 Write the PHP programs to do the following: 21-27
a) Implement simple calculator operations.
b) Find the transpose, Multiplication, Addition of two matrices.
09 Write a PHP program named states.py that declares a variable states 28-30
with value “Mississippi Alabama Texas Massachussetts Kansas”.Write a
PHP program that does the following.
a) Search for a word in variable states that ends in xas. Store this word
in element( ) of a list named states list.
b) Search for a word in states that begins with k and s .Perform a case-
insensitive comparison.
c) Search for a word in states that ends in a .Store this word in element 3
of the list.
10 Write a PHP program to sort the student records which are stored in the 31-34
database using selection sort.
1
201304
1. Write a Javascript to design a simple calculator to perform the
following operations: sum, product, difference and quotient.
<html>
<head>
<script>
function dis(val)
document.getElementById("result").value+=val
function solve()
let x = document.getElementById("result").value
let y = eval(x)
document.getElementById("result").value = y
function clr()
document.getElementById("result").value = ""
</script>
<!--for styling-->
2
201304
<style>
.title{
margin-bottom: 10px;
text-align: center;
width: 210px;
color: green;
input[type="button"]
background-color: green;
color: black;
width: 100%;
input[type="text"]
background-color: white;
width:100%;
</style>
3
201304
</head>
<!--creating a table-->
<body>
<div class="title">CALCULATOR</div>
<table border="1">
<tr>
</tr>
<tr>
</tr>
<tr>
4
201304
<td><input type="button" value="-" onclick="dis('-')"/></td>
</tr>
<tr>
</tr>
<tr>
</tr></table>
</body>
</html>
5
201304
Output:
6
201304
2. Write a Javascript that calculates the squares and cubes of the numbers
from 0 to 10 and outputs HTML text that displays the resulting values in
an HTML table formats.
<html>
<head>
<script>
+ "</td></tr>");
document.write("</table>");
</script>
</html>
7
201304
Output:
8
201304
3. Write a Javascript program for Text-Growing and Text-Shrinking.
<html>
<body>
<div id="h"></div>
<script>
function a(){
"+color+"\"><b>"+t+"</b></h1>";
if(v==50) f = 0,t="TEXT-SHRINKING";
if(v==5) f = 1,t="TEXT-GROWING";
c();
function c(){
setTimeout(a,300);}
c();
</script>
</body>
</html>
9
201304
Output:
10
201304
4. Write a HTML file and Javscript program for.
a) Position in the string of the leftmost vowel.
b) Number with its string in a reverse order.
<html>
<script>
if(b){
while(b>0)
else{
a = a.search('[aeiouAEIOU]');
</script>
</html>
11
201304
Output:
12
201304
5. XML document to store information about the student.
XML file
<STUDENTDTA>
<STUDENT>
<USN>USN: 3GN16CS002</USN>
<NAME>NAME: SAMMISHRA</NAME>
<COLLEGE>COLLEGE: GNDECB</COLLEGE>
<BRANCH>BRANCH: BVOC</BRANCH>
<YEAR>YEAR:2021</YEAR>
<EMAIL>EMAIL: [email protected]</EMAIL>
</STUDENT>
<STUDENT>
<USN>USN: 3GN16CS009</USN>
<NAME>NAME: PRERANA</NAME>
<COLLEGE>COLLEGE: GNDECB</COLLEGE>
<BRANCH>BRANCH: BVOC</BRANCH>
<YEAR>YEAR:2020</YEAR>
13
201304
<EMAIL>EMAIL: [email protected]</EMAIL>
</STUDENT>
<STUDENT>
<USN>USN: 3GN16CS010</USN>
<NAME>NAME: NEHA</NAME>
<COLLEGE>COLLEGE: GNDECB</COLLEGE>
<BRANCH>BRANCH: BVOC</BRANCH>
<YEAR>YEAR:2021</YEAR>
<EMAIL>EMAIL: [email protected]</EMAIL>
</STUDENT>
<STUDENT>
<USN>USN: 3GN16CS019</USN>
<NAME>NAME: SAHITHYA</NAME>
<COLLEGE>COLLEGE: GNDECB</COLLEGE>
<BRANCH>BRANCH: BVOC</BRANCH>
<YEAR>YEAR:2021</YEAR>
<EMAIL>EMAIL: [email protected]</EMAIL>
</STUDENT>
</STUDENTDTA>
14
201304
la5.css
*{
USN{
color: blue;
font-size: 30px;
margin-top: 20px;
15
201304
Output:
16
201304
6. Writea php program to display number of visitors visiting the webpage
and to display this count of visitors , with proper headings.
<?php
$file = 'count.txt';
$c = file_get_contents($file);
file_put_contents($file,$c+1);
?>
17
201304
Output:
18
201304
7. Writea php program to display a digital clock which displays the
current time of the server.
<head>
<style>
p{
color: yellow;
font-size: 90px;
position: absolute;
top: 40%;
left:50%;
transform: translate(-50%,-50%);
body{
background-color: maroon;
</style>
</head>
19
201304
Output:
20
201304
8a. Write the PHP programs to do the following:
-Implement simple calculator operations.
<html>
<head>
<style>
table, td, th {
width: 35%;
text-align: center;
background-color: lightgray;
input,p { text-align:right; }
</style>
</head>
<body>
<table>
<tr>
value="calculate">Calculate</td></tr>
<tr>
21
201304
<td>Second Number:</td><td><input type="text"
name="num2"/></td>
</tr>
</form>
<?php
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
echo "<tr><td>
Addition :</td><td><p>".($num1+$num2)."</p></td>";
echo "<tr><td>
Multiplication :</td><td><p>".($num1*$num2)."</p></td>";
echo "</table>";
Else
22
201304
}
?>
</body>
</html>
23
201304
Output:
24
201304
8b. Write the PHP programs to do the following:
Find the transpose, Multiplication, Addition of two matrices.
`<!DOCTYPE html>
<html>
<body>
<?php
function pr($a){
}echo "<br>";
}echo "<br>";
$a = [[1,2,3],[4,5,6],[7,8,9]];
$b = [[7,8,9],[4,5,6],[1,2,3]];
$c[$i][$j] = $a[$j][$i];
25
201304
for ($j=0; $j < 3; $j++)
$c[$i][$j] = 0;
?>
</body>
</html>
26
201304
Output:
27
201304
9. Write a PHP program named states.py that declares a variable states
with value “Mississippi Alabama Texas Massachussetts Kansas”.Write a
PHP program that does the following.
a) Search for a word in variable states that ends in xas. Store this word in
element( ) of a list named states list.
b) Search for a word in states that begins with k and s .Perform a case-
insensitive comparison.
c) Search for a word in states that ends in a .Store this word in element 3
of the lis
<html>
<body>
<?php
$b = explode(' ',$states);
$n = strlen($c);
28
201304
for ($i=0; $i < count($d); $i++)
?>
</body>
</html>
29
201304
Output:
30
201304
10. Write a PHP program to sort the student records which are stored in
the database using selection sort
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "labprogram";
if (!$conn) {
$result = $conn->query($sql);
$usn = array() ;
echo "<tr><th>USN</th><th>NAME</th><th>Marks</th></tr>";
if ($result->num_rows > 0)
while($row = $result->fetch_assoc())
$usn[] = $row["usn"] ;
31
201304
}
$n = sizeof($usn) ;
$pos = $i ;
$pos = $j ;
$temp = $usn[$i] ;
$usn[$i] = $usn[$pos] ;
$usn[$pos] = $temp ;
$name = [ ] ;
$marks = [ ] ;
$result = $conn->query($sql);
if ($result->num_rows> 0)
32
201304
while($row = $result->fetch_assoc())
for($i=0;$i<$n;$i++)
if($row["usn"] == $usn[$i])
$name[$i]=$row["name"];
$marks[$i]=$row["marks"];
echo "<tr><th>USN</th><th>NAME</th><th>Marks</th></tr>";
?>
33
201304
Output:
34
201304