Assignment Endsem
Assignment Endsem
Expected Output:
****
* *
* *
****
*
*
*
<?php
$height = 7;
$width = 5;
?>
<?php
$rows = 10;
$cols = 10;
?>
Q.3:- Write a PHP script to remove nonnumeric characters except comma and dot.
Sample string : '$123,34.00A'
Expected Output : 12,334.00
<?php
$string = '$123,34.00A';
$cleanedString = preg_replace('/[^0-9,.]/', '', $string);
echo $cleanedString; // Output: 123,34.00
?>
Q.4:- Write a PHP program to check which number nearest to the value 100
among two given integers. Return 0 if the two numbers are equal.
<?php
function nearestTo100($num1, $num2) {
if ($num1 == $num2) {
return 0;
}
// Sample inputs
$inputs = [
[78, 95],
[95, 95],
[99, 70]
];
Sample Input: { 1, 2, 0, 3, 5, 7, 0, 9, 11 }
Sample Output: New array: 0,0,1,3,5,7,2,9,11
<?php
function shiftZerosToLeft($arr) {
$zeros = array_filter($arr, function($value) {
return $value === 0;
});
<?php
class Vehicle {
public $brand;
public $model;
public $year;
<?php
class Student {
public $name;
public $age;
public $grade;
Q.8:- An array contains a set of 5 words. Write Javascript to reverse each word
and arrange the resulting words in alphabetical order. Make use of array
functions.
console.log(reversedWords);
Q.9:- Selection for an army camp for boys is based on the following criteria.
i) Age group – 18 to 25
ii) Height - >=160cms
iii) Weight – 60Kgs SC/St students are given a relaxation of 5cms height & 5kgs
weight.
Accept the necessary details through form, do necessary validations and prepare
selection list using PHP.
Index.html
<!DOCTYPE html>
<html>
<head>
<title>Army Camp Selection</title>
</head>
<body>
<h2>Army Camp Selection</h2>
<form action="selection.php" method="post">
Age: <input type="number" name="age" required><br><br>
Height (in cms): <input type="number" name="height" required><br><br>
Weight (in kgs): <input type="number" name="weight" required><br><br>
Category:
<select name="category" required>
<option value="">Select Category</option>
<option value="General">General</option>
<option value="SC/ST">SC/ST</option>
</select><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Selection.php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$age = $_POST["age"];
$height = $_POST["height"];
$weight = $_POST["weight"];
$category = $_POST["category"];
Que. 10
<html>
<head>
<title>Registration Form</title>
<script>
function showPassword() {
var x = document.getElementById("password");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
</head>
<body>
<h2>Registration Form</h2>
<form method="post" action="process.php">
<fieldset>
<legend>Name and Address</legend>
<label for="ssn">SSN:</label>
<input type="text" id="ssn" name="ssn" required><br><br>
<label for="fullname">Full Name:</label>
<input type="text" id="fullname" name="fullname" required><br><br>
<label for="street">Street and Number:</label>
<input type="text" id="street" name="street" required><br><br>
<label for="postal_code">Postal Code:</label>
<input type="text" id="postal_code" name="postal_code" required><br><br>
<label for="city">City:</label>
<input type="text" id="city" name="city" required><br><br>
</fieldset>
<br>
<fieldset>
<legend>Username and Password</legend>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<input type="checkbox" onclick="showPassword()"> Show Password<br><br>
</fieldset>
<br>
<input type="submit" value="Register">
</form>
</body>
</html>
Q.11:- Using Node.js create a web page to read two created files names from user
and combine contents of both in to third one with all contents in Uppercase.
Index.html
<!DOCTYPE html>
<html>
<head>
<title>Combine Files</title>
</head>
<body>
<h2>Combine Files</h2>
<form action="/combine" method="post">
File 1 Name: <input type="text" name="file1" required><br><br>
File 2 Name: <input type="text" name="file2" required><br><br>
<input type="submit" value="Combine">
</form>
</body>
</html>
Server.html
const fs = require('fs');
const express = require('express');
const bodyParser = require('body-parser');
Q.12. Write a PHP script to calculate the difference between two dates. Sample
dates : 1988-12-12, 2024-05-06 .
<?php
$date1 = new DateTime('1988-12-12');
$date2 = new DateTime('2024-05-06');
$interval = $date1->diff($date2);
<?php
$string = '$123,34.00A';
$cleanedString = preg_replace('/[^0-9,.]/', '', $string);
echo $cleanedString; // Output: 12,334.00
?>