Math 275 FINAL FALL 2012

download Math 275 FINAL FALL 2012

of 19

  • date post

    25-Feb-2018
  • Category

    Documents

  • view

    214
  • download

    0

Embed Size (px)

Transcript of Math 275 FINAL FALL 2012

  • 7/25/2019 Math 275 FINAL FALL 2012

    1/19

    | P a g e

    Faculty Of Computer StudiesM275

    Web Development using PHP and MySQL

    Final Examination- SolutionFall 2012-2013

    Date Saturday January 12, 2013( 2.5) HoursTime Allowed:Number of Exam Pages: 19

    Instructions:

    This exam consists of 3 parts [ Total is 100 Marks ]

    1. Part A [Total marks available is 10] consists of a set of

    multiple choice questions all of which must be answered2. Part B [ Total marks available is 40 ] ; the student should

    .of them4answer any3. Part C Long Coding [Total marks available is 50 ] , The

    .questions2answerstudent should

  • 7/25/2019 Math 275 FINAL FALL 2012

    2/19

    2| P a g e

    PART A [ 10 Marks ] :

    Choose the correct answer [ 2 Mark for each question ] :

    1) _______ types are often returned by functions that deal with external applications or files.

    a. Resourceb. Datac. Nulld. None

    2) PHP provides the function _________ to change the type of a variable.a. gettype()b. settype()c. testtype()d. None.

    3) PHP has both a require() statement, which performs a similar function to ________a. include(), and a require_once() statement.

    b. include()

    c. include_once()d. None

    4) What will be the output from the following code fragment?$test_val = 5.5466;settype($test_val, integer);echo $test_val;

    a. 5.5b. 6

    c. 5d. 4

    5) The MySQL _______________ transform a string into lowercase or uppercase:a. LCASE() and UCASE() functionsb. CASEL() and CASEU() functionsc.

    LCASE()d.

    None

    Part B [ 40 Marks ] : Answer ONLY 4 questions [ 10 Marks for each ] :

    1) a. MySQL checks three things during the authentication process. The actions associated with these threethings are performed in two steps . Detail the two steps . [ 5 marks ]

    Answer :1. MySQL looks at the host you are connecting from and the username andpassword pair that you are using. If your host is allowed to connect, yourpassword is correct for your username, and the username matches oneassigned to the host, MySQL moves to the second step.2. For whichever SQL command you are attempting to use, MySQL verifiesthat you have the ability to perform that action for that database, table,and field.

  • 7/25/2019 Math 275 FINAL FALL 2012

    3/19

    3| P a g e

    b. From a Linux/Unix operating system, how would you get help on configuration options (the options that youpass to the configure script in your PHP distribution)? [5 marks ]

    Answers1. You can get help on configuration options by calling the configure script inthe PHP distribution folder and passing it the --help argument:./configurehelp

    2) Create a calculator script that enables the user to submit two numbers and choose an operation (addition,multiplication, division, or subtraction) to perform on them. [ 10 Marks]

    solution :

    a basic PHP calculator:

  • 7/25/2019 Math 275 FINAL FALL 2012

    4/19

    4| P a g e

    else

    {

    if($_POST[' compute '] == 'add')

    {

    $calc = ($_POST['value1']+$_POST['value2']);

    $op = '+';

    }

    if($_POST[' compute '] == 'subtract')

    {

    $calc = ($_POST['value1']-$_POST['value2']);

    $op = '-';

    }

    if($_POST[' compute '] == 'divide')

    {

    $calc = ($_POST['value1']/$_POST['value2']);

    $op = '/';

    }

    if($_POST[' compute '] == 'multiply')

    {

    $calc = ($_POST['value1']*$_POST['value2']);

    $op = '*';

    }

    echo $_POST['value1'].' '.$op.' '.$_POST['value2'].' = '.$calc;

    }

    ?

  • 7/25/2019 Math 275 FINAL FALL 2012

    5/19

    5| P a g e

    3) Write a PHP script that uses cookie session to create a page counter for a website . [ 10 marks] .

    Title

    4) Create a PHP function works out a 10 percent discount of the total payment by a customer . You onlywant to apply the discount if the customer spent over 100 Dollar if not, don't apply the discount. In bothcases, you want the function to return the answer to your questionWhat do I charge this customer? .Suppose the total payment is initiated to 120 dollar . [10 Marks]

    Answer :

  • 7/25/2019 Math 275 FINAL FALL 2012

    6/19

    6| P a g e

    ?>

    5) The following real-world organizationalchart of a department that has department ID and Name

    indicates a connection between this department and a number of employees . each employee has an ID , FirstName and last name to identify him/her [10 Marks]

    a. State the degree of Department- Employee relationship .b. Draw the table representation showing the degree of the relation and stating the normalization Form of it

    .

    :Solution

    In a one-to-many relationship, keys from one table appear multiple times in asecond normalization formrelated table

    6) a. State the four basic steps to create an Image in PHP . b. Write a PHP script to create an image of simple line graph with the label Sales given that hight andwidth = 200 . [ 10 Marks]Solution :

    1- Creating a canvas image on which to work

  • 7/25/2019 Math 275 FINAL FALL 2012

    7/19

    7| P a g e

    2- Drawing shapes or printing text on that canvas3- Outputting the final graphics

    4- Cleaning up resources .

    Part C : Long Coding Problems [ 50 Marks ] Answer 2 Questions :

    1) What You are going to do for this question is to accept a number from the user. That number willrepresent one of the following:

    The radius of a circle.

    The length of one side of a square.

    The length of one side of an equalateral triangle.The user will specify the number and what it represents and then you will use PHP to calculate the area of thatobject, return the value, and rewrite the form so the user can enter another number and calculate a differentresult [ 25 Marks]Hints :

    Create a form that allows the user to enter a value that is used to calculate the area of a basic geometricshape: a circle, a square, or an equalateral triangle.

    Include a set of radio buttons that allows them to determine which shape they want to calculate the areaof.

    Use PHP to accept the data from the form using a POST method.

    Use PHP to test for legal values.

    Use an if statement in PHP to test for legal values.

    Use a switch statement in PHP to determine which calculation is to be performed. Use PHP to calculate and report on the values.

    Solution :

    Step 1: Our Form

    First thing you can do to get started is open up homework two and save it as hw03.php or whatever you want tocall it. These directions assume the assignment is named hw03.php. The document should have four sections.

  • 7/25/2019 Math 275 FINAL FALL 2012

    8/19

    8| P a g e

    A heading that describes the document. A footer at the bottom containing your name and copyright info.

    A form to enter the information into. An output area to write the output to.

    How you organize these elements is up to you. However, you will make life much easier on yourself if you putthe output area before the form in the code. It means you will be able to do almost all your PHP work in a singlecoding block.

    Here is the code for a simple example of how the form can be put together. I will be working from this model inthe assignment.

    Enter a number here :

    This number is a:
    : the radius of a circle
    : the length of one side of a square
    : the length of one side of an equalateral triangle

    Hopefully, this form should be self-explanatory.

    The PHP Code

    The best way to write the code is to put our output section before our form. That way we can put most of ourPHP code in a single block. So above the form, put in your PHP block.

    Notice that the form has two submit buttons. One is marked "Calculate" and the other is marked "Clear". Thereason for this is that the button marked clear is actually a reset button. Since we will be using PHP to get theform field values to dynamically persist, a regular reset button will not work.

    If the user clicks "Calculate", it perform the calculation, and if they click "Clear" it will reset the form. Thus wewant to start of with a conditional that tests which direction to go with the form.

  • 7/25/2019 Math 275 FINAL FALL 2012

    9/19

    9| P a g e

    The first thing we want in the block is a test for which direction to go in. This test will form the primarystatement in the block. If fact, depending on how you write it, it is the only statement in the block, sinceeverything else is nested within it.

    So how do we test which button was clicked? Well, you will notice that both submit buttons are named "submit".Since pressing a submit button with a name and value will associate that value with the name and send it back tothe server, which just need to determine whether submit equals "Calculate" or "Clear".

    All the form fields submitted by was of the post method are stored by PHP in an array called$HTTP_POST_VARS. So what we have to do is test the value of $HTTP_POST_VARS['submit']. In newerversions of PHP, we can also use the short form of $_POST['submit']. We can test test for the "Clear" value first,since it is less code, then test for "Calculate".

    Let's start with clearing the form, since it is our first statement. How do we clear the form?

    To answer this requires thinking ahead a little. We need to set the value of our text form element to an emptystring, as well as unselect any radio buttons.

    We could work with our array elements directly, but it is good form to leave those as is and assign the values tonew variables internal to the script which are then written back to the form when we are done. So let us come upwith two variables, one for the text box and one