Page 343 - Computer Software Application TP - Volume 1
P. 343

COMPUTER SOFTWARE APPLICATION - CITS



                {
                       return new ArrayIterator($this->users);
                 }
              }

              $userCollection = new UserCollection($users);
              foreach ($userCollection as $user)
              {
                 echo $user->name . “ (“ . $user->age . “)” . PHP_EOL;
              }
                       ?>

              </body>
              </html>
           3  Save the program in C:\Apache24\htdocs in a folder with .php extension
           4  Run the Apache services from windows services

           5  Open the browser and type the following address
              http://localhost/foldername/
           6  Click the php file to run and verify the output












           1  Provide an example of a class constants be accessed from outside the class definition in PHP.
           2  Create a ‘Person’ class with attributes like ‘name’ and ‘age’. Create a ‘Student’ subclass that inherits from
              Person and adds a ‘studentID’ attribute. Instantiate a Student object and access its superclass attributes
              along with the subclass attribute.
           3  Create an abstract class ‘Animal’ with an abstract method ‘makeSound()’. Create concrete subclasses ‘Cat’
              and ‘Dog’ that extend Animal and implement the makeSound() method to produce different sounds for each
              animal. Call the makeSound() method for a Cat and a Dog object.
           4  Create a class ‘Product’ with properties like ‘name’, ‘price’, and ‘quantity’. Serialize an object of this class into
              a string using PHP’s serialization mechanism.

           5  Create a function that reads data from a file, use PHP exceptions to handle errors such as file not found or
              insufficient permissions while reading the file.
           6  Create an array of product objects representing items in a shopping cart. Use the ArrayIterator class in PHP
              to iterate over this array and calculate the total cost of all items in the shopping cart.

















                                                           328
                               CITS : IT & ITES - Computer Software Application - Exercise 60
   338   339   340   341   342   343   344   345   346   347   348