PHP: ASSIGNMENT NO.:1
PRACTICE PROGRAM:
1. Write a PHP script to perform arithmetic operations on two numbers (Addition, Subtraction, Multiplication Division ).
ANS:
HTML CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="Q1.PHP">
enter first number: <input type="text" name="first"><br>
<br>
enter second number: <input type="text" name="second"><br>
<br>
<button>arithmetic operation!</button>
</form>
</body>
</html>
PHP CODE:
<?php
$a = $_GET["first"];// readline("enter first number:");
$b = $_GET["second"];// readline("enter second number:");
$c = $a+$b;
echo("addition of $a and $b is ".$c."<br>");
$c = $a-$b;
echo("subtraction of $a and $b is ".$c."<br>");
$c = $a*$b;
echo("multiplication of $a and $b is ".$c."<br>");
$c = $a/$b;
echo("division of $a and $b is ".$c."<br>");
$c=$a%$b;
echo("modulas of $a and $b is ".$c."<br>");
?>
-------------------------------------------------------------------------------------------------------------
2. Write a PHP script to display a maximum of two numbers using a conditional operator.
ANS:
<html>
<head>
<title>max of two numbers.</title>
</head>
<body>
<form action="Q2.php">
enter a number: <input type="text" name="first"><br>
<br>
enter second number: <input type="text" name="second"><br>
<br>
<button>find max!</button>
</form>
</body>
</html>
PHP CODE:
<?php
$a = $_GET["first"];
$b = $_GET["second"];
if ($a>$b) {
echo"$a is greater than $b";
}
else {
echo"$b is greater than $a";
}
?>
-------------------------------------------------------------------------------------------------------------------------
3. Write a PHP script that will perform pre and post-increment of a number. (Example ++a, a++).
ANS:
PHP CODE:
<?php
$a = 10;
echo("pre-increment value of $a is ".++$a."<br>");
echo("post increment value of $a is ".$a++."<br>");
echo("pre-decrement value of $a is ".--$a."<br>");
echo("post decrement value of $a is ".$a--."<br>");
echo("pre-decrement value of $a is ".--$a."<br>");
?>
----------------------------------------------------------------------------------------------------------------------
SET A:
1. Write a PHP Script to display Quotient and Remainder of the division of two variables.
ANS:
HTML CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="Q1.php">
enter first number:<input type="text" name="first"><br>
<br>
enter second number: <input type="text" name="second"> <br>
<br>
<button>click me!</button><br>
</form>
</body>
</html>
PHP CODE:
<?php
$a = $_GET["first"];
$b = $_GET["second"];
$c = $a/$b;
echo("quotient after division of $a and $b is ".$c."<br>");
$c = $a%$b;
echo("reminder after division of $a and $b is ".$c."<br>");
?>
--------------------------------------------------------------------------------------------------------------------
2. Write a PHP Script to swap the values of two variables.
ANS:
HTML CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>program for swap two variables itself!</h1>
<form action="Q2.php">
enter first number: <input type="text" name="first"><br>
<br>
enter second number: <input type="text" name="second"><br>
<br>
<button>click</button>
</form>
</body>
</html>
PHP CODE:
<?php
$a = $_GET["first"];
$b = $_GET["second"];
echo("before swapping a=$a and b=$b"."<br>");
$temp = $a;
$a = $b;
$b = $temp;
echo("after swapping a=$a and b=$b"."<br>");
?>
------------------------------------------------------------------------------------------------------------------
3. Write a PHP Script which will convert temperatures from Celsius(C)to Fahrenheit (F). (Hint: C=5.0/9(F-32)
ANS:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>temperature convertor!</h1>
<form action="Q3.php">
Enter temperature in fehrenheit: <input type="text" name="first"><br>
<br>
<button>click</button>
</form>
</body>
</html>
PHP CODE:
<?php
$f = $_GET["first"];
$c = (5.0/9)*($f-32);
echo("the temperature in celcius is ".$c."<br>");
?>
----------------------------------------------------------------------------------------------------------
SET B:
1. Write a PHP Script to display the surface area and volume of a cuboid. (Hint: surface area=2(lb+lh+bh ), volume = l*b*h )
ANS:
HTML CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>calculate area and volume of cuboid!</h1>
<form action="Q1.php">
Enter length of cuboid: <input type="text" name="length"><br>
<br>
Enter width of cuboid: <input type="text" name="width"><br>
<br>
Enter height of cuboid: <input type="text" name="height"><br>
<br>
<button>calculate!</button>
</form>
</body>
</html>
PHP CODE:
<?php
$l = $_GET["length"];
$b = $_GET["width"];
$h = $_GET["height"];
$v = ($l*$b*$h);
echo("volume of cuboid is ".$v."<br>");
$a = 2*(($l*$b)+($l*$h)+($b*$h));
echo("surface area of cuboid is ".$a."<br>");
?>
------------------------------------------------------------------------------------------------------------------
2. Write a PHP Script to calculate the area of Circle, Square, and Rectangle.
ANS:
HTML CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Calculation of area of circle ,square and rectangle! </h1>
<form action="Q2.php">
Enter radius of circle: <input type="text" name="radius"><br>
<br>
Enter length of square: <input type="text" name="square"><br>
<br>
Enter width of rectangle: <input type="text" name="width"> <br>
<br>
Enter length of rectangle: <input type="text" name="length"><br>
<br>
<button>calculate!</button>
</form>
</body>
</html>
PHP CODE:
<?php
$pi = 3.14;
$r = $_GET["radius"];
$ac = $pi*$r*$r;
echo("\n area of circle is ".$ac."<br>");
$s = $_GET["square"];
$as = $s*$s;
echo("\n area of square is ".$as."<br>");
$l = $_GET["length"];
$b = $_GET["width"];
$re = $l*$b;
echo("\n area of rectangle is ".$re);
?>
---------------------------------------------------------------------------------------------------------------------
3. Write a PHP Script to display the total and percentage of Marks of Subjects (Out of 100) Data Structure, Digital Marketing, PHP, SE, and Bigdata.
ANS:
HTML CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Marks calculator!</h1>
<form action="Q3.php">
<h3>Enter your subject marks out of 100!</h3>
data structure: <input type="text" name="data" size="2px"><br>
<br>
digital marketing : <input type="text" name="digi" size="2px"><br>
<br>
PHP : <input type="text" name="php" size="2px" ><br>
<br>
software engineering: <input type="text" name="se" size="2px"><br>
<br>
big data: <input type="text" name="big" size="2px"><br>
<br>
<button>calculate!</button>
</form>
</body>
</html>
PHP CODE:
<?php
$d = $_GET["data"];
$di = $_GET["digi"];
$p = $_GET["php"];
$s= $_GET["se"];
$b = $_GET["big"];
$t=$d+$di+$p+$s+$b;
$avg = $t/5;
echo("total marks is ".$t."<br>");
echo("percentage is ".$avg."<br>");
?>
-----------------------------------------------------------------------------------------------------------------------------------
SET C:
1. Write a PHP Script to calculate the total cost of AIR Ticket Reservation and display the details for Name, Address, Contact No, Source, Destination, Date of journey, Gender of passenger, No of Persons, Price per Ticket, etc.
ANS:
HTML CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="Q1.css">
</head>
<body>
<div id="main">
<h2>AIR ticket reservation</h2>
<div id="form">
<form action="Q1.php" method="post">
<div class="input">
<label for="name"><u>Enter Name:</u></label>
<input type="text" name="name" id="inp"><br>
</div>
<div class="input">
<label for="address"><u>Address:</u></label>
<input type="text" name="address" id="inp">
</div>
<div class="input">
<label for="contact"><u>Contact No.:</u></label>
<input type="number" name="contact" id="inp"><br>
</div >
<div class="input">
<label for="src"><u>Source:</u></label>
<input type="text" name="src" id="inp">
</div >
<div class="input">
<label for="dest"><u>Destination:</u></label>
<input type="text" name="dest" id="inp">
</div>
<div class="input">
<label for="date"><u>Date of journey:</u></label>
<input type="date" name="date" id="inp">
</div>
<div class="input">
<label for="gender"><u>Gender of passenger:</u></label>
<select name="gender" id="gen">
<option value="1">Male</option>
<option value="2">Female</option>
</select>
</div>
<div class="input">
<label for="person"><u>No.of persons:</u></label>
<input type="text" name="person" id="inp">
</div>
<div class="input">
<label for="class"><u>Choice class:</u></label>
<select name="class" id="class">
<option value="1">Normal class</option>
<option value="2">Special class</option>
</select>
</div>
<div class="input">
<label for="price"><u>Price of per Ticket:</u></label>
<input type="text" name="price" id="inp">
</div>
<div class="input">
<input type="submit" name="submit" id="submit" value="submit">
<input type="reset" name="reset" id="reset" value="reset">
</div>
</form>
</div>
</div>
</body>
</html>
CSS CODE:
body{
height: 400px;
width: 100%;
padding: 0;
margin: 0;
background-color: antiquewhite;
}
#main{
border: 1px solid black;
box-shadow: 50px black;
margin-right: 30%;
margin-left: 30%;
margin-top: 30px;
padding-left: 10px;
border-radius: 5px;
background-color: white;
}
#inp{
margin-top: 5px;
margin-bottom: 5px;
}
#submit{
margin-bottom: 5px;
margin-right: 50%;
}
h2{
text-align: center;
}
Comments
Post a Comment
Enter comment here!