Final Exam, Version 1 CSci 127: Introduction to Computer Science Hunter College, City University of New York

Similar documents
Final Exam, Version 1 CSci 127: Introduction to Computer Science Hunter College, City University of New York

Final Exam, Version 2 CSci 127: Introduction to Computer Science Hunter College, City University of New York

Final Exam, Version 3 CSci 127: Introduction to Computer Science Hunter College, City University of New York

Mock Final Exam CSci 127: Introduction to Computer Science Hunter College, City University of New York

Final Exam, Version 2 CSci 127: Introduction to Computer Science Hunter College, City University of New York

Mock Final Exam CSci 127: Introduction to Computer Science Hunter College, City University of New York

Final Exam, Version 3 CSci 127: Introduction to Computer Science Hunter College, City University of New York

Final Exam, Version 4 CSci 127: Introduction to Computer Science Hunter College, City University of New York

Sample Final Exam CSci 127: Introduction to Computer Science Hunter College, City University of New York

Mock Final Exam CSci 127: Introduction to Computer Science Hunter College, City University of New York

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE Instructor: Final Exam Fall 2014

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

Do not turn to the next page until the start of the exam.

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

In this chapter you will learn:

Final Examination Semester 2 / Year 2005

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay

CSci 127: Introduction to Computer Science

COMP322 - Introduction to C++ Lecture 01 - Introduction

EECS 183 Fall 2015 Exam 2 Free Response (134 points)

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

CSCE Practice Midterm. Data Types

CSci 127: Introduction to Computer Science

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.7. User Defined Functions II

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

CSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

CS101 PLEDGED SPRING 2001

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

CSci 127: Introduction to Computer Science

Tutorial Letter 103/1/2017 Introduction to Programming I

Read this before starting!

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

University of Michigan EECS 183: Elem. Programming Concepts Fall 2011 Exam 1: Part 1: Form 1. Professors: ML Dorf, Elliot Soloway

BRAZOSPORT COLLEGE LAKE JACKSON, TEXAS SYLLABUS COSC 1320: INTRODUCTION TO C++ PROGRAMMING COMPUTER TECHNOLOGY & OFFICE ADMINISTRATION DEPARTMENT

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

CSCE Practice Midterm. Data Types

Ch 6. Functions. Example: function calls function

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

CSCI 111 First Midterm Exam Fall Solutions 09.00am 09.50am, Wednesday, October 18, 2017

CSCE 206: Structured Programming in C++

CASPER COLLEGE COURSE SYLLABUS MSFT 1600 Managing Microsoft Exchange Server 2003 Semester/Year: Fall 2007

PREPARING FOR PRELIM 1

CSCI 111 Midterm 2 Exam Spring Solutions 09.00am 09.50am, Wednesday, May 04, 2016

CSCI 1370 APRIL 26, 2017

1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?

Fall 08, Sherri Goings, Exam #1 (10/2), form 1 B

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

Other operators. Some times a simple comparison is not enough to determine if our criteria has been met.

Chapter 2 - Control Structures

CPT101- Principles of Programming

C++ Programming: From Problem Analysis to Program Design, Third Edition

Lecture #9 **go to Blackboard ** Review from Shackelford Reading If statements Loops. Using if statements and loops

Lecture 23: Pointer Arithmetic

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

Increment and the While. Class 15

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

CSci 127: Introduction to Computer Science

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Add Subtract Multiply Divide

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

1 #include <iostream> 2 using namespace std; 3 4 // implementing the dynamic List ADT using Linked List 5 6 class Node{ 7 8 private: 9 int data; 10

Chapter 4: Making Decisions. Copyright 2012 Pearson Education, Inc. Sunday, September 7, 14

REPETITION CONTROL STRUCTURE LOGO

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, October 13, 2015

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 03

SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017

Minot State University BUSINESS INFORMATION TECHNOLOGY DEPARTMENT Course Outline

CS 2316 Exam 3. Practice. Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

Read this before starting!

Read this before starting!

4.1. Chapter 4: Simple Program Scheme. Simple Program Scheme. Relational Operators. So far our programs follow a simple scheme

CSCI544, Fall 2016: Assignment 1

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

CSCI 135 Software Design and Analysis, C++ Homework 1 Solution

CS150 Sample Final. Name: Section: A / B

CS2255 HOMEWORK #1 Fall 2012

CS 1301 Exam 1 Fall 2010

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 4: Control Structures I (Selection)

Introduction to Programming I COS1511 School of Computing Revision Notes

CSCI 528: OBJECT ORIENTED PROGRAMMING, Fall 2015

Introduction to Programming

Section 001. Read this before starting!

do { statements } while (condition);

Transcription:

Final Exam, Version 1 CSci 127: Introduction to Computer Science Hunter College, City University of New York 17 May 2018 Exam Rules Show all your work. Your grade will be based on the work shown. The exam is closed book and closed notes. When taking the exam, you may have with you pens, pencils, and an 8 1/2 x 11 piece of paper filled with notes, programs, etc. You may not use a computer, calculator, tablet, smart watch, or other electronic device. Do not open this exams until instructed to do so. Hunter College regards acts of academic dishonesty (e.g., plagiarism, cheating on examinations, obtaining unfair advantage, and falsification of records and official documents) as serious offenses against the values of intellectual honesty. The College is committed to enforcing the CUNY Policy on Academic Integrity and will pursue cases of academic dishonesty according to the Hunter College Academic Integrity Procedures. I understand that all cases of academic dishonesty will be reported to the Dean of Students and will result in sanctions. Name: EmpID: Signature:

1. (a) What will the following Python code print: i. a = "Jan&Feb&Mar&Apr&May&Jun" print(a.count("&")) ii. b = a.split("&") print(b[0]) iii. mo = b[-1].upper() print(mo) iv. for c in mo: print(c.lower()) (b) Consider the following shell commands: $ ls -l -rw-r--r--@ 1 stjohn staff 5308 Mar 21 14:38 quizzes.html -rw-r--r-- 1 stjohn staff 54013 Apr 20 18:57 zonedist.csv -rw-r--r--@ 1 stjohn staff 1519 Apr 22 15:14 zonemap.py -rw-r--r-- 1 stjohn staff 16455174 Mar 20 19:02 zoning2.html -rw-r--r-- 1 stjohn staff 17343896 Mar 20 18:58 zoningids.json i. What is the output for: $ ls *zz* ii. What is the output for: $ ls -l grep "Apr" iii. What is the output for: $ ls -l grep "Apr" wc -l 1

2. (a) After executing the Python code, write the name of the turtle: import turtle turtle.colormode(255) lily = turtle.turtle() lily.color(0,255,0) silvena = turtle.turtle() silvena.color(0,0,1.0) alvin = turtle.turtle() alvin.color("#bbbbbb") jesse = turtle.turtle() jesse.color("#aa0000") i. which is blue: ii. which is pink: iii. which is green: iv. which is gray: (b) Write the Python code for the following algorithm: Ask user for input, and store in the string, octstring. Set decnum = 0. For each c in octstring, Set n to be int(c) Multiple decnum by 8 and add n to it Print decnum 2

3. (a) What is the value (True/False): i. ii. iii. in1 = True in2 = False out = in1 and in2 in1 = False in2 = True out = not in1 and (in2 or not in1) in1 = True in2 = False or not in1 in3 = in1 and in2 out = in1 or not in3 out = out = out = iv. in1 = False in2 = False out = (b) Design a circuit that implements the logical expression: ((not in1) and (in1 or in2)) or (not in3) 3

4. (a) Draw the output for the function calls: i. ramble(tess,0) import turtle tess = turtle.turtle() tess.shape("turtle") def ramble(t,side): if side == 0: t.stamp() else: for i in range(side): t.forward(50) t.left(360/side) ii. ramble(tess,6) (b) For the following code: def v1(vincent, munem): def start(): if vincent + munem > 0: panda = 20 return vincent minh = -30 else: qiuqun = v1(panda,minh) return -1 return qiuqun i. What are the formal parameters for v1(): ii. What are the formal parameters for start(): iii. What does start() return: 4

5. Write a complete Python program that asks the user for words (separated by spaces) and prints the number that end in t. For example: If the user entered: that tempest tea pot Your program should print: 3 5

6. Write a complete Python program that asks the user for the name of a.png (image) file and displays the upper right quarter of the image. For example if the image is hunterlogo.png (left), the displayed image would be (right): 6

7. Fill in the following functions that are part of a program that maps GIS data from NYC OpenData CSV files: getdata(): asks the user for the name of the CSV and returns a DataFrame of the contents. getlocale(): asks the user for latitude and longitude of the user s current location and returns those floating points numbers, and computedist(): computes the squared distance between two points (x1,y1) and (x2,y2): (x1 x2) 2 + (y1 y2) 2 import pandas as pd def getdata(): Asks the user for the name of the CSV and Returns a dataframe of the contents. def getlocale(): Asks the user for latitude and longitude of the user s current location and Returns those floating points numbers. def computedist(x1,y1,x2,y2): Computes the squared distance between two points (x1,y1) and (x2,y2) and Returns (x1-x2)^2 + (y1-y2)^2 7

8. (a) What are the values of register, $s0 for the run of this MIPS program: #Sample program that loops from 20 down to 0 ADDI $s0, $zero, 20 #set s0 to 20 ADDI $s1, $zero, 5 #use to decrement counter, $s0 ADDI $s2, $zero, 0 AGAIN: SUB $s0, $s0, $s1 BEQ $s0, $s2, DONE J AGAIN DONE: #To break out of the loop #use to compare for branching Values of $s0: (b) Write a MIPS program where the register, $s0 loops through the values: 4,8,12 8

9. What is the output of the following C++ programs? (a) //Walt Whitman #include <iostream> using namespace std; int main() { cout << "Be curious,\nnot"; cout << "judgmental." << endl; cout << "--W. Whitman" << endl; } (b) //Greetings! #include <iostream> using namespace std; int main() { cout << "Hi" << endl; int x = 2; while (x > 2) { cout <<"Again\n"; x--; } cout << "Bye" } (c) //Pluses and minuses #include <iostream> using namespace std; int main() { int i, j; for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) if ((i+j) % 2 == 0) cout << "+"; else cout << "-"; cout << endl; } } 9

10. (a) Write a complete Python program that prompts the user for a string until a non-empty string is entered. The program then prints the non-empty string that was entered. (b) Write a complete C++ program that prints the change in population of predator and prey following the Lotka-Volterra model: r = 2r.25rf f = 0.95f +.1rf where r is the number of prey (such as rabbits) each year and f is the number of predators (such as foxes) each year. The rabbit population doubles each year, but rf 4 are eaten by foxes. The fox population decreases by 5% due to old age but increases in proportion to the food supply, rf 10. Assume that the starting population of prey (rabbits) is 1000 and starting population of predators (foxes) is 100. Your program should print for the first 10 years: the year, the number of prey and the number of predators. 10