Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Dr.

Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus

Lab Manual

2246 NAL - 2
E-Commerce
[PRACTICAL ACTIVITY BOOK]

Prepared by
Dr. Vasanthi Muniasamy

Department of Computer Science,


Program: Information System
Academic year-2023-2024

1
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus

Index Page

S. No Marks Given Date Submission Date Signature

1 4

2 3

3 3

4 5

5 4

6 3

7 4

8 4

2
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus

1(a). Write a PHP program to find maximum of three numbers. [2 Marks]

<?php
$a = readline("Enter the Number for a: ");
$b = readline("Enter the Number for b: ");
$c = readline("Enter the Number for c: ");
if($a > $b)
{
if($a > $c)
echo "Maximum num a = $a";
else
echo "Maximum num c = $c";
}
else
{
if($c > $b)
echo "Maximum num c = $c";
else
echo "Maximum num b = $b";
}
?>

1(b). Write a PHP Program to check the given number is odd or even. [2 Marks]

<?php
$a = readline("Enter the Number: ");
if ($a % 2==0)
{
echo "Given number is EVEN";
}
else
{
echo "Given number is ODD";
}
?>

3
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus

2(a). Write a PHP Program to convert fahrenheit to celsius. [1 Mark]

<?php
$fahrenheit = readline("Enter the fahrenheit: ");
$celsius = (($fahrenheit - 32) * 5) / 9;
$celsius = round($celsius, 3);
echo "Temperature in celsius is: $celsius";
?>

2(b). PHP Program to check whether a number is a disarium number or not. [2 Marks]

<?php
$num = readline("Enter the number");
$rem = 0;
$sum = 0;
$size = strlen($num);
$n = $num;
while ($n > 0) {
$rem = $n % 10;
$sum = $sum + pow($rem, $size);
$n = (int)($n / 10);
$size--;
}
if ($sum == $num)
echo "$num is a disarium number";
else
echo "$num is not a disarium number";
?>

4
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus

3. Write PHP program to implement mathematical functions. [3 Marks]

<?php
$number = 6;
$result = $number * $number;
echo "Square of 6 is: $result\n\n";
$number = -225;
$absoluteValue = abs($number);
echo "Absolute Value: $absoluteValue\n\n";
$numbers = [12, 7, 25, 8, 14];
$maximum = max($numbers);
echo "Maximum Value: $maximum\n\n";
$minimum = min($numbers);
echo "Minimum Value: $minimum\n\n";
$number = 99.5;
$roundedUp = ceil($number);
echo "Rounded Up: $roundedUp\n\n";
$number = 99.5;
$roundedDown = floor($number);
echo "Rounded Down: $roundedDown\n\n";
$base = 2;
$exponent = 3;
$result = pow($base, $exponent);
echo "2^3: $result";
?>

5
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus

4(a). Write a PHP Program implement the concept of an array. [2 Marks]

<?php
$a = array(10, 30, 89, 64, 23);
$lar = $a[0];
$s = count($a);
for ($i = 0; $i < $s; $i++) {
if ($a[$i] > $lar)
$lar = $a[$i];
}
echo "Largest element in the array is $lar";
?>

4(a). Write a PHP Program implement the concept of an array. [3 Marks]

<?php
$array = [
"Father_name" => "salem",
"Father_age" => 50,
"Father_occupation" => "Engineer",
"Mother_name" => "Fathma",
"Mother_age" => 45,
"Mother_occupation" => "Home maker",
];
foreach ($array as $key => $value) {
echo "$key : $value\n\n";
}
?>

6
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus

5(a). Write a PHP program to implement Conditional statements - Switch. [2 Marks]

<?php
$day=date("l");
switch ($day) {
case "Sunday":
echo "It's the start of the week.";
break;
case "Wednesday":
echo "It's a weekday with various activities.";
break;
case "Friday":
echo "It's the weekend.";
break;
default:
echo "It's a regular day.";
break;
}

5(b). Write a PHP program to implement Conditional statements – if else. [2 Marks]

<?php
$age = 10;
$gender = "Female";
if ($age >= 18 and $gender == "Female")
echo "You are an adult Female.";
else
echo "You are not an adult Female.";
?>

7
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus

6(a). Write a PHP program to implement Looping statements – for [2 Marks]

<?php
for ($i = 1; $i <= 3; $i++) {
for ($j = 1; $j <= 5; $j++){
echo "$i * $j = ". $i * $j. "\n";
}
echo "\n";
}
?>

6(b). Write a PHP program to implement Looping statements – for [1 Mark]

<?php
$i = 1;
while ($i <= 10) {
echo "$i \n";
$i++;
}
?>

8
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus

7. Write a PHP program to implement String handling functions. [4 Marks]

<?php
$text = "welcome";
$length = strlen($text);
echo "Length of the string: $length\n\n";

$reverse = strrev($text);
echo "Reversed string: $reverse\n\n";

$upper = strtoupper($text);
echo "Upper string: $upper\n\n";

$text = "WELCOME";
$lower = strtolower($text);
echo "Lower string: $lower\n\n";

$substring = substr($text, 0, 5);


echo "Substring: $substring\n\n";

$text = "I love apples. apples are delicious.";


$new_text = str_replace("apples", "bananas", $text);
echo "$new_text\n\n";

$wordcount = str_word_count($text);
echo $wordcount;
?>

9
Dr. Vasanthi Muniasamy, Department of Computer Science, Al-Mahala Female Campus

8. Write a PHP program to implement Date and Time functions. [4 Marks]

<?php
echo "Today is " . date("Y/m/d") . "\n";
echo "Today is " . date("Y.m.d") . "\n";
echo "Today is " . date("Y-m-d") . "\n";
echo date("M-d-Y h:m:s\n", mktime(10,11,35,11,27,2021));
echo "Today is " . date("l\n\n");

echo "The time in " . date_default_timezone_get() . " is " . date("h:i:sa");


echo "\n";

date_default_timezone_set("Asia/Calcutta");
echo "The time in" . date_default_timezone_get() . "is" . date("h:i:sa");
echo "\n";

date_default_timezone_set("America/New_York");
echo "The time in" . date_default_timezone_get() . "is" . date("h:i:sa");
echo "\n";
?>

10

You might also like