CS310 ASSIGNMENT NO. 1 SPRING 2023 || 100% RIGHT SOLUTION || OPEN SOURCE WEB APPLICATION DEVELOPMENT || BY VuTech
Visit Website For More Solutions
www.vutechofficial.blogspot.com
KINDLY, DON’T COPY PASTE
QUESTION-1
Write a program to build a calculator using PHP. The calculator will use variables to store input values and then apply given arithmetic operations on input values then display the calculation results using these variables. Use echo statements to display the result of your calculations.
Arithmetic
Operations:
1. Division
Operation
2. Multiplication
Operation
3. Addition
Operation
4. Subtraction
Operation
SOLUTION
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
</head>
<body>
<h2>Calculator</h2>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="number" name="num1" required placeholder="Enter number 1">
<br><br>
<input type="number" name="num2" required placeholder="Enter number 2">
<br><br>
<select name="operator">
<option value="divide">Division</option>
<option value="multiply">Multiplication</option>
<option value="add">Addition</option>
<option value="subtract">Subtraction</option>
</select>
<br><br>
<input type="submit" value="Calculate">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$operator = $_POST['operator'];
if ($operator == "divide") {
$result = $num1 / $num2;
echo "The division of $num1 and $num2 is: " . $result;
} elseif ($operator == "multiply") {
$result = $num1 * $num2;
echo "The multiplication of $num1 and $num2 is: " . $result;
} elseif ($operator == "add") {
$result = $num1 + $num2;
echo "The addition of $num1 and $num2 is: " . $result;
} elseif ($operator == "subtract") {
$result = $num1 - $num2;
echo "The subtraction of $num2 from $num1 is: " . $result;
}
}
?>
</body>
</html>
QUESTION-2
Write a program using PHP in which you will store Your Student ID in a variable as string and apply following operations on student id using string manipulation functions and then print their result on screen.
- Length of student id
- Calculate the number of words in string.
- Reverse the string.
SOLUTION
<?php
$studentID = "YourStudentID12345"; // Replace with your actual student ID
// 1. Length of student ID
$length = strlen($studentID);
// 2. Calculate the number of words in the string
$wordCount = str_word_count($studentID);
// 3. Reverse the string
$reversedID = strrev($studentID);
// Print the results
echo "Length of student ID: " . $length . "<br>";
echo "Number of words in string: " . $wordCount . "<br>";
echo "Reversed student ID: " . $reversedID;
?>