Program A. Write a PHP script to calculate the area of a rectangle using arithmetic operators. Display the result.(area of a rectangle: $area = $length * $width;)
$length = 10;
$width = 5;
$area = $length * $width;
echo "$area"
Program B. Implement a script that converts currency from one denomination to another using arithmetic operators. Display the converted amount.
(Convert currency: $converted_amount = $amount * $conversion)
$amount = 10;
$conversion_rate = 56.21;
$converted_amount = $amount * $conversion_rate;
echo "Equivalent in dollar: $converted_amount";
Program A. Track the progress of a fundraising campaign by updating the donation total dynamically using combined assignment operators.
Display the updated total.
(Track fundraising: $total_donation += $new_donation)
$total_donation = 0;
$new_donation = 500;
$total_donation += $new_donation;
echo "Track fundraising: $total_donation"
Program B. Implement a voting system where candidate votes are incremented based on user input. Display the final vote count for each candidate.
(Voting System: $candidate_votes +=$user_vote;)
$candidate_votes = 5;
$user_vote = 1;
$candidate_votes += $user_vote;
echo "$candidate_votes";
Program A. Compare the performance of two athletes in a race and determine the winner using comparison operators. Display the result. (Compare athlete times: Use '<' to compare times.)
$athlete1 = 6.70;
$athlete2 = 9.10;
$winner = ($athlete1>$athlete2)?"Athlete 1" : "Athlete 2";
echo "Winner: $winner";
Program B. Evaluate the efficiency of two algorithms based on their execution times using comparison
operators. Display the more efficient algorithm. (Evaluate algorithm efficiency: Use '<' to
compare times.)
$algorithm1 = 40;
$algorithm2 = 20;
$fastAlgorithm = ($algorithm1 < $algorithm2) ? "Algorithm 1 is faster" : "Algorithm 2 is faster";
echo "$fastAlgorithm";
Program A. Calculate the factorial of a number using postfix increment/decrement operations. Display the factorial. (Calculate factorial: Use a loop to multiply numbers.)
$x = 4;
$factorial = 1;
for ($i = 1; $i <=$x; $i++){
$factorial *=$i;
} echo "$x! = $factorial";
Program B. Simulate the movement of a vehicle along a track using prefix increment/decrement
operations. Display the final position of the vehicle. (Simulate vehicle movement: Use += for
forward movement.)
$position = 0;
$end = 50;
$position += $end;
echo"Final position of the vehicle is: $position";
Program A. Determine eligibility for a discount based on purchase amount and customer loyalty using logical operators. Display whether the customer is eligible for a discount. (Determine discount eligibility: Use && to check conditions.)
$amount = 290;
$membership = true;
$discount = ($amount > 200 && $membership) ? "Eligible for discount" : "Not eligible for discount";
echo "$discount";
Program B. Design a decision-making system for a chatbot to respond to user queries using logical
operators. Display the appropriate response based on the query. (Chatbot decision-making: Use ?
: for simple conditions.)
$query = "Good Morning";
$response = ($query == "Good Morning") ? "Good Morning" : "It's morning";
echo "$response";