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

Similar documents
Final Exam, Version 3 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 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 4 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 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

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 Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

CSci 127: Introduction to Computer Science

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

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

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. Dr. Khalil Exam II Fall 2011

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

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

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

Final Examination Semester 2 / Year 2005

CSci 127: Introduction to Computer Science

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

In this chapter you will learn:

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

Read this before starting!

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

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

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

CS101 PLEDGED SPRING 2001

CSci 127: Introduction to Computer Science

Algorithmic Approaches for Biological Data, Lecture #1

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

ARTIFICIAL INTELLIGENCE AND PYTHON

Read this before starting!

OPEN BOOK, OPEN NOTES. NO COMPUTERS, OR SOLVING PROBLEMS DIRECTLY USING CALCULATORS.

Read this before starting!

Section 001. Read this before starting!

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

CSCE 206: Structured Programming in C++

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

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

Programming Language. Functions. Eng. Anis Nazer First Semester

Lecture 23: Pointer Arithmetic

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

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

CSci 1113 Final. Name: Student ID:

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

Increment and the While. Class 15

Read this before starting!

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

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

University of Dublin

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

Ch 6. Functions. Example: function calls function

CSci 127: Introduction to Computer Science

East Tennessee State University Department of Computer and Information Sciences CSCI 4717 Computer Architecture TEST 3 for Fall Semester, 2006

Chapter 1: Why Program? Computers and Programming. Why Program?

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

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.

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Second Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 11 November 2010

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

Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python.

CSCI 1370 APRIL 26, 2017

Shell / Python Tutorial. CS279 Autumn 2017 Rishi Bedi

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

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

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

CSCE 2014 Final Exam Spring Version A

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

Department of Computer Science Duke University Ph.D. Qualifying Exam. Computer Architecture 180 minutes

Read this before starting!

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

Tutorial Letter 103/1/2017 Introduction to Programming I

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

CSCI 528: OBJECT ORIENTED PROGRAMMING, Fall 2015

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

East Tennessee State University Department of Computer and Information Sciences CSCI 4717 Computer Architecture TEST 3 for Fall Semester, 2005

CSCI544, Fall 2016: Assignment 1

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

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

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

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

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

CSci 1113 Midterm 1. Name: Student ID:

Al Imam Mohammad Ibn Saud Islamic University College of Computer and Information Sciences Computer Science Department

CS 151 Final. Q1 Q2 Q3 Q4 Q5 Total Credit Score. Instructions: Student ID. (Last Name) (First Name) Signature

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, November 24, 2015

CPT101- Principles of Programming

Unit 6. Thinking with Functions

Chapter 3. More Flow of Control

EP241 Computing Programming

Lab 3: Control Flow / Conditional Statements. Based on the presentation made by Graham Northup

CS 141, Introduction to Computer Science Fall Midterm Exam

Computer Programming : C++

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

CSI33 Data Structures

Continental Mathematics League

Transcription:

Final Exam, Version 2 CSci 127: Introduction to Computer Science Hunter College, City University of New York 22 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 = "Mon*Tue*Wed*Thu*Fri" print(a.count("*")) ii. b = a.split("*") print(b[0]) iii. day = b[-1].upper() print(day) iv. for c in mo: print(c.lower()) (b) Consider the following shell commands: $ ls nyc.csv p40.py p41.py trees.csv i. What is the output for: $ ls *.csv ii. What is the output for: $ ls *.csv wc -l iii. What is the output for: $ mkdir data $ mv *.csv data $ ls wc -l 1

2. (a) After executing the Python code, write the name of the turtle: import turtle turtle.colormode(255) basak = turtle.turtle() basak.color(0,0,255) jimmy = turtle.turtle() jimmy.color(1.0,0.0,1.0) katherine = turtle.turtle() katherine.color("#cccccc") jiaxing = turtle.turtle() jiaxing.color("#990000") i. which is purple: ii. which is pink: iii. which is blue: iv. which is gray: (b) Write the Python code for the following algorithm: function decodemessage(numberlist, k) Create an empty message For each number in the list, numberlist code = 97 + ((number + k) modulo 26) Convert the code to the corresponding Unicode character Concatenate the character to the beginning of the message Return the message 2

3. (a) What is the value (True/False): i. ii. iii. in1 = False in2 = True out = in1 or in2 in1 = True in2 = True out = not in1 or (in2 and not in1) in1 = False in2 = True and not in1 in3 = in1 or in2 out = in1 or not in3 out = out = out = iv. in1 = True in2 = True out = (b) Design a circuit that implements the logical expression: ((in1 or in2) and (in1 or in3)) 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,3) (b) For the following code: def v2(jaime, lily): def start(): if jaime + lily > 10: gwenael = 8 return lily karen = 10 else: katherineh = v2(gwenael,karen) return -1 return katherineh i. What are the formal parameters for v2(): 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 numbers (separated by spaces) and prints the how many end in 5. For example: If the user entered: 101 15 50 645 Your program should print: 2 5

6. Write a complete Python program that asks the user for the name of a.png (image) file and displays the upper left 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 creates a graph of the fraction of population over time: getdata(): asks the user for the name of the CSV and returns a DataFrame of the contents, makefraction(): creates a column of the fraction of the two columns, and makegraph(): makes a scatter plot of the x versus y columns specified. import pandas as pd import matplotlib.pyplot as plt def getdata(): Asks the user for the name of the CSV. Returns a DataFrame of the contents. def makefraction(df,top,total,frac): Makes a new column, frac, of df that is df[top]/df[total] Returns the DataFrame, df def makegraph(df,xcol,ycol): Makes a pyplot scatter plot of x versus y columns of DataFrame df 7

8. (a) What are the values of register, $s0 for the run of this MIPS program: #Sample program that loops from 25 down to 5 ADDI $s0, $zero, 20 #set s0 to 20 ADDI $s1, $zero, 5 #use to decrement counter, $s0 ADDI $s2, $zero, 5 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,6,8,10 8

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

10. (a) Write a complete Python program that asks the user for the year they were born. If they enter a number before 1900, the program continues to ask for the year they were born. The program then prints the year that was entered. (b) Write a complete C++ program that prints the change in population of the state of New York: p = p + Bp Dp where p is the population, B is the birth rate of 12 births for every 1000 people ( 12 1000 ) each year, and D is the death rate of 7.8 for every 1000 people ( 7.8 1000 ). In 2017, the population of New York State was 19.85 million. Your program should print expected population over the 10 years from 2017 to 2026. Each line should have: the year and the population (in millions). 10