Answer to Question #250209 in Java | JSP | JSF for junior

Question #250209

2.1) What are the two ways to pass arguments to a function? (2) 2.2. Write a PHP script for an array containing 5 elements (Lerato, Thabo, Mbali, Sipho, Buhle) and prints out the following : (4) 2.3. Given the PHP script in 2.2. Print out one element at a time. (2) 2.4. Write a PHP script that checks which category a student belongs to based on the average mark of test 1 and test 2. If the student’s average is greater than 50, it should print out pass and if the student’s average is less than 50, it should print out fail. (5) 2.5. Given the PHP code below. Write a PHP code that will do the following: 2.5.1. Write the HTML code that will display the form. (5) 2.5.2. The form should take input from the user using POST method and display the values in the browser.


1
Expert's answer
2021-10-12T13:50:06-0400

2.1) The two ways to pass to pass the arguments are listed below -

a) Pass by value and b) Pass by reference

Example: Pass by value
void 
        Test(int k ){ 
             k = 5; 
        } 
        int main(){ 
          int y = 23; 
          Test(y); 
          printf("Value of y is %d\n",y);  
          return 0; 
        } 

b) Pass by reference

        void Test( int & k){ 
             k = 5; 
        }
        int main(){ 
          int y = 23; 
          Test(y); 
          printf("Value of y %d\n", y);  
          return 0; 
        } 

21.2

<?php
$txt =  ["Lerato", "Thabo", "Mbali", "Sipho", "Buhle"];
?>

21.3

<?php
$txt =  ["Lerato", "Thabo", "Mbali", "Sipho", "Buhle"];
for($i=0;$i<5;$i++){
echo  $txt[$i].",";
}
?>
21.4
<?php
$marks=60;
if($marks>50){
    echo "pass";
    }else{
    echo "Fail";
    }
?>
21.5

<!DOCTYPE html>
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  Enter Name: <input type="text" name="enterName">
  <input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {   
    $name = $_POST['enterName'];
    if (empty($name)) {
        echo "Name is not entered";
    } else {
        echo $name;
    }
}
?>
</body>
</html>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS