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; )
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_rate;)
Solution
A.Output
A.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;)
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;)
Solution
A.Output
A.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.)
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.)
Solution
A.Output
A.A. Calculate the factorial of a number using postfix increment/decrement operations. Display the factorial. (Calculate factorial: Use a loop to multiply numbers.)
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.)
Solution
A.Output
A.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.)
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.)
Solution
A. echo "Customer is eligible for a discount.";
} else {
echo "Customer is not eligible for a discount.";
}
B.
$user_query = "What is the weather like today?";
$response = strpos($user_query, "weather") !== false ? "It's sunny." : "I'm sorry, I don't understand your query.";
echo $response;
Output
A.© 2024 Ceejay Nilles. All rights reserved.