A. Write a PHP script to calculate the area of a rectangle using arithmetic operators.
$length = 10;
$width = 5;
$area = $length * $width;
echo "Area of rectangle: $area\n";
Area of rectangle: 50
B. Implement a script that converts currency from one denomination to another using arithmetic operators.
$usd = 100;
$conversion_rate = 0.88;
$eur = $usd * $conversion_rate;
echo "Equivalent in EUR: $eur\n";
Equivalent in EUR: 88
A. Track the progress of a fundraising campaign by updating the donation total dynamically using combined assignment operators.
$total_donation = 500;
$new_donation = 50;
$total_donation += $new_donation;
echo "Total donation: $total_donation\n";
Total donation: 550
B. Implement a voting system where candidate votes are incremented based on user input.
// B. Voting system
$candidate1_votes = 100;
$candidate2_votes = 80;
$user_vote = 1;
$candidate1_votes += $user_vote;
echo "Candidate 1 votes: $candidate1_votes\n";
Candidate 1 votes: 101
A. Compare the performance of two athletes in a race and determine the winner using comparison operators.
$athlete1_time = 9.81;
$athlete2_time = 9.79;
$winner = ($athlete1_time < $athlete2_time) ? "Athlete 1" : "Athlete 2";
echo "Winner: $winner\n";
Winner: Athlete 2
B. Evaluate the efficiency of two algorithms based on their execution times using comparison operators.
$algorithm1_time = 20;
$algorithm2_time = 15;
$faster_algorithm = ($algorithm1_time < $algorithm2_time) ? "Algorithm 1" : "Algorithm 2";
echo "Faster algorithm: $faster_algorithm\n";
Faster algorithm: Algorithm 2
A. Calculate the factorial of a number using postfix increment/decrement operations.
$n = 5;
$factorial = 1;
for ($i = 1; $i <= $n; $i++) {
$factorial *= $i;
}
echo "Factorial of $n: $factorial\n";
Factorial of 5: 120
B. Simulate the movement of a vehicle along a track using prefix increment/decrement operations.
$position = 0;
$distance = 10;
$position += $distance;
echo "Final position of vehicle: $position\n";
Final position of vehicle: 10
A. Determine eligibility for a discount based on purchase amount and customer loyalty using logical operators.
// A. Determine discount eligibility
$purchase_amount = 150;
$loyalty_member = true;
$eligible_discount = ($purchase_amount > 100 && $loyalty_member) ? "Eligible" : "Not eligible";
echo "Discount eligibility: $eligible_discount\n";
Discount eligibility: Eligible
B. Design a decision-making system for a chatbot to respond to user queries using logical operators.
$user_query = "weather";
$response = ($user_query == "weather") ? "Today's weather is sunny." : "I don't understand your
query.";
echo "Chatbot response: $response\n";
Chatbot response: Today's weather is sunny.