CS637 Practice Final Exam NAME:_________________________
Open books, handouts, solutions, etc., including online docs. Attend class and keep your video on. Submit your solution to Gradescope, or if problems with that, email to me. You can ask short questions during the exam by speaking up, or send me email at elizabeth.oneil@umb.edu. Show all work by editing this document (preferred option), or on separate pages with problems clearly marked and in order. Each problem is worth 20 points, except 6 and 7 are worth 15 points. Total points = 150.
Note that this is too long for an actual final exam, but shows the kinds of problems the real final may have. Note that two problems require drawings, as has the homework, so you should have practice in adding a drawing to your document at the right place. See "Gradescope info" on the class web page under Resources for some pointers.
b. Design a two-page web UI for this app (not counting error pages). For each page specify the user controls (links, buttons, forms, etc.), preferably by using a page flow as we have done in homework 3 and in the slides.
4. Web background
See the our pizza projects for the pizzapie image, in file pizzapie.jpg,
a 100x100 pixel image. Suppose the following HTML file is named
index.html and is located in the test
directory of the
web server’s root directory.
<!DOCTYPE html>
<html>
<head>
<style type = "text/css">
* { margin: 0; padding: 0}
body {
width: 500px;
border: black solid 3px; }
h1 {
background:lightblue;
}
</style>
</head>
<body>
<h1> Pizza Pie </h1>
<img src="pizzapie.jpg" alt="pie" width="100" height="100">
<p>
Here it is again:
<img src="pizzapie.jpg" alt="pie" width="100" height="100">
</p>
</body>
</html>
a. Show the display to proper scale on the screen for this page, in a browser window of 600x600 pixels. Indicate the browser window with a drawn square, and then put the images and appropriate text inside it, with the border. Use cross hatching to show the blue background.
b. Give the sequence of GET commands (one line each, each ending with HTTP/1.1) that occur when you browse to this page.
a. What HTTP command is issued by the browser? Show the whole command line, including any parameters and the HTTP/1.1 at the end.
b. What PHP program processes this HTTP request? Give its name, directory, and page number of its code in the text.
c. Consider the code as it executes in the controller after the user clicks the "Basses" link, until the point it forwards to a view. In particular, give the name and final value of each assigned variable. Include array values (i.e., show the elements, at least their id and name values). Note that the picture on pg. 181 gives you information on the array contents, as does pg. 99.
d. What model calls were involved in the execution you described in c.?
6. Objects
Here is part of cart.php designed to represent a simple shopping cart in a webapp:
<?php
class Cart {
// array of $product_id => $qty
private $itemQty;
// Create an empty cart
function __construct() {
$this->itemQty =
array();
}
// Add an item to the cart
function addItem($product_id, $quantity) {
$this->itemQty[$product_id] = $quantity;
}
...
a. Give code to create an empty cart called $cart1
b. Add 2 units of product 3 and 4 units of product 5 to $cart1 by calling its addItem method (shown above)
c. Is it possible to access the Cart's $itemQty from code outside cart.php? Explain how or why not.
a. What HTTP command (ending in HTTP/1.1) would be used to get the current JSON representation of order 12?
b. If $content holds the JSON content for the body of the response to be returned by the Slim server (set up as we have done), how does the server get it sent back to the client? Give the line of code. (This can be done in two ways, with and without $response. Show either way.)
c. What PHP function do we call in the PHP client to convert the string returned in the response into a PHP array?
d. Under what circumstances should the server return HTTP 400?
8. Handling Users in bigger websites.
a. Explain how we ensure that passwords cannot be read in transit, for example, by "sniffing" tools that read raw packets off the network.
b. Explain how a web app remembers that a certain user has logged in a few minutes ago, so they are not bothered by repetitive requests for passwords.
a. Write a small HTML file that has a body, with a main, and inside main, a section containing "Hello" in an p element. It should also have a script element for Javascript in app.js. The section element should have an attribute named "id" of va
b. Write JS code (no JQuery, just Javascript) for app.js that locates the section and adds another p element containing "Goodbye".
c. Add an event handler to the section element so that when a user clicks on the section, another p element containing "Goodbye" is added below the preceding ones