New Lab Report 2024 Unit2
New Lab Report 2024 Unit2
Instructions:
Create your new repository on GitHub and push your lab solution to GitHub with new
branch for each lab set.
Share your repository to instructor.basanta@gmail.com as a collaborator.
Print and attach your updated GitHub screenshot into lab set
Format
● Cover (Print)
● GitHub Screenshot
● Lab Question –hand written
● Introduction –hand written
● Syntax and Format –hand written
● Code –hand written
● Output(Print)- With full URL
Lab-1
1. Write a PHP program to create variable with different datatypes,
a. Print all the data using echo and print
b. Display content of array using print_r and var_dump
c. Display result of checking data types.
2. Calculate area of circle taking radius input and defining value of PI as constant value.
3. Write a function that takes an integer minutes and converts it to seconds.
4. Create a function that takes two numbers as arguments and returns their sum.
5. Write a function that takes the base and height of a triangle and return its area.
6. Create a function that takes the age in years and returns the age in days.
7. Create a function that takes voltage and current and returns the calculated power.
8. A farmer is asking you to tell him how many legs can be counted among all his animals.
The farmer breeds three species:
chickens = 2 legs
cows = 4 legs
pigs = 4 legs
Write PHP program to calculate total number of legs of all the animals asking input from
user using form.
9. Create a function that takes the number of wins, draws and losses and calculates the
number of points a football team has obtained so far.
wins get 3 points
draws get 1 point
losses get 0 points
Write PHP program to calculate total number of point of all the games asking input from
user using form.
10. Create a function that takes two strings as arguments and return
either true or false depending on whether the total number of characters in the first string
is equal to the total number of characters in the second string.
11. Create a function that returns true if an integer is evenly divisible by 5,
and false otherwise.
12. Write a function that returns the length of a string. Make your function recursive.
13. Write a function that accepts base (decimal), height (decimal) and shape ("triangle",
"parallelogram") as input and calculates the area of that shape.
14. Create a function that takes an array and a string as arguments and returns the index of
the string.
15. Given an index and an array, return the value of the array with the given index.
16. A typical car can hold four passengers and one driver, allowing five people to travel
around. Given n number of people, return how many cars are needed to seat everyone
comfortably.
17. Write a PHP program to compute the sum of the two given integer values. If the two
values are the same, then returns triple their sum.
18. Write a PHP program to get the absolute difference between n and 51. If n is greater than
51 return triple the absolute difference.
19. Write a PHP program to create a new string where 'if' is added to the front of a given
string. If the string already begins with 'if', return the string unchanged.
Sample Input:
"if else"
"else"
"if"
Sample Output:
if else
if else
if
20. Write a PHP program to create a new string which is 4 copies of the 2 front characters of
a given string. If the given string length is less than 2 return the original string.
Sample Input:
"C Sharp"
"JS"
"a"
Sample Output:
CCCC
JSJSJSJS
a
21. Write a PHP program to create a new string with the last char added at the front and back
of a given string of length 1 or more.
Sample Input:
"Red"
"Green"
"1"
Sample Output:
dRedd
nGreenn
111
22. Write a PHP program to create a new string taking the first 3 characters of a given string
and return the string with the 3 characters added at both the front and back. If the given
string length is less than 3, use whatever characters are there.
Sample Input:
"Python"
"JS"
"Code"
Sample Output:
PytPythonPyt
JSJSJS
CodCodeCod
23. Write a PHP program to check the largest number among three given integers.
24. Write a PHP program to convert the last 3 characters of a given string in upper case. If
the length of the string has less than 3 then uppercase all the characters.
Sample Input:
Nepal
Npl
Bca
Bachelor
Sample Output:
NePAL
NPL
BCA
BacheLOR
25. Write PHP Script to display following array into HTML table.
$info = [ 'name' => 'Ram Bahadur', 'address' => 'Lalitpur','email' => 'info@ram.com',
'phone' => 98454545,'website' => 'www.ram.com'];
Name Ram Bahadur
Address Lalitpur
Email info@ram.com
Phone 98454545
Website www.ram.com
26. Write PHP Script to display student mark sheet into table, store data into PHP
multidimensional array.
27. Write PHP Script to create and validate login form with username and password.
28. Write PHP Script to create and login form to implement session and cookie.
29. Write PHP script to upload CV with following details:
a. File type: PDF & DOCS
b. File size less than 1 MB
30. Write PHP script to upload Profile Image with following details:
a. File type: PNG & JPEG
b. File size less than 500 KB
31. Write a PHP script to validate and register (store) user with following data.
a. Username with minimum 8 character
b. Valid email Address
c. Validate Date of Birth
d. Valid phone length
32. Write a PHP Script to validate, store, list, and update and delete record from database
using MySQL database with following fields.
a. id,name,rank,status,image,created_by,updated_by,created_at,updated_at
33. Write PHP program to perform CRUD operation for the following tables.
courses
id
title
duration
status
created_at
updated_at
students
id
name
course_id (use foreign key)
fee
rollno
phone
address
dob
status
created_at
updated_at
34. Wrote PHP Script to take user marks using form and generate mark sheet when user input
all data. (Please look at last page for mark sheet format)
35. Write PHP script to calculate simple interest using form.
36. Write PHP script to calculate tax using form.
Married
annual income > 450000 and <= 550000 extra 10% tax for 100000
annual income > 550000 and <= 750000 extra 20% tax for 200000
annual income > 750000 and <= 1300000 extra 30% tax for 550000
annual income > 1300000 extra 35% tax for remaining amount
Un-married
annual income > 400000 and <= 500000 extra 10% tax for 100000
annual income > 500000 and <= 750000 extra 20% tax for 250000
annual income > 750000 and <= 1300000 extra 30% tax for 550000
annual income > 1300000 extra 35% tax for remaining amount
If gender is female