University of Makati
College of Computer Science
Web System and Technologies
Laboratory Exercise 3. PHP Numbers
Group Name: Zodiac
Team Leader: Mariano, Carl Jacob S.
Members: Redoloso, James Lloyd
Jarabata, Maria Angelita
Valentin, Vince
Submitted to: Prof. Michael C. Olivo
Date of Submission: ____
1
I. INTENDED LEARNING OUTCOMES
At the end of this exercise, students should be able to:
1. Learn PHP numbers
2. Illustrate the various arithmetic functions.
3. Demonstrate the use of numbers and syntax
4. Apply for numbers in computations
II. ACTIVITY
2
Code #1: <HTML>
<HEAD>
<TITLE>Converter</TITLE>
</HEAD>
<BODY style="background-color:powderblue;">
<p style="font-family: verdana;">
<div align="center">
<?php
ini_set('display_errors',0);
$fah ==0;
?>
<form action="" method="post">
<p style="font-size:30px">Enter Fahrenheit</p>
<input type="text" name="fah" id="text" size=30 maxlength=30
placeholder="Enter Celsius"><?php $_POST['fah'] ?><br>
<input class="button" type="submit" name="submit" value="submit"/>
<p style="font-size:30px">Enter Celsius</p>
<input type="text" name="cel" id="text" size=30 maxlength=30
placeholder="Enter Fahrenheit"><?php $_POST['cel'] ?><br>
<input class="button" type="submit" name="compute" value="compute"/>
<?php
ini_set('display_errors',0);
3
if(isset($_POST['compute'])){
$cel = $_POST['cel'];
$Fahrenheit = (float)(($cel * 9 / 5) + 32);// celsius to fahrenheit
}
if(isset($_POST['submit'])){
$fah = $_POST['fah'];
//$celsius = (float)(($fah * 9 / 5) - 32);//fahrenheit to celsius
$div = 5/9;
$div1 = $fah - 32;
$div2 = $div * $div1;
$celsius = (float)($div2);
}
?>
<h1>
<?php
if(isset($_POST['compute'])){
echo "Results for Fahrenheit: ";
echo $Fahrenheit;
}
?>
</h1>
<h1>
<?php
if(isset($_POST['submit'])){
echo "Results for celsius:";
echo $celsius;
}
s ?>
</h1>
</div>
</form>
</BODY>
</HTML>
4
2. The basic rate of a bus is 10php for the first 1km and an additional 2php for every
succeeding 2kms. Input the distance the commuter will travel (in m), and the payment.
Display the total distance travel (in km), the cost of the travel, and the change of the
commuter.
Code #2: <HTML>
<HEAD>
<TITLE>Bus Fare</TITLE>
</HEAD>
<BODY style="background-color: #fefbd8;">
<div align="center">
<h1 style="font-family: verdana;"> Bus basic rate is P10 </h1>
<form method="POST">
Distance:
<input type="number" name="distance" size=30 maxlength=30
placeholder="Input Distance in Meter"><br><br>
Payment:
<input type="number" name="payment" size=30 maxlength=30
placeholder="Input your Payment"><br><br>
<input type="submit" name ="submit2" value="compute">
</form>
<?php
if (isset($_POST['submit2'])) {
$distance = $_POST['distance'];
5
$payment = $_POST['payment'];
$distancetoKM = $distance/1000;
$minpayment = 10;
$totalfare = 0;
if ($distancetoKM > 1){
if ((distancetoKM)% 1 == 0) {
$change = ($distancetoKM)/2;
$totalfare = ($change*2) + $minpayment;
}
} else {
$totalfare=$minpayment;
}
echo "<h2> <u> <span> Output: </span> </u> </h2>";
echo "<h3> Distance Travel (KM): $distancetoKM <br>";
echo "Payment: P$payment <br>";
echo "Fare: P$totalfare <br>";
echo "Change: P".($payment - $totalfare)." </h3>";
}
?>
</BODY>
</div>
</HTML>
3. Create a PHP script that will compute and display the area of triangle, square, and
quadratic equations.
6
Code #3: <HTML>
<HEAD>
<TITLE> COMPUTE </TITLE>
</HEAD>
<style>
h2 {
font-family: verdana;
}
</style>
<BODY style="background-color:powderblue;">
<div align="center";>
<form method="POST">
<h2> Find the Area of Triangle </h2>
Base:
<input type="number" name="base" size=30 maxlength=30
placeholder="Input Length of Base"><br><br>
Height:
<input type="number" name="height" size=30 maxlength=30
placeholder="Input Length of Height"><br><br>
<input type="submit" name="submit1" value="Calculate">
</form>
7
<?php
if (isset($_POST['submit1'])) {
$base = $_POST['base'];
$height = $_POST['height'];
$area = ($base*$height)/2;
echo "<b> Answer: </b><br>";
echo "The area of a triangle with base as $base and height as
$height is $area";
?>
<br>
<form method="POST">
<h2> Find the Area of Square </h2>
<input type="number" name="num1" size=30 maxlength=30
placeholder="Input Length of Square side"><br><br>
<input type="submit" name="submit2" size=30 maxlength=30
value="Calculate">
</form>
<?php
if (isset($_POST['submit2'])) {
$a = $_POST['num1'];
$area = $a * $a;
echo "<b> Answer: </b><br>";
echo "The area of a square with the length of " .$a. " is "." "
.$area;
return 0;
}
?>
</BODY
</div>
</HTML>
8
Code #3.2: <HTML>
<HEAD>
<TITLE> QUAD EQUATION </TITLE>
</HEAD>
<style>
{
font-family: times new roman;
}
</style>
<BODY style="background-color: #BDB76B;">
<div align="center";>
<form method="POST">
<h2> Find Solution for Quadratic Equation </h2>
A = <input type="text" name="A" size=30 maxlength=30
placeholder="Coefficient A"><br><br>
B = <input type="text" name="B" size=30 maxlength=30
placeholder="Coefficient B"><br><br>
C = <input type="text" name="C" size=30 maxlength=30
placeholder="Coefficient C"><br><br>
<input type="submit" name="submit" value="Find X!">
</form>
9
<?php
if (isset($_POST['submit'])) {
$a = $_POST['A'];
$b = $_POST['B'];
$c = $_POST['C'];
$precision = 4;
$d = $b - 4 * $a * $c;
if($d <0) {
echo "Roots are complex numbers.";
echo "<br>";
echo "Roots of quadratic equation are: ";
echo "<br>";
echo "x = ". -$b/(2*$a). " + " .number_format(sqrt(-
$d)/(2*$a), $precision). "i ";
echo "<br>";
echo "x = ". -$b/(2*$a).number_format(-sqrt(-
$d)/(2*$a), $precision). "i ";
}
else if($d == 0){
echo "Both roots are equal.";
$root1 = -$b /(2* $a);
echo "Root of quadratic equation is: " .$root1;
return 0;
}
else{
echo "Roots are real numbers.";
$root1 = ( -$b + sqrt($d)) / (2* $a);
$root2 = ( -$b - sqrt($d)) / (2* $a);
echo "Roots of quadratic equation are: " .$root1
.$root2;
}
return 0;
?>
10
</BODY>
</div>
</HTML>
III. CONCLUSION:
Our conclusion is what we’ve learned in this topic, basically PHP Numbers can
used in different kind of conversion like Fahrenheit to Celsius and vice versa,
rate within the distance, area of triangle, square, quadratic equation. This
activity gives us an idea on how to build a conversion using PHP Numbers
which we only see in some websites or application that related to these
conversions and equation.
IV. REFERENCE/s
RUBRICS:
Activity 1 Correct Output 50%
with no Errors
Apply HTML Design 30%
Conclusion, Source Code, 20%
Screen Shot and References
Total
11