0% found this document useful (0 votes)
7 views

OST Lab Record

The document is a practical record note for BCA students at SRM Institute of Science and Technology, detailing various experiments conducted in the Open Source Technologies course during the academic year 2024-2025. It includes a certificate of completion, an index of experiments, and specific PHP programming tasks such as checking odd/even numbers, sorting arrays, and implementing classes. Each experiment outlines the aim, procedure, program code, output, and results of the executed tasks.

Uploaded by

yagdomyonon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

OST Lab Record

The document is a practical record note for BCA students at SRM Institute of Science and Technology, detailing various experiments conducted in the Open Source Technologies course during the academic year 2024-2025. It includes a certificate of completion, an index of experiments, and specific PHP programming tasks such as checking odd/even numbers, sorting arrays, and implementing classes. Each experiment outlines the aim, procedure, program code, output, and results of the executed tasks.

Uploaded by

yagdomyonon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

FACULTY OF SCIENCE AND HUMANITIES


DEPARTMENT OF COMPUTER APPLICATIONS

PRACTICAL RECORD NOTE

STUDENT NAME :

REGISTER NUMBER :

CLASS : BCA SECTION :

YEAR & SEMESTER : II YEAR & IV SEMESTER

SUBJECT CODE : UCA23401J

SUBJECT : OPEN SOURCE TECHNOLOGIES

APIRL 2025
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
FACULTY OF SCIENCE AND HUMANITIES
DEPARTMENT OF COMPUTER APPLICATIONS
SRM Nagar, Kattankulathur – 603 203

CERTIFICATE

Certified to be the bonafide record of practical work done by

Register No. of II BCA Degree


programme for UCA23401J – OPEN SOURCE TECHNOLOGIES in the
Computer lab in SRM Institute of Science and Technology during the academic
year 2024-2025.

Staff In-charge Head of the Department

Submitted for Semester Practical Examination held on .

Internal Examiner External Examiner


INDEX

S. PAGE STAFF
DATE TITLE
NO NO SIGNATURE

1 02/12/2024 LINUX COMMANDS

04/12/2024 (A) ODD OR EVEN

2
(B) CHECK IF A NUMBER IS POSITIVE,
09/12/2024
NEGATIVE, OR ZERO

(A) PRINT EVEN NUMBERS FROM 1 TO 20


11/12/2024
(FOR LOOP)

(B) SUM OF FIRST 10 NATURAL NUMBERS


3 16/12/2024
(WHILE LOOP)

(C) MULTIPLICATION TABLE OF 5 (DO-


18/12/2024
WHILE LOOP)

02/01/2025 (A) STORE AND DISPLAY 5 STUDENT NAMES

06/01/2025 (B) STUDENT MARKS (ASSOCIATIVE ARRAY)


4

(C) STUDENT DETAILS


09/01/2025
(MULTIDIMENSIONAL ARRAY)

5 16/01/2025 SORTING AN ARRAY

6 21/01/2025 MAXIMUM AND MINIMUM IN AN ARRAY

7 23/01/2025 FACTORIAL USING CLASS

DATE DIFFERENCE CALCULATION USING


8 30/03/2025
PHP

9 04/02/2025 INHERITANCE IN PHP

10 06/02/2025 STRING MANIPULATION FUNCTIONS


INDEX

PAGE STAFF
S. NO DATE TITLE
NO SIGNATURE

CALL BY VALUE AND CALL BY


11 12/02/2025
REFERENCE

12 19/02/2025 EMAIL ID VALIDATION

13 26/02/2025 MOBILE NUMBER VALIDATION

14 05/03/2025 CRUD OPERATIONS IN PHP WITH MYSQL

READ AND PRINT A STRING IN PHP (CLI


15 19/03/2025
MODE)

FACTORIAL CALCULATION USING A WEB


16 21/03/2025
INTERFACE
EXP NO : 01
LINUX COMMANDS
DATE : 02/12/2024

1. To list all the contents in a directory


Command: ls

2. To print a message in the terminal


Command: echo "Your message here"

3. To create a directory
Command: mkdir <directory_name>

4. To create multiple directories using a single command


Command: mkdir -p <directory1>/<directory2>

5. To change the current working directory


Command: cd <directory_name>

6. To append text to a file


Command: echo "text" >> <file_name>

7. To display the contents of a file


Command: cat <file_name>

8. To move to the previous directory


Command: cd ..
9. To remove or delete a directory
Command: rmdir <directory_name> (for empty directories)

Command: rm -r <directory_name> (for non-empty directories)

10. To copy contents from one file to another


Command: cp <source_file> <destination_file>

11. To remove a file


Command: rm <file_name>

12. To view the present working directory


Command: pwd

13. To clear the terminal screen


Command: clear

14. To know the current user


Command: whoami

15. To display running processes


Command: ps

16. To display detailed system information


Command: uname -a
17. To sort files in a directory efficiently
Command: ls -l | sort

18. To sort files in reverse order

Command: ls -lr

19. To sort files in a directory based on size


Command: ls -lS

20. To display file contents in reverse order


Command: tac <file_name>

21. To count the number of words in a file


Command: wc -w <file_name>

22. To count the total number of characters in a file


Command: wc -m <file_name>

23. To count the total number of lines in a file


Command: wc -l <file_name>
24. To add a new line to a file named name.txt

Command: echo "New line text" >> name.txt

25. To move or rename files

Command : mv <oldname.txt> <newname.txt>

26. To navigate to another directory

Command: cd <directory_name>

27. To display detailed listing of all directories

Command: ls -lh

28. To create a symbolic link to a file

Command: ln -s <target_file> <link_name>

29. To create a new file called name.txt

Command: touch name.txt

30. To display the contents of name.txt

Command: cat name.txt


EXP NO : 02
(a) ODD OR EVEN
DATE : 04/12/2024

Aim :

To write a PHP program to check whether a given number is odd or even.

Procedure :
Program :

<?php
$num = 7;
if ($num % 2 == 0) {
echo "$num is Even";
} else {
echo "$num is Odd";
}
?>

Output :

7 is Odd

Result :

The program is executed successfully.


EXP NO : 02 (b) CHECK IF A NUMBER IS POSITIVE,
DATE : 09/12/2024 NEGATIVE, OR ZERO

Aim :

To write a PHP program to check if a number is positive, negative, or zero using


an if-else statement.

Procedure :
Program :

<?php
$num = -5;
if ($num > 0) {
echo "$num is Positive";
} elseif ($num < 0) {
echo "$num is Negative";
} else {
echo "$num is Zero";
}
?>

Output :

-5 is Negative

Result :

The program is executed successfully.


EXP NO : 03 (a) PRINT EVEN NUMBERS FROM
DATE : 11/12/2024 1 TO 20 (FOR LOOP)

Aim :

To write a PHP program that prints even numbers from 1 to 20 using a for loop.

Procedure :
Program :

<?php
for ($i = 2; $i <= 20; $i += 2) {
echo "$i ";
}
?>

Output :

2 4 6 8 10 12 14 16 18 20

Result :

The program is executed successfully.


EXP NO : 03 (b) SUM OF FIRST 10 NATURAL
DATE : 16/12/2024 NUMBERS (WHILE LOOP)

Aim :

To write a PHP program that calculates the sum of the first 10 natural numbers
using a while loop.

Procedure :
Program :

<?php
$sum = 0;
$i = 1;
while ($i <= 10) {
$sum += $i;
$i++;
}
echo "Sum of first 10 natural numbers is: $sum";
?>

Output :

Sum of first 10 natural numbers is: 55

Result :

The program is executed successfully.


EXP NO : 03 (c) MULTIPLICATION TABLE OF 5
DATE : 18/12/2024 (DO-WHILE LOOP)

Aim :

To write a PHP program that prints the multiplication table of 5 using a do-
while loop.

Procedure :
Program :

<?php
$num = 5;
$i = 1;
do {
echo "$num x $i = " . ($num * $i) . "<br>";
$i++;
} while ($i <= 10);
?>

Output :

5 × 1 = 5
5 × 2 = 10
5 × 3 = 15
5 × 4 = 20
5 × 5 = 25
5 × 6 = 30
5 × 7 = 35
5 × 8 = 40
5 × 9 = 45
5 × 10 = 50

Result :

The program is executed successfully.


EXP NO : 04 (a) STORE AND DISPLAY 5 STUDENT
DATE : 02/01/2025 NAMES (ONE-DIMENSIONAL ARRAY)

Aim :

To write a PHP program that stores and displays five student names using a
one-dimensional array.

Procedure :
Program :

<?php
$students = array("John", "Alice", "Mike", "Sara", "Tom");
foreach ($students as $student) {
echo "$student <br>";
}
?>

Output :

John
Alice
Mike
Sara
Tom

Result :

The program is executed successfully.


EXP NO : 04 (b) STUDENT MARKS (ASSOCIATIVE ARRAY)
DATE : 06/01/2025

Aim :

To write a PHP program that stores and displays student marks using an
associative array.

Procedure :
Program :

<?php
$marks = array("John" => 85, "Alice" => 90, "Mike" => 78);
foreach ($marks as $name => $score) {
echo "$name scored $score marks.<br>";
}
?>

Output :

John scored 85 marks.


Alice scored 90 marks.
Mike scored 78 marks.

Result :

The program is executed successfully.


EXP NO : 04 (c) STUDENT DETAILS
DATE : 09/01/2025 (MULTIDIMENSIONAL ARRAY)

Aim :

To write a PHP program that stores and displays student details using a
multidimensional array.

Procedure :
Program :

<?php
$students = array(
array("John", 85, "A"),
array("Alice", 90, "A+"),
array("Mike", 78, "B")
);
foreach ($students as $student) {
echo "Name: " . $student[0] . ", Marks: " .
$student[1] . ", Grade: " . $student[2] . "<br>";
}
?>

Output :

Name: John, Marks: 85, Grade: A


Name: Alice, Marks: 90, Grade: A+
Name: Mike, Marks: 78, Grade: B

Result :

The program is executed successfully.


EXP NO : 05 SORTING AN ARRAY
DATE : 16/01/2025

Aim :

To write a PHP program that sorts an array in ascending order.

Procedure :
Program :

<?php
$numbers = array(5, 2, 8, 1, 3);
sort($numbers);
echo "Sorted numbers: ";
foreach ($numbers as $num) {
echo "$num ";
}
?>

Output :

Sorted numbers: 1 2 3 5 8

Result :

The program is executed successfully.


EXP NO : 06 FIND MAXIMUM AND MINIMUM
DATE : 21/01/2025 IN AN ARRAY

Aim :

To write a PHP program to find the maximum and minimum values in an array.

Procedure :
Program :

<?php
$numbers = array(10, 20, 5, 40, 30);
$max = max($numbers);
$min = min($numbers);
echo "Maximum value: $max <br>";
echo "Minimum value: $min";
?>

Output :

Maximum value: 40
Minimum value: 5

Result :

The program is executed successfully.


EXP NO : 07 FACTORIAL USING CLASS
DATE : 23/01/2025

Aim :

To create a class in PHP that calculates and prints the factorial of a given
number.

Procedure :
Program :

<?php
class factorial_of_a_number {
protected $n;

public function __construct($n1) {


$this->n = $n1;
}

public function result() {


$factorial = 1;
for ($i = 1; $i <= $this->n; $i++) {
$factorial *= $i;
}
return $factorial;
}
}

$newfactorial = new factorial_of_a_number(5);


echo $newfactorial->result();
?>

Output :

120

Result :

The program is executed successfully.


EXP NO : 08 DATE DIFFERENCE
DATE : 30/03/2025 CALCULATION USING PHP OOP

Aim :

To calculate the difference between two dates using PHP's DateTime class

Procedure :
Program :

<?php
$sdate = new DateTime("1981-11-03");
$edate = new DateTime("2013-09-04");
$interval = $sdate->diff($edate);
echo "Difference : " . $interval->y . " years, " .
$interval->m . " months, " . $interval->d . " days ";
?>

Output :

120

Result :

The program is executed successfully.


EXP NO : 09 INHERITANCE IN PHP
DATE : 04/02/2025

Aim :

To demonstrate inheritance by implementing a BankAccount class and a


SavingAccount class.

Procedure :
Program :

<?php
class BankAccount {
private $balance = 0;

public function getBalance() {


return $this->balance;
}

public function deposit($amount) {


if ($amount > 0) {
$this->balance += $amount;
}
}
}

class SavingAccount extends BankAccount {


private $interestRate;

public function setInterestRate($interestRate) {


$this->interestRate = $interestRate;
}

public function addInterest() {


$interest = $this->interestRate * $this-
>getBalance();
$this->deposit($interest);
}
}

$account = new SavingAccount();


$account->deposit(100);
$account->setInterestRate(0.05);
$account->addInterest();
echo $account->getBalance();
?>

Output :
105

Result :

The program is executed successfully.


EXP NO : 10 STRING MANIPULATION
DATE : 06/02/2025 FUNCTIONS

Aim :

To validate various string manipulation functions in PHP.

Procedure :
Program :

<?php
$r= "I am";
echo "$r\n";
echo strlen("Hi Everyone")."\n";
echo str_word_count("Hi Everyone")."\n";
echo strrev("Hello World")."\n";
echo strpos("Hi Buddy", "Buddy")."\n";
echo str_replace("world", "Jack", "Hello world")."\n";
echo strtoupper("world")."\n";
echo strtolower("WORLD")."\n";
echo ucfirst("world")."\n";
echo lcfirst("WORLD")."\n";
echo str_word_count("Welcome to PHP programming")."\n";
echo substr_replace("Hello World", "Everyone", 6)."\n";
echo substr_replace("alone", "ph", 0, 2)."\n";
?>

Output :
I am
12
2
dlroW olleH
3
Hello Jack
WORLD
world
World
wORLD
4
Hello Everyone
phone

Result :

The program is executed successfully.


EXP NO : 11 CALL BY VALUE AND
DATE : 12/02/2025 CALL BY REFERENCE

Aim :

To demonstrate call by value and call by reference in PHP.

Procedure :
Program :

Call by value :

<?php
function incrementValue($num) {
$num += 10;
echo "Inside function: $num\n";
}

$number = 10;
incrementValue($number);
echo "Outside function: $number\n";
?>

Output :
Inside function: 20
Outside function: 10

Call by reference :

<?php
function incrementValueByReference(&$num) {
$num += 10;
echo "Inside function: $num\n";
}

$number = 10;
incrementValueByReference($number);
echo "Outside function: $number\n";
?>

Output :
Inside function: 20
Outside function: 20

Result :

The program is executed successfully.


EXP NO : 12 EMAIL ID VALIDATION
DATE : 19/02/2025

Aim :

To validate an email address using PHP regex.

Procedure :
Program :

<?php
function checkemail($str) {
return (!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-
9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE :
TRUE;
}
if (!checkemail("[email protected]")) {
echo "Invalid email address.";
} else {
echo "Valid email address.";
}
?>

Output :
Valid email address.

Result :

The program is executed successfully.


EXP NO : 13 MOBILE NUMBER VALIDATION
DATE : 26/02/2025

Aim :

To validate a mobile number using PHP regex.

Procedure :
Program :

<?php
$phone = "9898203462";
if (preg_match('/^[0-9]{10}$/', $phone)) {
echo "Valid Phone Number";
} else {
echo "Invalid Phone Number";
}
?>

Output :
Valid Phone Number

Result :

The program is executed successfully.


EXP NO : 14 CRUD OPERATIONS IN PHP WITH MYSQL
DATE : 05/03/2025

Aim :

To implement Create, Read, Update, and Delete (CRUD) operations using


PHP and MySQL.

Procedure :
Program :
<?php
// Database Connection
$conn = new mysqli("localhost", "root", "", "newDB");
if ($conn->connect_error) {
die("Connection failure: " . $conn->connect_error);
}

// Create Table
$sql = "CREATE TABLE IF NOT EXISTS employees (
id INT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50) NOT NULL
)";
if ($conn->query($sql) === TRUE) {
echo "Table created successfully.<br>";
} else {
echo "Error creating table: " . $conn->error . "<br>";
}

// Insert Data
$sql = "INSERT INTO employees (id, firstname, lastname, email)
VALUES (1, 'Ram', 'Singh', '[email protected]')
ON DUPLICATE KEY UPDATE firstname='Ram', lastname='Singh', email='[email protected]'";
if ($conn->query($sql) === TRUE) {
echo "Record inserted successfully.<br>";
} else {
echo "Error inserting record: " . $conn->error . "<br>";
}

// Retrieve All Data


$sql = "SELECT * FROM employees";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "Retrieved data successfully:<br>";
while ($row = $result->fetch_assoc()) {
echo "ID: " . $row["id"] . " | Name: " . $row["firstname"] . " " . $row["lastname"] . "
| Email: " . $row["email"] . "<br>";
}
} else {
echo "No records found.<br>";
}

// Update Data
$sql = "UPDATE employees SET email='[email protected]' WHERE id=1";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully.<br>";
} else {
echo "Error updating record: " . $conn->error . "<br>";
}

// Delete Data
$sql = "DELETE FROM employees WHERE id=1";
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully.<br>";
} else {
echo "Error deleting record: " . $conn->error . "<br>";
}

// Close Connection
$conn->close();
?>
Output :

Table created successfully.


Record inserted successfully.
Retrieved data successfully.
Record updated successfully.
Record deleted successfully.

Result :

The program is executed successfully.


EXP NO : 15 READ AND PRINT A STRING IN PHP
DATE : 19/03/2025 (CLI MODE)

Aim :

To take user input in CLI mode using readline() and display the entered string.

Procedure :
Program :

<?php

// Taking input from user in CLI mode


$a = readline('Enter a string: ');

// Printing the input


echo "You entered: " . $a;

?>

Output :
Enter a string: Hello World
You entered: Hello World

Result :

The program is executed successfully.


EXP NO : 16 FACTORIAL CALCULATION USING
DATE : 21/03/2025 A WEB INTERFACE

Aim :

To develop a web-based PHP program that calculates the factorial of a given


number using an HTML form.

Procedure :
Program :

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Factorial Calculator</title>
<style>
body { font-family: Arial, sans-serif; text-align:
center; background: lightgray; }
.container { background: white; padding: 20px;
border-radius: 10px; width: 300px; margin: auto; margin-top:
50px; box-shadow: 2px 2px 10px gray; }
input, button { padding: 8px; margin-top: 10px;
border: none; border-radius: 5px; }
button { background: green; color: white; cursor:
pointer; }
</style>
</head>
<body>
<div class="container">
<h2>Factorial Calculator</h2>
<form method="post">
<input type="number" name="num"
placeholder="Enter a number" required>
<button type="submit"
name="submit">Calculate</button>
</form>
<?php
if (!empty($_POST["num"])) {
function fact($n) { return ($n <= 1) ? 1 :
$n * fact($n - 1); }
echo "<h3>Factorial: " . fact($_POST["num"])
. "</h3>";
}
?>
</div>
</body>
</html>
Output :

Result :

The program is executed successfully.

You might also like