COSC 465 Final Exam Fall 2018 You have 2 hours to complete the exam Good luck! Multiple Choice Questions (2 points each) Circle only one answer for each of the following problems: What is the primary goal of a scripting language? Allow programmers to write a program as quickly as possible, even if it sacrifices machine efficiency Allow programmers to write a program that executes quickly, even if the programmer requires a significant amount of time to write, test, and debug the program. Allow programmers to write multi-threaded, server applications that simultaneously support multiple client interactions. Allow programmers to create highly interactive web pages that support animations, form validation, and dynamic content. If I want to maintain session information in PhP across a multi-page web-site and I am using a single server, which of the following is the simplest server-side solution to use? cookies hidden form elements SESSION table database storage Suppose that I want to write an SQL prepared statement that will be called from a PHP script. The prepared statement should return all students in a course who received a score greater than some amount. The parameters will be the course id and the score. The attributes returned will be the studentId, score, and letter grade. How should I write the prepared statement, assuming that the relation has the following attributes: Grades(courseId, studentId, score, letterGrade) SELECT studentId, score, letterGrade FROM Grades WHERE courseId = $courseId AND score >= $score; SELECT studentId, score, letterGrade FROM Grades WHERE courseId = $1 AND score >= $2; SELECT studentId, score, letterGrade FROM Grades WHERE courseId = ? AND score >= ?; SELECT studentId, score, letterGrade FROM Grades WHERE courseId = ?[1] AND score >= ?[2]; Suppose you are given the following PUG template and PUG instantiation from Express. What html code will be created by the PUG template? // From Express var locals = { flowers: ['roses', 'daisies', 'violets'] }; res.render("index", locals); // index.pug ol - for (flower of #{flowers}) li= flower ol li roses li daisies li violets <ol> <li> roses daisies violets </li> </ol> <ol> <li> roses </li> <li> daisies </li> <li> violets </li> </ol> 1. roses 2. daisies 3. violets Multiple Answer Questions The following questions have more than one correct answer and each correct answer is worth 1 point. Each question states the number of correct answers. If you choose more than the indicated number of answers, you will one point for each additional answer. In which ways does a Javascript program typically modify the appearance of a web page once the web page has been loaded (2 correct answers): By modifying one or more properties of a tag element's style object By changing the text property of a tag element By adding, removing, or changing tag elements in the HTML DOM By adding, removing, or changing tag elements in the XML DOM Which of the following statements are true of a single page application (SPA) (3 correct answers)? It is a web application that consists of a single static page with the remaining pages being dynamically generated by the server in response to user interaction. It is a web application that downloads a desktop application from a server and then runs the application in the browser rather than a separate window. Once it has downloaded the application, it severs its ties with the server and uses the client's CPU and file system, just like an ordinary desktop application. It is a web application that runs in a single web page and provides a user experience that is similar to a desktop application, but which interacts with a server rather than the client's file system to acquire the data it needs to run the application. It is a computationally expensive web application that loads all of the application's resources immediately, runs in a single page on the client-side, and utilizes the client's CPU and file system so as to minimize the resource requirements of the server. It is a web application that encodes the business logic for the web application on the client-side rather than the server-side. Which of the following strings match the following regular expression. (4 correct answers) /^\w{3,5}$/ br6d Betty Sal! Ba bi? SARAH 62Yifan Pa_rt Fill in the blank questions
Fill in the blanks for each of the following questions. (8 points) For each of the following definitions, select the most appropriate language/protocol/library/database from the following list that matches it: PhP Pug Javascript MongoDB JSON Common Gateway Interface (CGI) SQL JQuery node.js Express css html ____________________ A client-side scripting language that handles user interactions with a web page. ____________________ An encoding that allows PhP to transmit a hash table back to the client side so that Javascript can easily re-create the hash table. ____________________ A server-side scripting language that generates dynamic web pages by allowing the user to intermix static html content with "code islands" that generate dynamic html content. Javascript questions
The following html markup applies to questions 9-11. <form name="tax" method="POST"> <input id = "amount" type="text" name="amount" maxlength="8"><br> <input id = "taxrate" type="text" name="taxrate" maxlength="4"><br> <input id = "salestax" type="text" name="salestax" maxlength="5"><br> </form> (2 points) Suppose I want to call a function named calculateTax() whenever a text box pointed to by the variable amount has its string changed to a new value. The function should be passed a reference to the text box as an argument. Which of the following statements will cause calculateTax() to be called (only one statement is correct)? amount.addEventListener("click", function() { calculateTax(this); }); amount.addEventListener("change", function() { calculateTax(this); }); amount.addEventListener("focus", function() { calculateTax(this); }); (2 points) Suppose as part of the above form I wanted to ask a user to specify the acceptable colors of the item they want to order and that there are 6 possible colors that a user could specify. What type of form element should I use assuming that they can specify multiple colors? radio buttons menu text box check boxes (4 points) Suppose as part of the CalculateTax function I have already performed the following two tasks: computed the sales tax amount and placed it in a variable called salestax_amount. retrieved a reference to the sales tax text box and assigned it to a variable named salestax_textbox. The final thing I want to do is make the color of the text in the sales tax textbox be red if the sales tax amount is more than $50 and black otherwise. Which of the following javascript fragments will do that? if (salestax_amount > 50) salestax_textbox.style.color = 'red' else salestax_textbox.style.color = 'black' if (salestax_amount > 50) salestax_textbox.color = 'red' else salestax_textbox.color = 'black' if (salestax_amount > 50) salestax_textbox.innerCOLOR = 'red' else salestax_textbox.innerCOLOR = 'black' if (salestax_amount > 50) salestax_textbox.setColor('red'); else salestax_textbox.setColor('black'); HTML and CSS (4 points) Suppose you are given the following html and css specification: <head> <style> p { color: blue; } .intro { text-decoration: underline; color: black; } #intro { color: green; font-weight: bold; } </style> </head> <body> <p class="intro"> The fast, brown fox jumped over the fence and escaped from the dog named <span id="intro">hopeless. </body> What will the rendered output look like in a browser? The fast, brown fox jumped over the fence and escaped from the dog named hopeless. The fast, brown fox jumped over the fence and escaped from the dog named hopeless. The fast, brown fox jumped over the fence and escaped from the dog named hopeless. The fast, brown fox jumped over the fence and escaped from the dog named hopeless. (6 points) For each of the following characteristics of a web page, circle whether that characteristic should be specified using html or css. html css layout of elements on the page (i.e., their positions) html css the images, such as jpegs or gifs, that appear on the page html css organizing content into spans Miscellaneous Questions (8 points) B+ Trees. Show what the following degree 5 B+ tree looks like after 30 is inserted into it. Assume that both leaves and internal nodes can contain a maximum of 4 keys. When you split a bucket and one of the two buckets must contain an odd number of keys, put the odd number of keys in the rightmost bucket. (8 points) Write a regular expression to represent each of the following patterns. Just write the pattern and nothing else. For example, if I told you to write a pattern for a date that has the form mm-dd-yy, with month and day being one or two digits and year being exactly two digits, I would expect your answer to read /^\d{1,2}-\d{1,2}-\d{2}$/. The more compact your specification, the more points you will receive. An airline flight code that gives the flight and the from and to airports. An example would be UL3010-TYC-LAX. The flight code should be constructed such that: 1) the first two letters are one of UL, AA, or DL, 2) the flight number is 1-4 digits with the first digit being non-zero (e.g., 0300 is not allowed), 3) a dash, 4) the from airport specified as exactly three uppercase letters, 5) a dash, and 6) the to airport specified as exactly three uppercase letters. A string that specifies a zipcode as containing exactly 5 digits, followed by an optional group that contains a dash followed by 4 digits. For example, 37920 and 37920-2886 are legitimate zip codes.