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

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

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

Final Exam, Version 1 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 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

Final Exam, Version 3 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 2 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

CSci 127: Introduction to Computer Science

CSci 127: Introduction to Computer Science

Answer Key: CIS 166 Final Exam, Version 1, Spring 2015

CSci 127: Introduction to Computer Science

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

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.

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

a. a * c - 10 = b. a % b + (a * d) + 7 =

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

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

CS150 Sample Final. Name: Section: A / B

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

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

CS150 Sample Final Solution

Exam 3 Chapters 7 & 9

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

ARTIFICIAL INTELLIGENCE AND PYTHON

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

2. For each of the regular expressions, give a string that will matches it:

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

CSI33 Data Structures

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

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

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

Name Section: M/W or T/TH. True or False (14 Points)

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

INTERMEDIATE PYTHON FOR DATA SCIENCE. Comparison Operators

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.

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

Programming Language. Functions. Eng. Anis Nazer First Semester

Lab 8 - Subset Selection in Python

Linked List using a Sentinel

Total. Name: Signature: Circle course section: MW 9-11 MW 11-1 MW 6-8 TTh 9-11 TTh 1-3

CS101 PLEDGED SPRING 2001

Definition Matching (10 Points)

CMPS 221 Sample Final

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

EE 109 Lab 8a Conversion Experience

CS 1301 Exam 1 Fall 2009

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Lecture 23: Pointer Arithmetic

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

Math 1MP3, final exam

Chapter 2: Introduction to C++

Skills Quiz - Python Edition Solutions

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

CHAPTER 3 BASIC INSTRUCTION OF C++

Problem Solving: Storyboards for User Interaction

Python for Data Analysis. Prof.Sushila Aghav-Palwe Assistant Professor MIT

Text File I/O. #include <iostream> #include <fstream> using namespace std; int main() {

CSCE 2014 Final Exam Spring Version A

CAAM 420 Fall 2012 Lecture 29. Duncan Eddy

Computer Programming

Python Tutorial for CSE 446

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

Python Tutorial for CSE 446

Chapter 1 INTRODUCTION

Perfect square. #include<iostream> using namespace std; int main(){ int a=1; int square; while(true){ } cout<<square<<endl; }

2. For each of the regular expressions, give a string that will matches it:

Chapter 2. C++ Syntax and Semantics, and the Program Development Process. Dale/Weems 1

Midterm Exam 5 April 20, 2015

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

Control Flow: Loop Statements

IMPORTING & MANAGING FINANCIAL DATA IN PYTHON. Read, inspect, & clean data from csv files

CS 1301 Exam 1 Answers Fall 2009

Clustering to Reduce Spatial Data Set Size

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

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

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

Chapter 17 - Notes Recursion

Answer Key: CIS 166 Final Exam, Version 3, Spring 2015

CSci 127: Introduction to Computer Science

COMP322 - Introduction to C++ Lecture 01 - Introduction

REVIEW. The C++ Programming Language. CS 151 Review #2

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

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

VARIABLES & ASSIGNMENTS

STA141C: Big Data & High Performance Statistical Computing

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Homework Assignment #2 (revised)

CSc Introduction to Computing

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

CMPSCI 119 Fall 2018 Wednesday, November 14, 2018 Midterm #2 Solution Key Professor William T. Verts

CPE Summer 2015 Exam I (150 pts) June 18, 2015

Name SECTION: 12:45 2:20. True or False (12 Points)

Transcription:

Mock Final Exam CSci 127: Introduction to Computer Science Hunter College, City University of New York 15 May 2018 1. (a) What will the following Python code print: i. s = "Ada:)Lovelace:)Grace:)Hopper" a = s[0:3] print(a.upper()) ADA ii. names = s.split(":)") print(names[-1]) Hopper iii. b,c,d = names[1],names[2],names[3] print(b,d) Lovelace Hopper iv. print(b[-1]+"n"+d[-2]+"ine") print( Put_line: (", a.lower(), ") ) 0

eneine Put_line: (" ada ") (b) Consider the following shell commands: $ ls -l *z* -rw-r--r--@ 1 stjohn staff 5308 Mar 21 14:38 quizzes.html -rw-r--r-- 1 stjohn staff 54013 Mar 20 18:57 zonedist.csv -rw-r--r--@ 1 stjohn staff 1519 Mar 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 -l *z* grep ".html" -rw-r--r--@ 1 stjohn staff 5308 Mar 21 14:38 quizzes.html -rw-r--r-- 1 stjohn staff 16455174 Mar 20 19:02 zoning2.html ii. What is the output for: $ ls -l *z* grep ".html" wc -l 2 2. (a) Fill in the missing code below: #Demonstrates colors, using turtles import turtle tess = turtle.turtle() #Set color of tess to blue: tess.color("blue") #Set color of tess to maximum red, no green, and maximum blue: tess.color(255,0,255) #Set color of tess using hexcodes: red, green, and blue all equal to "A0": 1

tess.color("#a0a0a0") (b) Write the Python code for the following algorithm: Ask user for input, and store in the string, binstring. Set decnum = 0. For each c in binstring, Set n to be int(c) Double decnum and add n to it (decnum = 2 * decnum + n) Print decnum #binary to decimal binstring = input( Enter num: ) decnum =0 for c in binstring: n = int(c) decnum = decnum * 2 + n print(decnum) 3. (a) What is the value (True/False): in1 = False i. in2 = True out = in1 and in2 out = False ii. in1 = False in2 = True out = not in1 or (in2 and not in1) out = True iii. in1 = False in2 = False or not in1 in3 = in1 and in2 out = in1 and not in3 out = False 2

iv. in1 = True in2 = False out = True (b) Design a circuit that implements the logical expression: ((not in1) and (in1 or not in2)) and (in3 or not in3) 4. (a) Draw the output for the function calls: import turtle tess = turtle.turtle() tess.shape("turtle") i. ramble(tess,0) ii. ramble(tess,50) def ramble(t,length): if length < 10: t.stamp() else: t.forward(length) t.left(90) ramble(t,length-10) Answer Key: Answer Key: (b) What is returned when the function is invoked on the inputs below: def gee(a,b): while a!= b: if a > b: a = a - b else: 3

return a i. gee(1,1) b = b - a 1 ii. gee(2,3) 1 iii. gee(2,4) 2 iv. gee(16,24) 8 5. Write a complete Python program that uses folium to make a map of New York City. Your map should be centered at (40.75, 74.125) and include a marker for the main campus of Hunter College. The HTML file your program creates should be called: nycmap.html. #Make a map centered in NYC and with popup marker for Hunter import folium mapcuny = folium.map(location=[40.75, -74.125], zoom_start=10) folium.marker(location = [40.768731, -73.964915], popup = "Hunter College").add_to(mapCUNY mapcuny.save(outfile= nycmap.html ) 6. Using matplotlib.pyplot and numpy, write a complete Python program that reads in an array (grid) of elevations, elevations.txt. Your program should create an image where for each element of the array, the corresponding pixel is colored in the final image is: colored blue if the elevation is 0 or less, black if the elevation is positive and divisible by 10, and gray otherwise. Your resulting image should be stored in a file, topomap.png. # Takes elevation data of NYC and displays a contour map 4

#Import the libraries for arrays and displaying images: import numpy as np import matplotlib.pyplot as plt #Read in the data to an array, called elevations: elevations = np.loadtxt( elevationsnyc.txt ) #Take the shape (dimensions) of the elevations # and add another dimension to hold the 3 color channels: mapshape = elevations.shape + (3,) #Create a blank image that s all zeros: topomap = np.zeros(mapshape) for row in range(mapshape[0]): for col in range(mapshape[1]): if elevations[row,col] <= 0: #Below sea level topomap[row,col,2] = 0.5 elif elevations[row,col] % 10 == 0: topomap[row,col,0] = 0.0 topomap[row,col,1] = 0.0 topomap[row,col,2] = 0.0 else: topomap[row,col,0] = 0.3 topomap[row,col,1] = 0.3 topomap[row,col,2] = 0.3 #Save the image: plt.imsave( topomap.png,topomap) 7. Fill in the following functions that are part of a program that analyzes NYC Urban Forest of street trees (from NYC OpenData): getdata(): asks the user for the name of the CSV file and returns a DataFrame of the contents. totaltrees(): returns the number of trees (length) in the DataFrame, and biggestdiameter(): returns the largest diameter (tree dbh) in the DataFrame. import pandas as pd def getdata(): 5

Asks the user for the name of the CSV and Returns a dataframe of the contents. filename = input( Enter file name: ) df = pd.read_csv(filename) return(df) def totaltrees(df): Takes a DataFrame as input. Returns the length of the DataFrame. length = len(df) return(length) def biggestdiameter(df): Takes a DataFrame as input and Returns the maximum value in the column, tree_dbh. M = df[ tree_dbh ].max() return(m) 8. (a) What is the output for a run of this MIPS program: 6

# Store Help!! at the top of the stack ADDI $sp, $sp, -7 ADDI $t0, $zero, 72 # H SB $t0, 0($sp) ADDI $t0, $zero, 101 # e SB $t0, 1($sp) ADDI $t0, $zero, 108 # l SB $t0, 2($sp) ADDI $t0, $zero, 112 # p SB $t0, 3($sp) ADDI $t0, $zero, 33 #! SB $t0, 4($sp) ADDI $t0, $zero, 33 #! SB $t0, 5($sp) ADDI $t0, $zero, 0 # (null) SB $t0, 6($sp) ADDI $v0, $zero, 4 # 4 is for print string ADDI $a0, $sp, 0 syscall # print to the log Help!! (b) Write a MIPS program that prints: Hi! Hi! # Store Hi mom at the top of the stack ADDI $sp, $sp, -7 ADDI $t0, $zero, 72 # H SB $t0, 0($sp) ADDI $t0, $zero, 105 # i SB $t0, 1($sp) ADDI $t0, $zero, 33 #! SB $t0, 2($sp) ADDI $t0, $zero, 32 # (space) SB $t0, 3($sp) ADDI $t0, $zero, 72 # H SB $t0, 4($sp) ADDI $t0, $zero, 105 # i SB $t0, 11($sp) ADDI $t0, $zero, 33 #! SB $t0, 2($sp) ADDI $t0, $zero, 0 # (null) SB $t0, 12($sp) ADDI $v0, $zero, 4 # 4 is for print string 7

ADDI $a0, $sp, 0 syscall # print to the log 9. What is the output of the following C++ programs? (a) //Lewis Carroll, Alice in Wonderland #include <iostream> using namespace std; int main() { cout << "Take care of the sense, "<< endl; cout << "and the sounds will \n take care"; cout << "of themselves." << endl cout << endl; Take care of the sense, and the sounds will take care of themselves. (b) //Lewis Carroll, more Alice... #include <iostream> using namespace std; int main() { int count = 2; while (count > 0) { cout <<"Twinkle, "; count--; cout << "little bat!" Twinke, Twinke, little bat! 8

(c) //Stars and more stars #include <iostream> using namespace std; int main() { int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <= i; j++) cout << "*"; cout << endl; * ** *** **** ***** 10. (a) Write a complete Python program that prompts the user for a string and then prints the string in reverse. For example, if the user entered, Python, your program would print: nohtyp. #Reversing program: s = input( Enter a string ) news = "" for c in s: news = c + news print(news) Here s another #Another Reversing program: Many ways to do this program. Here s one: s = input( Enter a string ) news = "" for i in range(len(s)-1, -1,-1): news = news + s[i] print(news) (b) Write a complete C++ program that prints the spread of disease, following the Susceptible, Infected, Recovered (SIR) model: S =.95S I = I +.05S.04I R = R +.04I 9

where S is the size of the susceptible population, I is the number of currently infected in the population, and R is the number who have recovered. Each day, 4% of those ill recover and 5% of the susceptible population becomes infected. Assume that the starting susceptible population at year 0 is 1000 with 100 infected and 100 recovered. Your program should print for the first 10 days: the day, the number of susceptible population, the number currently infected, and the number who have recovered. //Checks input for positive number #include <iostream> using namespace std; int main() { float S = 1000, I = 100, R = 100; int day; cout << "Day\tSusceptible\tInfected\tRecovered\n"; for (day = 0; day < 10; day++) { cout << day << "\t" << S << "\t" << I << "\t" << R << "\n"; S =.95*S; I = I + 0.05*S - 0.04*I; R = R + 0.04I; return 0; 10