Computer Science 217

Similar documents
Computer Science 217

Computer Science 217

THE AUSTRALIAN NATIONAL UNIVERSITY Final Examination November COMP1730 / COMP6730 Programming for Scientists

CMSC 201 Computer Science I for Majors

Final Exam Practice Questions

1. What is the minimum number of bits needed to store a single piece of data representing: a. An integer between 0 and 100?

Chapter 5 : Informatics practices. Conditional & Looping Constructs. Class XI ( As per CBSE Board)

Python Activity 7: Looping Structures WHILE Loops

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

CSCI 101 Midterm Sample Questions

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

CS 1301 Exam 1 Fall 2013

Introduction to Problem Solving and Programming in Python.

Midterm Exam 2A Principles of Computing Fall November 10, 2014

Introduction to Programming

CS 105 Lab As a review of what we did last week a. What are two ways in which the Python shell is useful to us?

Midterm Exam 2B Answer key

THE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September COMP1730 / COMP6730 Programming for Scientists

CS 1301 Exam 1 Fall 2014

The while Loop 4/6/16 4

CS 1301 Exam 1 Fall 2013

Exam 1, Form A CSE 231 Fall 2012 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

CMSC411 Fall 2013 Midterm 1

Outline. policies. with some potential answers... MCS 260 Lecture 19 Introduction to Computer Science Jan Verschelde, 24 February 2016

CPSC 217 L01 Midterm

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm

Comp 150 Exam 2 Overview.

CS177 Python Programming. Recitation 2 - Computing with Numbers

Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts

CS 1301 Exam 1 Fall 2014

15-110: Principles of Computing Sample Exam #1

The University of Oregon May 16, 2015 Oregon Invitational Mathematics Tournament:

Selection statements. CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington

CPSC 121 Midterm 1 Friday October 14th, Signature: Section (circle one): 11:00 15:30 17:00

CPSC 121 Some Sample Questions for the Final Exam Tuesday, April 15, 2014, 8:30AM

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

Pattern Maker Lab. 1 Preliminaries. 1.1 Writing a Python program

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1

Text Input and Conditionals

Midterm #1a Fall minutes

CS 1301 Exam 1 Answers Fall 2009

Lesson 19: The Graph of a Linear Equation in Two Variables is a Line

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

Types, Expressions, and States

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2016 Midterm I

UNIVERSITY REGULATIONS

Laboratory 5: Implementing Loops and Loop Control Strategies

CS/ECE 374 Fall Homework 1. Due Tuesday, September 6, 2016 at 8pm

CPSC 121 Midterm 1 Friday February 5th, Signature: Section (circle one): Morning Afternoon

Loop structures and booleans

Introduction to Programming

Common Loop Algorithms 9/21/16 42

MC302 GRAPH THEORY SOLUTIONS TO HOMEWORK #1 9/19/13 68 points + 6 extra credit points

CE151-4-AU UNIVERSITY OF ESSEX. Sample Examination Questions 2011 INTRODUCTION TO PROGRAMMING

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

CPSC 217 Midterm (Python 3 version)

CS110 Introduction to Computing Fall 2006 Midterm Exam

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2010

When Brunel s ship the SS Great Britain was launched into the River Thames, it made such a splash that several spectators on the opposite bank were

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Introduction to programming using Python

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Number Sense Workbook 7, Part 1: Unit 3

2. Explain the difference between read(), readline(), and readlines(). Give an example of when you might use each.

CMPT 120 Control Structures in Python. Summer 2012 Instructor: Hassan Khosravi

EECS 270 Midterm Exam

CS 1301 Exam 3 Spring 2014

Topic 2: Making Decisions

Assignment 2: Welcome to Java!

Topic 2: Making Decisions

6th Bay Area Mathematical Olympiad

CMSC201 Computer Science I for Majors

CS 115 Lecture 8. Selection: the if statement. Neil Moore

Difference Between Dates Case Study 2002 M. J. Clancy and M. C. Linn

Module 3: Representing Values in a Computer

University of New Mexico Department of Computer Science. Final Examination. CS 561 Data Structures and Algorithms Fall, 2011

1/11/2010 Topic 2: Introduction to Programming 1 1

CS 1301 Exam 1 Fall 2009

The University of Oregon May 16, 2015 Oregon Invitational Mathematics Tournament:

Variables, expressions and statements

The Bisection Method versus Newton s Method in Maple (Classic Version for Windows)

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

CS16 Exam #1 7/17/ Minutes 100 Points total

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

Discrete Mathematics and Probability Theory Fall 2013 Midterm #2

CS 1301 Exam 1 Spring 2014

ETGG1801 Game Programming Foundations I Andrew Holbrook Fall Lecture 0 - Introduction to Computers 1

Structure and Interpretation of Computer Programs Summer 2015 Midterm 1

1 Fall 2017 CS 1110/1111 Exam 3

MA 111 Review for Exam 4

To become familiar with array manipulation, searching, and sorting.

History of Computing. Ahmed Sallam 11/28/2014 1

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

COS 226 Fall 2015 Midterm Exam pts.; 60 minutes; 8 Qs; 15 pgs :00 p.m. Name:

Transcription:

Computer Science 217 Midterm Exam Fall 2012 November 1, 2012 Name: ID: Class Time (Circle One): 1:00pm 3:00pm Instructions: Neatly print your name and ID number in the spaces provided above. Pick the best answer for each multiple choice question. Answer each question by writing the correct answer in the space provided. Answer all multiple choice questions using UPPER CASE letters. This exam consists of 10 pages, including the cover. Before answering any questions count the pages and ensure that they are all present. You have 1 hour 30 minutes to complete this exam. Unless noted otherwise, each question is worth one mark. This exam is closed book. You are not permitted to use any electronic devices or reference materials. DO NOT TURN PAST THIS PAGE UNTIL YOU ARE INSTRUCTED TO BEGIN Version A Page 1

1. (12 marks) Consider a right angle triangle, with sides a, b and c. By Pythagorean theorem, the length of side c is. Your task is to write a program that reads an integer, n, from the user, and finds and displays all triangles where 1 <= a <= n and 1 <= b <= n and a, b, and c are all integers. Your program should also display a count of how many triangles are found. Hint: To determine if a number is an integer, compute the remainder when you divide it by 1. If the remainder is 0 then the number is an integer. Otherwise it is not. Your program must include appropriate prompts and output messages, which should match the sample executions shown below. In the sample executions user input is shown in bold: Sample 1: Enter an integer: 2 Found 0 triangle(s) Sample 2: Enter an integer: 4 Triangle 3 4 5 Triangle 4 3 5 Found 2 triangle(s) Sample 3: Enter an integer: 15 Triangle 3 4 5 Triangle 4 3 5 Triangle 5 12 13 Triangle 6 8 10 Triangle 8 6 10 Triangle 8 15 17 Triangle 9 12 15 Triangle 12 5 13 Triangle 12 9 15 Triangle 15 8 17 Found 10 triangle(s) Place you answer on the next page. Don t use this space. No, really, don t do it! 0 Version A Page 2

Place your answer to the programming question on this page. Version A Page 3

2. Which of the following was used first to aid with mathematical computations? A. Babbage Difference Engine B. ENIAC C. Transistor D. Vacuum Tube E. Wii 3. The area of computer science that concentrates on techniques for determining how efficiently problems can be solved in terms of time and space is: A. Computer Vision B. Distributed Systems C. Human Computer Interaction D. Information Security E. Theory of Computation 4. List three examples of components of a computer that connect to the CPU through the South Bridge: 5. Within Bloom s Taxonomy, the level of competence that is characterized by the ability to compare two or more distinct solutions and identify their strengths and weaknesses is: 6. The output of top-down design is: A. a collection of high-level programming language statements B. a collection of low-level programming language statements C. a flowchart D. an algorithm E. an executable file 7. (2 marks) The following variable names are being considered for use in a Python program. Some of the names are legal names that can be used in a Python program, while others are illegal. Circle all of the legal variable names. Note that you should only consider whether or not the name is legal. A name may still be legal even if it is stylistically poor. pir8 F5 for NES 1_2_3 if-else Loch Ness Monster _x PRINT Version A Page 4

8. In the classic game The Legend of Zelda for the Nintendo Entertainment System, the player is restricted to carrying a maximum of 255 rupees (the game s currency). Given this information, it is most likely that the player s rupee total is being stored in a: A. bit B. byte C. double word D. half word E. word 9. Consider the following code segment: a = 5 b = "9" print(a+b) When the program is run, it will display: A. 5 B. 9 C. 14 D. 59 E. None of the above answers are correct 10. Consider the following code segment: a = "5.0" b = "10.0" x = float(a / b) print(x) When it runs, the output will be: A. 0 B. 0.5 C. 2 D. 2.0 E. None of the above answers are correct 11. The operator with highest precedence is: A. + B. = C. >= D. and E. not Version A Page 5

12. Which type of Python error will always be caught when you execute your program, regardless of the input values that are provided? A. Semantic errors B. Logic errors C. Runtime errors D. Syntax errors E. More than one of the above answers is correct 13. Convert 123 base 10 to binary: 14. Convert 11322 4 to hexadecimal: Version A Page 6

15. (2 marks) Convert 73 base 12 to base 6: Consider the following Python program: x = int(input("enter x: ")) y = int(input("enter y: ")) if x >= 1: x = x + 1 y = y - 1 z = 0 if x == 2: x = x + 1 y = y * 2 z = 1 if y < 4: x = x + 1 y = y + 1 z = -1 print(x, y, z) 16. If the user enters 5 for x and 1 for y, then the output will be: 17. If the user enters 1 for x and 4 for y, then the output will be: 18. If the user enters 5 for x and 5 for y, then the output will be: 19. Provide an example of integer values for x and y that will cause the program to crash (saying that the program will crash because of non-integer input is not a valid answer to this question): x = y = Version A Page 7

20. Name one of the two logical operators which are functionally complete: 21. Complete the truth table for the expression B or not A and not B. Draw a box around the column that represents your result so that it is clear which column we are supposed to mark. A B 0 0 0 1 1 0 1 1 Consider the following Python program: a = int(input("enter a: ")) if a < 0: a = a + 1 print("a") if a == 0: print("b") a = a - 1 else: print("c") a = a + 1 elif a == 0: print("d") a = a - 1 print("e") 22. If the user enters 0 for a, then the output will be: 23. If the user enters -1 for a, then the output will be: 24. If the user enters -2 for a, then the output will be: 25. What level of white-box test coverage must be achieved in order to prove that your program does not contain any bugs? A. Condition coverage B. Graph coverage C. Heuristic coverage D. Path coverage E. None of the above answers are correct Version A Page 8

Consider the following code segment: a = 0 for i in range(4,8): if i % 2 == 0: a = a + i print(a) 26. The output of this program is: Consider the following code segment: a = float(input("enter a: ")) c = 0 while a < 5: c = c + 1 b = a * 2 while b < 3: b = b + 1 c = c * 2 a = a + 1 print(c) 27. If the user enters 0 for a then the output will be: 28. If the user enters 3 for a then the output will be: 29. If the user enters 5 for a then the output will be: 30. How many copies of the letter X does the following program display? for i in range(0,10): j = 0 print("x") while (j < 50): print("x") j = j + 1 31. What is the minimum number of times that a pre-tested loop will execute? Version A Page 9

32. (4 marks) The following program is supposed to read integers from the user until a negative number is entered. After the negative number is entered the program should report how many nonnegative numbers were entered, the largest number entered, and the smallest non-negative number entered. For example, if the user enters the values 5, 2, 7, 0, 6, -3, the program should report a count of 5, a largest value of 7, and a smallest non-negative value of 0. Unfortunately the program contains (at least) 4 bugs. The comments are all correct, and describe what the program is supposed to do. Circle each of the 4 bugs (and only the bug) and write 1 sentence or less next to each bug indicating what you would need to do to fix it. Note that in this context a bug is defined to be something that will stop the program from generating a correct result, or causes the program to crash. It does not include stylistic issues, differences in output messages, spelling mistakes in prompts, etc. # read the first input value from the user x = int(input("enter a number: ")) # create and initialize variables for count, minimum and maximum count = 0 mn = 0 mx = 0 # continue reading values until a negative number is entered while x > 0: if x < mn: # if a new smallest value is found, mn = x # record it if x > mx: # if a new largest value is found, mx = x # record it count = count + 1 # count all of the values entered # read the next input value from the user x = input("enter another number: ") # Display the results if count!= 0: # provide a meaningful message if no values were entered print("no values were entered.") else: # display the count, minimum non-negative value and maximum value print(count,"values were entered") print("the largest value is: ",mx) print("the smallest non-negative value is: ",mn) Version A Page 10