Assignment 1 : Basics in PHP
Set A :
Q1. Write a PHP Script to display Quotient and Remainder of the division of two variables.
<?php
$a = 60;
$b = 2;
$Quotient = $a / $b;
echo "Quotient is = $Quotient <BR>";
$remainder = $a % $b;
echo "Remainder is = $remainder <BR>";
?>
===========================================================
Q 2. Write a PHP Script to swap the values of two variables.
<?php
$a = 10;
$b = 20;
echo "Before swap a and b is $a and $b <BR>";
$temp = $a;
$a = $b;
$b = $temp;
echo "After swap a and b is $a and $b <BR>";
?>
===========================================================
Q3. Write a PHP Script which will convert temperatures from Celsius(C)to Fahrenheit (F). (Hint: C=5.0/9(F-32)
<?php
$f = 80;
$c = 5 / 9 * ($f - 32);
$c = round($c, 4);
echo "The Celsius is $c <BR>";
?>
===========================================================
Set B :
Q1. 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 )
<?php
$length = 5;
$height = 10;
$breath = 15;
$cuboidSurfaceArea = 2 * (($length * $breath) + ($length * $height) + ($breath * $height));
echo ("The Surface Area of a cuboid is " . $cuboidSurfaceArea);
$cuboidVolume = $length * $breath * $height;
echo ("<BR> The Volume of a Cuboid is ". $cuboidVolume);
?>
===========================================================
Q2. Write a PHP Script to calculate the area of Circle, Square, and Rectangle.
<?php
echo "2. Write a PHP Script to calculate the area of Circle, Square, and Rectangle. <BR>";
define("PI", 3.14);
$radius = 5; $side = 5; $length = 10; $width = 20;
// area of circle
$circle_Area = PI * $radius * $radius;
echo("Area of Circle is ".$circle_Area);
// area of square
$square_area = $side * $side;
echo("<BR>Area of Square is " . $square_area);
// area of rectangle
$rectangle_area = $length * $width;
echo("<BR>Area of Rectangle is ". $rectangle_area);
?>
=======================================================
<?php
Q3. Write a PHP Script to display the total and percentage of Marks of Subjects (Out of100) Data Structure, Digital Marketing, PHP, SE, and BigData.
$student1 = array( "data_structure" => 70,
"digi_mark" => 90,
"php" => 88,
"SE" => 60,
"big_data" => 45);
$total_marks = 0; $sub = 0;
foreach ($student1 as $key => $value) {
$total_marks += $value;
$sub++;
}
echo("<BR>The total marks of student1 is ".$total_marks);
echo("<BR>Percentage is = ". $total_marks / $sub);
?>
===========================================================
Set C :
Q1. 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.
HTML file : index.html
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@.0.2/dist/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="css/01_php_form.css" />
<title>AIR Ticket Reservation</title>
</head>
<body>
<form action="01_01_details.php" method="post" id="air_form">
<h3 class="form_title">AIR Ticket Reservation</h3>
<div class="mb-3">
<label for="name" class="form-label">Name :</label>
<input type="text" class="form-control" id="name" name="name" />
</div>
<div class="mb-3">
<label for="address" class="form-label">Address :</label>
<input
type="text"
class="form-control"
id="address"
name="address"
/>
</div>
<div class="mb-3">
<label for="contact" class="form-label">Contact No. :</label>
<input
type="number"
class="form-control"
id="contact"
name="contact"
/>
</div>
<div class="mb-3">
<label for="source" class="form-label">Source :</label>
<input
type="text"
class="form-control"
id="source"
name="source"
/>
</div>
<div class="mb-3">
<label for="destination" class="form-label"
>destination :</label
>
<input
type="text"
class="form-control"
id="destination"
name="destination"
/>
</div>
<div class="mb-3">
<label for="date" class="form-label"> Date of journey :</label>
<input type="date" class="form-control" id="date" name="date" />
</div>
<div class="mb-3">
<label for="gender" class="form-label"> Gender :</label><br />
<input type="radio" name="g" value="male" />
<label class="gender">Male</label>
<input type="radio" name="g" value="female" />
<label class="gender">Female</label>
</div>
<div class="mb-3">
<label for="pass_no" class="form-label">No of Persons :</label>
<input
type="number"
class="form-control"
id="pass_no"
name="pass"
/>
</div>
<div class="mb-3">
<h6>Price per Ticket is Rs. 150</h6>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
--------------------------------------------------------------------------------------------
CSS file : 01_php_form.css
#air_form {
padding: 1rem 2rem;
width: 500px;
margin: 2rem auto;
border-radius: 8px;
box-shadow: 3px 3px 8px rgba(0, 0, 0, 0.3);
}
label {
font-size: 16px;
font-weight: 500;
color: gray;
}
.gender {
margin-right: 10px;
}
.form_title {
text-align: center;
}
-----------------------------------------------------------------------------------------------
PHP file : 01_01_details.php
<?php
echo "<H1>";
echo "AIR Ticket Reservation Details <BR>";
echo "</H1>";
$persons = $_POST['pass'];
$price = 150;
foreach ($_POST as $key => $value) {
echo "$key : $value <br>";
}
$total_cost = $persons * $price;
echo("Total cost of Air Reservation is Rs. $total_cost");
?>
This Php file Output :
AIR Ticket Reservation Details
name : SARODE SIDDHARTH RAVINDRA
address : Ram nagar
contact : 55
source : 5
destination : mumbai
date : 2023-08-18
g : male
pass : 4
Total cost of Air Reservation is Rs. 600
==========================================================
0 Comments