CS 110 Exam 2 Spring 2011

Similar documents
CS 110 Exam 2 Fall 2011

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

CS 1301 Exam 3 Spring 2014

Question: Total Points: Score:

CS 1301 Exam 1 Fall 2011

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

Question: Total Points: Score:

Exam Percentage: / 55 = %

Question: Total Points: Score:

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

CS 110 Exam 1 Fall 2011

Instructor: Yu Wang 11/16/2012

CS 1301 Exam 1 Fall 2010

Question: Total Points: Score:

CS 1301 Exam 1 Spring 2014

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

CS 190 Exam 1 Fall 2010

Section 004 Spring CS 170 Exam 1. Name (print): Instructions:

Place your name tag here

CS 1301 Exam 1 Spring 2011

CS 2316 Exam 4 Fall 2012

Question: Total Points: Score:

Question: Total Points: Score:

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

Question: Total Points: Score:

CS 2316 Exam 4 Fall 2011

CS 155 Exam 2 Spring 2015

CS 170 Exam 1. Version: B Fall Name (as on OPUS):

CS Exam 2 - Spring 2010

Your (printed!) Name: CS 1803 Exam 3. Grading TA / Section: Monday, Nov. 22th, 2010

CS 1301 Exam 2 A Fall 2015

CS 170 Exam 1. Version: C Fall Name (as on OPUS):

CS 1301 Exam 1 Spring 2014

Question: Total Points: Score:

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2014

Question: Total Points: Score:

CS 1803 Fall 2010 Exam 1

Question: Total Points: Score:

CS 190 Exam 2 Fall 2014

CS 1301 Exam 2 Fall 2013

CS 170 Exam 2. Version: A Fall Name (as in OPUS) (print): Instructions:

CS 1301 Exam 3 A Spring 2015

CS 2316 Exam 1 Spring 2013

CS 1301 Exam 1 Fall 2014

CS Name : Grading TA:

CS 2316 Exam 4 Fall 2011

CS 1301 Exam 3 Spring 2012

CS 2316 Exam 1 Spring 2014

CS 2316 Exam 4 Fall 2012

Question: Total Points: Score:

CS Exam 3 - Spring 2010

CS 1301 Exam 3 Fall 2014

CS 1301 Exam 2 A Fall 2015

CS Exam 3 - Spring 2010

CS 1301 Exam 1 Spring 2015

CS 1301 Exam 2 Fall 2014

Question: Total Points: Score:

CS 170 Exam 2. Section 004 Fall Name (print): Instructions:

CS 2316 Exam 4 Fall 2014

CS 1803 Fall 2010 Exam 1

Question: Total Points: Score:

CS 2316 Exam 4 Spring 2013

Question: Total Points: Score:

CS 1301 Exam 1 Fall 2013

Section 002 Spring CS 170 Exam 1. Name (print): Instructions:

CS 2316 Exam 3 Fall 2011

CS 1301 Post Exam 3 Practice Spring 2016

CS 2316 Exam 2 Summer 2011

Question Possible Points Earned Points Graded By GUI 22 SQL 24 XML 20 Multiple Choice 14 Total Points 80

CS 1301 Exam 1 Fall 2013

CS 1301 Exam 2 Fall 2010

CS 2316 Exam 4 Spring 2012

CS 1301 Exam 2 Spring 2014

CS 2316 Exam 3 Spring 2013

CS 2316 Exam 3 Fall 2012

CS 111X - Fall Test 1

Page: Total Points: Score:

1. Consider the following code snippet. Describe what the user will see when it is executed.

A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University 2011 Pearson Prentice Hall ISBN

CS170 (005): Introduction to Computer Science Exam 2

CISC 1600 Lecture 2.4 Introduction to JavaScript

CSE 131S Introduction to Computer Science Summer SON Exam I

CS 2316 Exam 3 Summer 2014

CS 1301 Exam 3 Fall 2010

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

Working with JavaScript

CS Exam 2 Name: Your Grading TA: This exam has 7 pages including the title page. Please check to make sure all pages are included.

Your (printed!) Name: CS 1803 Exam 2. Grading TA / Section: Monday, Oct 25th, 2010

A Balanced Introduction to Computer Science, 3/E

Spring 2016 Algorithms Midterm Exam (Show your work to get full credit!)

Programming language components

ORB Education Quality Teaching Resources

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

Enhancing Web Pages with JavaScript

CS 1301 Exam 1 Fall 2009

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

Unit Notes. ICAWEB411A Produce basic client-side script for dynamic web pages Topic 1 Introduction to JavaScript

CS1046 Lab 4. Timing: This lab should take you 85 to 130 minutes. Objectives: By the end of this lab you should be able to:

Transcription:

CS 110 Exam 2 Spring 2011 Name (print): Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam in compliance with the Honor Code of Emory University. Do NOT sign nor take this exam if you do not agree with the honor code. Instructions: Keep your eyes on your own paper. Do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than the professor/proctor for ANY reason in ANY language in ANY manner. Do not use notes, books, calculators, etc during the exam. Turn all mobile devices off and put them away now. You cannot have them on your desk. Stop writing and put down your pencils when told to do so. Academic misconduct will not be tolerated. The penalty for violating any of the above policies or other misconduct will be a zero on this exam. Other disciplinary action as deemed appropriate by the Emory Honor Council may also be applied. Time: This exam has 9 questions on 11 pages including the title page. Please check to make sure all pages are included. You will have 50 minutes to complete this exam. I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Emory community. I have also read and understand the requirements outlined above. Signature: Page: 2 3 4 5 7 8 9 10 Total Points: 6 4 8 15 18 22 12 15 100 Score: 1

1. Multiple Choice. Circle the correct answer for each question. (a) (1 point) Javascript is an: A. interpreted language B. compiled language C. machine language D. assembly language E. algorithmic language (b) (1 point) In Javascript, the + operator can be used on what data types? A. a combination of strings and numbers B. strings only C. numbers only D. whole numbers only (such as 1, 2, 3, etc) E. partial numbers only (such as 1.23 or 4.56) (c) (1 point) Which of the following is NOT a high-level language? A. C++ B. Java C. Javascript D. Fortran E. binary (d) (1 point) What values does the function Math.random() return? A. between 0 (inclusive) and 1 (exclusive) B. between 0 (inclusive) and 1 (inclusive) C. between 0 (inclusive) and 100 (exclusive) D. between 1 (inclusive) and 2 (inclusive) E. between 1 (inclusive) and 100 (exclusive) (e) (1 point) What statement displays an alert box in Javascript? A. write.alert; B. alert("text"); C. display.alert; D. alert = "text"; E. innerhtml = "alert text"; (f) (1 point) In Javascript a line beginning with the symbols // is a(n): A. variable B. function C. comment D. HTML element E. statement 2

(g) (1 point) In programming, debugging is the process of systematically locating and A. understanding data types. B. using the assignment operator. C. using precedence rules to evaluate expressions. D. fixing errors. E. removing variables. (h) (1 point) In Computer Science, Big-Oh notation is used to A. measure the exact number of seconds required by a given algorithm on a particular computer. B. represent an algorithm s performance in relation to the size of the problem. C. measure the amount of computer memory required by a given algorithm. D. count the number of operate instructions needed to solve a problem of a given size. E. specify how precise an algorithm needs to be. (i) (1 point) In Javascript, the = operator performs what function? A. It is used to store numbers in memory. B. It is used to assign data types to variables. C. It is used to test whether two mathematical expressions are logically equivalent. D. It assigns the value on its right hand side to the left hand side. E. It is used to test whether two expressions are equal to each other (j) (1 point) In a programming context, libraries are A. the output of a function. B. the inputs to a function. C. user defined functions which allow code reuse. D. user manuals which document a programming language. E. similar functions grouped together for easy reference. 3

2. Multiple Answer. Circle ALL of the correct answers for each question. There will be at least one correct answer for each question, but there may be more. (a) (2 points) Binary search is an example of an : A. logarithmic algorithm. B. O(N 2 ) algorithm. C. O(log(N)) algorithm. D. divide-and-conquer algorithm. E. O(N) algorithm. F. O(X N ) algorithm. G. constant time algorithm. (b) (2 points) Which of the following would NOT be considered an algorithm. A. A web browser. B. A method of searching data for a specific number. C. A recipe for baking a cake. D. A high-level programming language. E. Instructions on how to put together a bookcase. (c) (2 points) Which of the following are examples of legal variable names in Javascript? A. 1x B. x1 C. x_1 D. X1 E. x+1 F. x 1 G. x11 (d) (2 points) Consider the following Javascript statements: w = 3; x = 4; y = 12; If added as the 4th statement, which of the following statements would make the variable z equal to the value of 3? A. z = y - (x * w) + w; B. z = y / x; C. z = x / y; D. z = 3; E. z = w; F. z = w * y; G. z = w / 0; 4

3. Fill in the Blank. Answer the following questions about the following HTML/Javascript webpage. <html> <head> <title>my Calculating Webpage</title> <script type="text/javascript"> function GetRand() { num = Math.random(); bignum = num * 100; num = Math.round(bignum); document.getelementbyid( output ).innerhtml = num; } </script> </head> <body> <input type="button" value="click me!" onclick="getrand();"> <div id="output"></div> </body> </html> (a) (2 points) What is the name of the function defined in this file? (a) GetRand (b) (2 points) How many Javascript statements are in the function? (b) 4 (c) (2 points) How many variables are defined in the function? (c) 2 (d) (2 points) List the variables defined in the function. (e) (2 points) What library (or libraries) does this function use? (d) (e) num, bignum Math (f) (2 points) What function(s) from the library(or libraries) you listed in Part e above are used in the code? (f) random, round (g) (3 points) In your own words, briefly describe how this webpage works. 5

Solution: Every time the user clicks the button a new random number between 0 and 100(inclusive) will be generated. The number will have no decimal places since it is rounded. 6

4. (4 points) Briefly describe the difference between an interpreter and a compiler Solution: Interpreter: translates 1 line of code to machine language at a time Compiler: translates entire program to machine lang. at once 5. (6 points) When designing algorithms, we must sometimes make trade-offs between a variety of factors that are desirable. List 3 different things you might consider when designing an algorithm. Solution: simplicity, running time, amount of memory, precision, etc. Note that correctness is different then precision. We always want our algorithm to be correct but the level of precision that defines correctness may be open for debate. 6. (8 points) Briefly describe the difference between a syntax error and a logic error and give a Javascript statement that is an example of each. Solution: syntax: typographical errors. Forgetting a quotation mark, semicolon, misspelling a word, etc. user_name = valerie; is missing a quotation mark. logic: code is correct/legal, but gives an unexpected result because user applied logic incorrectly. avg = 100 + 96 / 2; when user really meant avg = (100 + 96) / 2; 7

7. Write the value of the variable after each Javascript statement executes. Write if the variable does not have a value assigned to it. Be sure to indicate whether a value is a string or a number through the use of quotation marks. (a) (14 points) x y z x = 42; 42 y = x * 2; 42 84 x = y + 2-4 / 2; 84 84 z = Hello +! ; 84 84 Hello! x = z + x; Hello!84 84 Hello! z = parsefloat( 13 ); Hello!84 84 13 y =(y + z) * 2; Hello!84 194 13 x y z x = 6 + 5 * 2-4; 12 (b) (8 points) y = (2 + 1) * 2-2 12 4 z = y / 2 * 2 + 2; 12 4 6 x = x / y - z -3 4 6 8

8. (12 points) Algorithms. Suppose you have a list of numbers. You want to count all numbers that are greater than a given number. You know three additional pieces of information: the list is sorted in ascending order the length of the list there are no numbers repeated in the list. For example, if the list was: 12 15 19 22 45 62 75 81 93 101 and you were trying to find all numbers greater than 25. One way to do this is to use a sequential search. That is, examine the first element, decide if it is greater than your target number, examine the second element, decide if it is greater than your target number, etc. until you have examined all the elements in the list and counted the number that are greater than your target number Develop a different algorithm which is more efficient then the one described above. Write it as an ordered list of steps. Hint, test your algorithm using the above list and a target number of 101. Is your algorithm more efficient then the one described above? Solution: Preform a binary search find the location of the target number or the location where target number should be (if it isn t in the list). Once you ve found that location, subtract the location from the length of the list. Most common mistake: many students described a binary search without stating how they would use that to find the count asked for in the question. 9

9. (15 points) Code Writing. Complete the webpage below by writing a function described below. The HTML has been given for you and should not be modified. Write a function named Average which gets two numbers from the user (via the input text boxes) and averages them. The average should displayed as shown in Figure 1(next page) when the user clicks the button. <html> <head> <title>my Averaging Webpage</title> <script type="text/javascript" </script> </head> <body> <input type="text" size=4 id="num1"> <input type="text" size=4 id="num2"> <input type="button" value="average these!" onclick="average();"> <hr> <div id="output"></div> </body> </html> Solution: Should be something like: function Average() { n1 = parsefloat(document.getelementbyid( num1 ).value); n2 = parsefloat(document.getelementbyid( num2 ).value); avg = (n1+n2)/2; document.getelementbyid( output ).innerhtml = The average of + n1 + and + n2 + is + avg; } +2 function declaration/name +2 values retrieved from user input correctly (x2) +2 strings/values converted to numbers correctly (x2) 10

+3 variables used appropriately +2 average computed correctly +2 correct output string generated and assigned to innerhtml +2 correct syntax Figure 1: Example of webpage in Question 9 11