Multiple Choice Questions (2 points each): Circle only one answer for each of the following
problems:
- Suppose I have two arrays in Perl named @a and @b and I want to pass them
to a function named addArrays that will perform a pairwise addition on the elements of @a and
@b. Which of the following function calls will successfully pass the two
arrays intact to the function addArrays (i.e., addArrays will have two parameters)?
- @c = addArrays(@a, @b);
- @c = addArrays(\@a, \@b);
- @c = addArrasy($a, $b);
- @c = addArrays(&@a, &@b);
- Suppose I have the following JavaScript code fragment:
for (index = 0; index < fruits.length; index++) { ... }
What is a more compact way to write this for loop?
- for (index in fruits) { ... }
- for each (index fruits) { ... }
- for (fruits as index) { ... }
- for index in range(0, fruits.length) { ... }
- In Perl, why should you use my rather than local to
declare a local variable?
- my uses static, lexical scoping, whereas local uses dynamic scoping
which is more apt to break the program
- my indicates that the local variable should receive a reference
to a parameter's value whereas local indicates that the parameter's value to
should be copied into the local variable, thus leading to
expensive copies for parameters that are objects, such as lists or hash tables
- local has a loophole that allows the variable to end up in the
global namespace once the function exits
- local flattens a hash table parameter into a list of the hash table's keys
and values whereas my keeps the hash table intact as an object
- If the server wishes to return its information to the client in a
format that will allow the information to be easily converted to a
Javascript object (i.e., associative array), which format should it
use to transmit the information:
- plain text format
- JSON format
- XML format
- DOM format
- What is the purpose of the bless command in Perl's object system?
- It associates a package with a module, thus identifying the package as an instance of that module
- It associates a subclass with a class, thus allowing methods not defined in the subclass to be located in the superclass
- It associates a reference, which is usually a reference to a hash, with a class, thus identifying the object as an instance of that class
- It is the command used in place of a constructor to create a new object.
- If I want to create a Perl class named Rectangle which is a subclass of GraphicalObject, which of the following sets of commands will properly set up the inheritance hierarchy between Rectangle and GraphicalObject?
-
class Rectangle extends GraphicalObject;
-
class Rectangle : base Graphical Object;
-
package Rectangle;
derives GraphicalObject;
-
package Rectangle;
use base("GraphicalObject");
- Why is it so important to validate your data on the server side, even
if the web form has its own validation functions?
- You may have incorrectly written the validation functions on the
web form
- The CGI transmission protocol is highly prone to transmit faulty
data
- Hackers may be able to by-pass the web form by calling your script
directly
- Hackers may have entered malicious data on the web form that javascript
functions cannot detect
- What critical feature does Javascript lack that makes it inappropriate
for general purpose computing but makes it secure/trusted for client-side
computing?
- lack of pointers
- prototype-instance object system rather than class-instance object
system
- inability to read/write files
- inability to read from stdin or write to stdout
Multiple Answer Questions (36 points total): The following questions may have one or more
correct answers. Circle all answers that are correct.
- Which of the following are advantages of prepared SQL queries in PHP?
- They execute faster because the query is pre-optimized by the query optimizer
- They prevent cross-site scripting attacks
- They reduce the amount of data traffic between the server and the client
- They provide a way to cache database results on the client side so that repetitive queries can be answered without sending the query to the server.
- They speculatively pre-fetch results from the SQL database so that data is potentially already cached in the server's memory when it is needed.
- They make it more difficult to carry out injection attacks against the database
- Which of the following are server side mechanisms for handling session
information in PHP?
- cookies
- hidden form elements
- SESSION table
- database storage
- What are the advantages of cookies over session variables?
- They prevent hackers from corrupting the data that is sent to the server
- They can be preserved between web sessions, which means that the user can close their web browser, re-open it, and the data will still be available.
- They allow multiple servers to handle the same web session
- They allow client-side scripts to access the data, as well as server side scripts.
- They only have to be transmitted once per web session rather than with each page request
- They allow more session data to be stored because they are stored on the server rather than the client and hence are subject to the server's size limitations rather than the browser's size limitations.
- In which of the following situations should I use the POST method
for submitting a form:
- When the form will be used to query the database but not modify it
- When you want to allow external web-crawlers to query your site
without going through the web-interface for the site
- When the form will be used to modify the database, such as placing
an order or a reservation
- When the amount of information to be transmitted is in the thousands
of kilobytes or more.
- Which of the following strings match the following regular expression.
/^\d{2,4}$/
- bz385sj
- 171
- 37920
- 25
- 4
- 5384
- 223444
- 324432
- Which of the following strings match the following regular expression.
/^([A-Z]\.)|([A-Z][a-z]*)$/
- 146Brad
- M.
- Ma
- G
- asterisk
- M.Brad
- GeorgeB.
- AARDVARK
- Which of the following features typically distinguish scripting languages
from traditional, compiled languages such as C or C++?
- built-in data types for lists and hash tables, instead of library
support for these data types
- strong access protections for object-oriented programming
- interpreted execution
- support for high-level string manipulation, including
pattern-matching constructs
- built-in high-level loop constructs for iterating through lists and arrays, instead of library support for these loop constructs.
- efficient execution of programs
- support for general-purposing computing (e.g., the ability to
write programs to accomplish arbitrary tasks)
- concise, compact syntax that allows programmers to quickly
write small but powerful programs
- In which of the followng ways might a hacker be able to attack your
web site if you fail to escape incoming data with
single and double quotes with \'s and
to convert html special characters to their corresponding entity codes?
- The hacker could cause you to return links to the client-side that could
cause a user to click to a malicious web-site
- The hacker could cause you to return javascript code that implants a
virus on the client's hard drive
- The hacker could execute malicious code on your server if you pass
the data as parameters to system commands
- The hacker could execute malicious queries on your database if you
pass the data as parameters to database queries
- The hacker could cause you to return javascript code that searches the
client's hard drive for passwords
- In which of the following ways does a prototype-instance model differ from
a class-instance model.
- All prototypes are themselves objects.
- Prototypes cannot contain methods.
- Prototypes do not have constructors.
- Properties can be dynamically added or deleted from any instance
object.
- Properties can be dynamically added or deleted from any prototype
object.
- Prototypes are computationally more efficient than classes.
- Prototypes cannot support multiple inheritance.
- Prototypes allow web interfaces to be rapidly changed without
shutting down the web-site and recompiling it.
- Which of the following features can Ajax support on a web-page that
could not be supported by javascript or html alone?
- Incrementally add or delete email headers sent from a server without
regenerating the entire page
- Validate form data and mark invalid form elements without
re-generating the entire page
- Update parts of a web page based on local changes to form data
- Display forms and allow users to interact with the forms by
clicking on form elements and entering information into text boxes
- Display stock quotes without re-generating the entire page
- Allow a user to move to a new page by clicking on a link
- Allow new images to be periodically downloaded from the server
and displayed in the same location without re-generating the entire
page
- Display static images that are downloaded from the server when the
web-page is first loaded.
- Which of the following problems with updating
content on a web page was AJAX designed to solve?
- An inability to dynamically generate html pages on the server side
that would reflect changes user made to a form
- The loss of the state information of javascript variables when a
new page was loaded
- An inability to transmit images in a web-page
- The browser would freeze until the server responded with a new page
- Bandwidth and latency issues caused by having to transmit an entire
page of information.
- A malicious hacker could read information on the client's file system
- Which of the following advantages does XML have over a database?
- Given the same amount of data, it provides much more compact
storage
- It can execute queries more efficiently
- Its data is human-readable
- It provides greater data security
- It is less likely to have redundant data that is subject to
update anamolies
- It provides powerful query operators that allows end-users without
programming experience to quickly combine data from different schemas
and generate reports
- It supports semi-structured data that may have different attributes
based on an element's type
- It provides better support for concurrent updating of its data
Fill in the blank questions: Fill in the blanks for each of the following
questions.
- (8 points) For each of the following tasks, indicate which
scripting language/markup language was designed to handle it:
- ____________________ create dynamic web pages on the server side by embedding code islands in html mark-up.
- ____________________ use regular expressions, to extract data
from files and format this data into reports.
- ____________________ modify parts of a web-page by modifying the
page's html dom
- ____________________ encode data by marking it up with tags
Javascript questions. The following html markup applies to questions 22-26.
All of the questions are multiple choice except for the one question explicitly
marked as multiple answer.
Your name is your name and your email is
email address.
- (2 points) If I want to obtain the user's first name and assign it to the
variable firstname, which of the following Javascript statements should
I use?
- firstname = document.forms.application.fname;
- firstname = document.forms.application.fname.value;
- firstname = document.forms.application.fname.innerHTML;
- firstname = document.getElementById('fname').value;
- Multiple Answer (4 points) How should I assign the value in name to the html element named username in
the above html form? Circle all answers that are correct.
- document.username.html = name;
- document.username = name;
- document.username.innerHTML = name;
- document.getElementById('username') = name;
- document.getElementById('username').innerHTML = name;
- document.getElementById('username').value = name;
- document.getElementById('username').firstChild.nodeValue = name;
- document.getElementById('username').firstChild = name;
- (2 points) Suppose I wanted to add a submit button to the above form. Which of
the following markup elements correctly accomplishes this task?
- <input type="submit" />
- <submit value="Submit Query" />
- <input type="button" value="Submit" />
- <input validateForm() />
- (2 points) Suppose I wanted to add an event to the first name text box that
calls a function named validateName when the user changes the text
string in the box. The function should be passed a reference to the
fname element as an argument. Which of the following attribute
clauses should I add to the fname element?
- onClick = validateName(fname);
- onClick = validateName(this);
- onChange = validateName(fname);
- onChange = validateName(this);
- changeEvent = validateName(fname);
- changeEvent = validateName(this);
- (2 points) Suppose as part of the above form I wanted to ask a user to specify their
occupation and there are 6 possible occupations that a user could
specify. What type of form element should I use assuming that they can
specify only one occupation?
- radio buttons
- menu
- text box
- check boxes
- (6 points) Insert 10 into the following B+-tree of degree 5. Assume
that leaf nodes can hold a maximum of 4 values.
- (10 points) Write a Perl 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}$/.
- A name such that: 1) the name may consist of one or
more words (e.g., Brad T Vander Zanden), 2) the first letter of each separate
word in the name is capitalized and the remaining letters are
lower case,
3) there may be 0 or more remaining letters after the first letter
3) each word in the name consists only of alphabetical letters, and
4) each word of the name is separated by exactly one blank space.
- A string that specifies an id as containing:
- exactly 2 digits,
- followed by a group that contains a dash followed by
4-6 digits,
- followed by an optional group that contains a dash followed by
1-3 lowercase letters (a-z).
For example, 37-9203-br and 43-485855 are legitimate zip codes.
- (12 points) Write a Perl function named duplicate that
determines whether or not there are any duplicate lines in a file. The
function should take the name of the file as a string and it should return
1 if the file contains duplicate lines and 0 otherwise. If the file has
duplicate lines, duplicate should print the line numbers of the
duplicated lines. For example, if the
file contains the lines:
hi
how are you
this is
a test
how are you
brad
brad
how are you
today?
then duplicate should print:
lines 2 and 5 are duplicates
lines 6 and 7 are duplicates
lines 2 and 8 are duplicates
Note that if a line is duplicated more than once, such as "how are you", then
duplicate
prints out the line number of the first line in the file that it duplicates.