CS201 MID TERM SOLVED MCQs || PAST PAPERS || GROUP-1 || INTRODUCTION TO PROGRAMMING || VuTech Visit Website For More Solutions www.vutechofficial.blogspot.com …
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.
<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;
?>
KINDLY, DON’T COPY PASTE SUBSCRIBE, SHARE, LIKE AND COMMENTS FOR MORE UPDATES SEND WHATSAPP OR E-MAIL FOR ANY QUERY 0325-6644800 kamranhameedvu@gmail.com Visit Website For More Solutions www.vutechofficial.blogspot.com
We provide Virtual University of Pakistan Study Materials such as Solution of Assignments, GDBs, Mid Term Solved Papers, Final Term Solved Papers, Mid Term Solved MCQs, and Final Term Solved MCQs. We also provide regular Semester Quizzes, Updated Handouts, and Short Questions and Answers. We help you with your research and many other educational-related topics, as far as we know. Furthermore, Share your problem with us and Please feel free to ask any related questions.