أخر الاخبار

حل اسئلة ويب متقدم قسم الحاسوب الجامعة المستنصرية نموذج رقم1

 حل اسئلة ويب متقدم قسم الحاسوب الجامعة المستنصرية نموذج رقم1

حل اسئلة ويب متقدم قسم الحاسوب الجامعة المستنصرية نموذج رقم1



Q1) chose the correct answer: [25 Marks]

1 -Which of the following type of variables are sequences of characters, like 'PHP supports

string operations.'?

A - Strings B- - Arrays C - Objects D - Resources

2 Which of the functions is used to sort an array in descending order?

A- sort() B- asort() C- rsort() D- dsort()

3-What will be the output of the following PHP code?

< ?php

$fruits = array ("mango", "apple", "pear", "peach");

$fruits = array_flip($fruits); echo

($fruits[0]);

?>

A. mango B. Error C. peach D. 0

4 If else through a block of code as long as the specified condition is true

 A-True B- false

5 The type of PHP language is ----------

A- Tightly typed language B- Loosely typed language C- Server typed language

D- Client typed language

6 Which of the following function is used to get length of a string?

A - Size () B - strlen() C - length D - None of the above.

7 Which one of the following function is capable of reading a file into a string variable?

A. file_contents() B. file_get_contents() C. file_content() D. file_get_content()

8 Which one of the following is the right way of defining a function in PHP?

A. function { function body }

B. data type functionName(parameters) { function b}ody}

C. functionName(parameters) { function body }

D. function fumctionName(parameters) { function body }

9- Which of the following PHP functions can be used to get the current memory usage?

A. get_usage() B. get_peak_usage() C. get_memory_usage()

D. get_memory_peak_usage()

10-Which of the following variable is used to generate random numbers using PHP?

A - srand() B - rand() C - random() D - None of the above.

11 How will you concatenate two strings?

A - Using. Operator. B - Using + operator. C - Using add() function D - Using

append() function

12 Which of the following is an associative array of variables passed to the current script via

HTTP cookies?

A - $GLOBALS B - $_SERVER C - $_COOKIE D - $_SESSI

13 What’s the output

$string="Morning";

echo strlen ($string);

A- 2 B- 4 C-5 D- 6? is correct 7

14 Which of the following is correct about determine the "truth" of any value not already

of the Boolean type?

A - If the value is an array, it is false if it contains no other values, and it is true otherwise. For

an object, containing a value means having a member variable that has been assigned a

value.

B - Valid resources are true (although some functions that return resources when they are

successful will return FALSE when unsuccessful).

C - Don't use double as Booleans.

D - All of the above

15 PHP supports a wide range of databases in web?

A- True B- false

16 PHP’s numerically indexed array begin with position .

A- -1 B- 0 c- 1 D- 2

17 String Value must be include in

A- single quotes B- double quotes C- A and B D- no one of all

18- this is $ reference to the calling object

A. T B. F

19 GET may be used for sending

A-non-sensitive data B- sensitive data C- both D- no one

20 -Which of the following is not true

A.PHP can be used to develop web applications. B. PHP makes a website dynamic

C. PHP applications cannot be compiler D. PHP cannot be embedded into html.

21 Which one of the following should not be used while sending passwords or other sensitive information?

A-GET B- POST C- REQUEST D- NEXT

22 in post method the result at given moment cannot to

A- saved B- move C- bookmark D- Delete

23 ASP is the web page design programs

A. T B. F

24 String Concatenation Operator is connect three or four variables together

A. T B. F

25 The out put of the code is

<?php

echo strlen("Hello world!");

?>

A- 10 B-11 c-12 D- no one


Q2) Answer A & B question [5 marks]

A- whats the output of the program ?

PHP
<?php
$array = [
  [1, 2],
  [3, 4],
];

foreach ($array as $innerArray) {
  echo $innerArray[0] . "\n"; 
}
?>

Sol//

This code will output:

1
3


B- How do you write "good morning" in PHP?

Sol//

  1. Using Double Quotes:
PHP
<?php
echo "Good morning";
?>
  1. Using Single Quotes:
PHP
<?php
echo 'Good morning';
?>

Both approaches produce the same output:

Good morning


Q3) Answer A & B question

A- Give the syntax statement to give the below: [7 marks]

1- True if both $x and $y are true

2- True if either $x or $y is true, but not both 

3- True if either $x or $y is true

4- Appends $txt2 to $txt1

5- Returns true if $x and $y have the same key/value pairs 

6- The if Statement

7-Returns true if $x is less than or equal to $y

Sol//

1. True if both $x and $y are true:

if ($x && $y) {
} 

  • 2. True if either $x or $y is true, but not both:
if ($x xor $y) {
    // statements
}


  • 3. True if either $x or $y is true:
if ($x || $y) {
    // statements
}

  • 4. Appends $txt2 to $txt1:
$txt1 .= $txt2;
  • 5. Returns true if $x and $y have the same key/value pairs (equivalent to PHP 7+ strict comparison):
if ($x === $y) {
}
  • 6. The if Statement:
if (condition) {
    // statements
}


7. Returns true if $x is less than or equal to $y:

if ($x <= $y) {    // statements}


B- Whats the Interactive contaxt explain it and give example.

Sol//

The interactive context in PHP refers to the environment where PHP scripts are executed interactively, allowing developers to execute PHP code directly from the command line interface (CLI) without the need to create a separate script file. It provides a convenient way to test small code snippets, debug code, and experiment with PHP features without the overhead of creating and running a full script.

To enter the interactive context, you can use the PHP interactive shell by running the `php -a` command in your terminal or command prompt. Once in the interactive shell, you can type PHP code directly, and it will be executed immediately.

Here's an example:

$ php -a Interactive mode enabled php > echo "Hello, world!"; Hello, world! php > $x = 10; php > echo $x * 2; 20 php > exit $

In this example, we entered the PHP interactive shell using the `php -a` command. We then executed some PHP code interactively: we echoed a greeting, assigned a value to a variable `$x`, and performed a simple arithmetic operation. Finally, we exited the interactive shell by typing `exit`.


Q4) answer the A & B

A- What the loop statements define it and give example of each one? [ 4 marks]

Sol//

Loop statements are a fundamental programming construct that allow you to execute a block of code repeatedly until a certain condition is met. Here's a breakdown of the commonly used loop statements in PHP:

1. for Loop:

  • Definition: Used to iterate a specific number of times based on an initialization, condition, and increment/decrement expression.
  • Syntax:
PHP
for ($initialization; $condition; $increment/decrement) {
  // Code to be executed repeatedly
}
  • Example:
PHP
for ($i = 0; $i < 5; $i++) {
  echo "The number is: $i\n";
}

This code will print the numbers 0 to 4 (5 times).

2. while Loop:

  • Definition: Executes code repeatedly as long as a specified condition is true.
  • Syntax:
PHP
while ($condition) {
  // Code to be executed repeatedly
}
  • Example:
PHP
$x = 1;
while ($x <= 10) {
  echo "The number is: $x\n";
  $x++; // Increment x by 1
}

This code will print the numbers 1 to 10 (10 times).

3. do-while Loop:

  • Definition: Similar to while, but the code block executes at least once, even if the condition is initially false.
  • Syntax:
PHP
do {
  // Code to be executed repeatedly
} while ($condition);
  • Example:
PHP
$y = 0;
do {
  echo "The number is: $y\n";
  $y++; // Increment y by 1
} while ($y < 5);

This code will print the numbers 0 to 4 (5 times), regardless of the initial value of $y.

4. foreach Loop:

  • Definition: Iterates over elements in an array or an object.
  • Syntax:
PHP
foreach ($array as $value) { // Or: foreach ($object as $key => $value)
  // Code to be executed for each element
}
  • Example:
PHP
$fruits = ["apple", "banana", "orange"];
foreach ($fruits as $fruit) {
  echo "I like to eat $fruit\n";
}


B- The output of program is below, wright the program ?[6 marks]

The product of 10 x 0 is 0

The product of 10 x 1 is 10

The product of 10 x 2 is 20

The product of 10 x 3 is 30

The product of 10 x 4 is 40

The product of 10 x 5 is 50

The product of 10 x 6 is 60

The product of 10 x 7 is 70

The product of 10 x 8 is 80

The product of 10 x 9 i

Sol//

for ($i = 0; $i <= 9; $i++) {
  $product = 10 * $i;
  echo "The product of 10 x $i is $product\n";
}


العملي

A- Q)) Suppose you have the following table:

Name compiler graph math

Ali        90           88        92

Saad     70          85         60

Amel     30         45         52

Fahad   80         75         83

write a program in php to print the rating of each student as following:

the rating of each student is :-

1 : the Marks of the Student Ali is :

compiler : 90

graph : 88

math : 92

The Average is : 90


2 : the Marks of the Student Saad is :

compiler : 70

graph : 85

math : 60

The Average is : 72


3 : the Marks of the Student Amel is :

compiler : 30

graph : 45

math : 52

The Average is : 42


4 : the Marks of the Student Fahad is :

compiler : 80

graph : 75

math : 83

The Average is : 79

END

Sol//

<?php

// Define the student data as an associative array
$students = [
    "Ali" => [
        "compiler" => 90,
        "graph" => 88,
        "math" => 92
    ],
    "Saad" => [
        "compiler" => 70,
        "graph" => 85,
        "math" => 60
    ],
    "Amel" => [
        "compiler" => 30,
        "graph" => 45,
        "math" => 52
    ],
    "Fahad" => [
        "compiler" => 80,
        "graph" => 75,
        "math" => 83
    ]
];

// Function to calculate and display student details
function printStudentMarks($studentName, $studentData) {
    echo "The Marks of the Student $studentName is :\n";

    // Loop through each subject (key) and its mark (value)
    foreach ($studentData as $subject => $mark) {
        echo "$subject : $mark\n";
    }

    // Calculate and display the average
    $total = array_sum($studentData);
    $average = $total / count($studentData);
    echo "The Average is : $average\n\n";
}

// Loop through each student and call the function
foreach ($students as $studentName => $studentData) {
    printStudentMarks($studentName, $studentData);
}

?>

Output:

This code will produce the following output, matching the prompt's requirements:

The Marks of the Student Ali is :
compiler : 90
graph : 88
math : 92
The Average is : 90

The Marks of the Student Saad is :
compiler : 70
graph : 85
math : 60
The Average is : 72

The Marks of the Student Amel is :
compiler : 30
graph : 45
math : 52
The Average is : 42

The Marks of the Student Fahad is :
compiler : 80
graph : 75
math : 83
The Average is : 79


تعليقات



حجم الخط
+
16
-
تباعد السطور
+
2
-