Problem 1-A: Calculate the area of a rectangle


Description:

Write a PHP script to calculate the area of a rectangle using arithmetic operators. Display the result.

Solution:

$length = 50;
$width = 5;
$area = $length * $width;
echo "The area of the Rectangle is $area"

Output:

The area of the Rectangle is 250


Problem 1-B: Currency conversion


Description:

Implement a script that converts currency from one denomination to another using arithmetic operators. Display the converted amount.

Solution:

$amount = 150;
$conversion_rate = 0.99;
$converted_amount = $amount * $conversion_rate;

echo "A P$amount is $$converted_amount in US Dollars"

Output:

A P150 is $2.7 in US Dollars


Problem 2-A: Track fundraising campaign


Description:

Track the progress of a fundraising campaign by updating the donation total dynamically using combined assignment operators. Display the updated total.

Solution:

$total_donation = 300;
$new_donation = 30;
$total_donation += $new_donation;

echo "The fundraising campaign has $total_donation donations";

Output:

The fundraising campaign has 330 donations


Problem 2-B: Voting system


Description:

Implement a voting system where candidate votes are incremented based on user input. Display the final vote count for each candidate.

Solution:

$candidate1_votes = 91;
$candidate2_votes = 110;

$user_vote = 1;
$user2_vote = 2;

$candidate1_votes += $user_vote;
$candidate2_votes += $user2_vote;

echo "Candidate 1 votes: $candidate1_votes\n
      Canditate 2 votes: $candidate2_votes\n
      Canditate 2 wins!";

Output:

Candidate 1 votes: 92
Canditate 2 votes: 112
Canditate 2 wins!


Problem 3-A: Compare athlete performance


Description:

Compare the performance of two athletes in a race and determine the winner using comparison operators. Display the result.

Solution:

$athlete1= 10.51;
$athlete2 = 9.11;

$winner;

if($racer1 < $racer2){
    $winner = "Athlete 1";
}else{
    $winner = "Athlete 2";
}

echo "$winner wins in $athlete2 seconds";

Output:

Athlete 2 wins in 9.11 seconds


Problem 3-B: Evaluate algorithm efficiency


Description:

Evaluate the efficiency of two algorithms based on their execution times using comparison operators. Display the more efficient algorithm

Solution:

$algorithm1= 3;
$algorithm2 = 5;

$winner;

if($algorithm1 < $algorithm2){
    $winner = "Algorithm 1";
}   else{
    $winner = "Algorithm 2";
}

echo "$winner is the faster algorithm\n
       Time: $algorithm1 n";

Output:

Algorithm 1 is the faster algorithm
Time: 3 n


Problem 4-A: Calculate factorial


Description:

Calculate the factorial of a number using postfix increment/decrement operations. Display the factorial.

Solution:

$nNumber = 5;
$factorial = 1;

for($i = 1;$i <= $nNumber; $i++){
    $factorial *= $i;
}

echo "The factorial of $nNumber is $factorial";

Output:

The factorial of 5 is 120


Problem 4-B: Simulate vehicle movement


Description:

Simulate the movement of a vehicle along a track using prefix increment/decrement operations. Display the final position of the vehicle.

Solution:

$position = 0;
$distance = 10;

$forward = $position += ++$distance;

echo "Previous Position: $previous
Final Position: $forward";

Output:

Previous Position: 10
Final Position: 11


Problem 5-A: Determine discount eligibility


Description:

Determine eligibility for a discount based on purchase amount and customer loyalty using logical operators. Display whether the customer is eligible for a discount.

Solution:

$purchaseAmount = 100;
$loyaltyMember = true;

$discountReal = ($purchaseAmount >= 100 && $loyaltyMember == true) ? "Yes, I am eligible for discount" : "No, I'm not eligible for discount";

echo "Are you eligible for discount? $discountReal";

Output:

Are you eligible for discount? Yes, I am eligible for discount


Problem 5-B: Chatbot decision-making


Description:

Design a decision-making system for a chatbot to respond to user queries using logical operators. Display the appropriate response based on the query.

Solution:

$userQuery = "location";
$response = ($userQuery == "location") ?"We are in the Philippines": "I don't know that.";

echo "User Query: $userQuery\nChatbot Response: $response ";    

Output:

User Query: location
Chatbot Response: We are in the Philippines