Final Exam Solutions

Greetings students,

Below are PDF documents that you can download which show the solutions to questions on the examination. Since nobody will be taking the test late, I am able to post them immediately.

Keep in mind that the solutions and scenarios listed on these documents aren’t the only solutions to questions, and I will use the best judgment possible, along with common sense, when grading your hard work.

If you have any questions or concerns, please let me know.

Final Exam Practice Test

Greetings, students. This is the final Exam Practice Test. The actual exam will have 10 questions, whereas this practice test contains only five.

  • When completing this practice test, try to answer the questions without using online resources, since you will not be allowed to use a computer during the actual exam.
  • You may want to have a few sheets of (good ol’ fashioned) pencil and paper handy, since you’ll be completing the examination on paper.

Refer to the study guide for topics that you should be familiar with before beginning this test.

If you have any questions, please let me know.

Practice Test

  • Question #1:

Fill in the blanks:

    • A _____________________ is preceded by a dollars sign ($) symbol and stores a value.
    • If/Else and If/Else/Elseif are examples of _____________________ statements.
    • Operations consist of ____________________, which manipulate ________________.
  • Question #2:

Write a function that accepts two arguments, and then performs the following operations on the variables:

    1. Test if the arguments are a string of at least two characters
    2. Concatenate the two strings together (in order)
    3. Reverse the string (strrev())
    4. If the string is longer than ten characters, convert it to lowercase (strtolower())
    5. If not, convert it to upper case (strtoupper())
    6. Return the result
  • Question #3:

Analyze the following code, and write what the HTML output will be:


<?php

function fixNumber($input)
{
  if (!is_numeric($input)  || strlen($input) < 4)
    return $input;

  //sttrev() reverses the string
  $input = strrev($input);

  $x = 3;

  while($x < strlen($input))
  {
    $beforeComma = substr($input, 0, $x);
    $afterComma = substr($input, $x);

    $input = $beforeComma . "," . $afterComma;

    $x+=4;
  }

  //strrev() reverses the string (again)
  $input = strrev($input);

  return $input;
}

$states = array();
$states["Georgia"] = array("Capital" => "atlanta", "sqMiles" => 59425);
$states["Florida"] = array("Capital" => "tallahassee", "sqMiles" => 65795);
$states["Virginia"] = array ("Capital" => "richmond", "sqMiles" => 42774);
$states["Maine"] = array("Capital" => "augusta", "sqMiles" => 33414);

ksort($states);

foreach($states as $stateName => &$stateStats)
{  $stateStats["sqMiles"] = fixNumber($stateStats["sqMiles"]);  }

echo "<ul>";

foreach($states as $stateName => $stateInfo)
{
  echo "<li><strong>$stateName</strong> <em>(". ucfirst($stateInfo["Capital"]) .")</em> -
  {$stateInfo["sqMiles"]}</li>";
}

echo "</ul>";

?>
  • Question #4:

Below is the HTML code for a form. Study it closely:


<form name="myForm" method="post" action="processme.php">

  <h1>What is your favorite food?</h1>

  <p>Name <input type="text" name="userName" /></p>
  <p>Age <input type="text" name="age" /></p>
  <p>Favorite Food <input type="text" name="favFood" /></p>
  <p>Pass Phrase <input type="password" name="userName" /></p>

</form>

Write PHP code that processes the form. Adhere to the following specifications:

    1. Validate the input. All fields are required.
    2. If there are any missing fields, use die() to terminate the script.
    3. Print the name of each field using an ordered list (<ol>).
  • Question #5:

Identify four problems that will cause parse errors within the script:


<?php

function printNotice($notice == null)
{
  /Print any notices
  if ($notice == null && isset($_GET["notice"]))
    $theNotice = $GET["notice"];

  elseif ($notice == null & isset($_POST["notice"]))
    $theNotice = $_POST["Notice"];

  elseif($notice !== null)
    $theNotice = $notice;

  if(iset($theNotice))
    echo "<div class=\"notification\">$theNotice</div>";
}

?>

SPOT Evaluations: This Wednesday (Apr 16)

Hi,

I will be handing out the SPOT Evaluation forms in class this Wednesday, April 16 during our last class session.

It is important that you show up on Wednesday and fill out the SPOT evaluation, so that you can provide your input and feedback to the course, and let the College know what you think can be improved with the way that it was taught.

Please try to make it.

Thanks,
Casey

Study Guide for Final

Here is the much-anticipated review for the final exam! Read and understand everything below carefully to ensure that you are prepared. If you have specific questions, feel free to ask me, or drop by class on Monday, April 14.

General Description

The final exam is worth 20% of your grade. It will consist of 10 questions and one extra-credit question. The test will include following types of questions:

  • Fill-in-the-Blank - You will fill in the missing word for a written definition of a PHP concept.
  • Fill-in-the-Blank Code - I will provide code with blanks in it. You will fill in the blanks to complete the code.
  • Analyze Code - I will provide a complete block of code. You will analyze the code, and print the output.
  • Write Code - I will provide a written scenario. You will provide a solution to the scenario by writing PHP code.

Topics to Brush Up On

Here’s everything you need to study up on to be ready for the final exam:

Basic Terminology

Know the definitions of the following terms:

  • Variables
  • Operators
  • Operands
  • Loops
  • Arrays

Basic Programming Techniques

Know how to use:

Arrays

Understand how to use arrays:

Strings

Understand how to use:

Classes/Objects

Understand the following Object-Oriented concepts:

  • Instantiation
  • Encapsulation
  • Methods
  • Properties
  • Public and Private
  • Interface methods

Know how to (see lecture notes from earlier in the term):

  • Code a class
  • Instantiate a class as an object
  • Run a method in a class
  • Make a method or property private
  • Create interface methods

Databases

Understand how to do the following with databases (see lecture notes):

  • Create a database using an SQL tool (like phpMyAdmin)
  • Create tables in a database
  • Create records using the SQL language
  • Update records using the SQL language
  • Retrieve records using SQL SELECT
  • Use WHERE in SQL statements
  • Connect to a MySQL database using PHP
  • Run a SQL query using PHP
  • Process the results of a SQL query into an array using PHP

Files

Understand what the following functions do:

  • Understand how to open a file, read from it, and close it.
  • Understand what modes you can use to open a file.

Input

  • Understand how to access data in the $_GET array
  • Understand how to access data in the $_POST array
  • Understand how to create a $_GET query in the URL address
  • Understand how to send data to PHP from a form using POST

General Announcements

Greetings students,

I’ll see you in lecture today at 3:30. In the meantime, here are some important announcements:

  • No class next Monday — I am moving up Wednesday’s lecture on Web Services to today, and I am moving up next Monday’s lecture on PHP Frameworks to Wednesday. Monday, I will be available in the classroom to answer questions and provide help on the final project, but there will be no lecture.
  • The Review for the Final — Will be posted here, on this website, on Wednesday. It will consist of a study guide and a practice test. If you do well on the practice test, you should be fine on the final exam.

That’s all for now! If you have questions, please let me know.

Lecture Notes: Mar. 31

Greetings, class. Below is a .ZIP file with our little application in it. Feel free to download

Also… Useful Resources