Docsity

Sample Final Exam CSci 127, Schemes and Mind Maps of Computer Science

Toggle sidebar
bg1
Sample Final Exam
CSci 127: Introduction to Computer Science
Hunter College, City University of New York
Fall 2017
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:
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Sample Final Exam CSci 127 and more Schemes and Mind Maps Computer Science in PDF only on Docsity!

Sample Final Exam

CSci 127: Introduction to Computer Science

Hunter College, City University of New York

Fall 2017

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:

months = ["Jan","Feb","Mar","Apr","May",
"Jun","Jul","Aug","Sep","Oct","Nov","Dec"] half = months[6] print(half.upper()) print(half[0]) print(months[-1].lower()) print(months[2:4]) start = 9 print(months[start-1]) term = 3 print(months[(start+term-1)%12])

Answer Key: JUL J dec [’Mar’, ’Apr’] Sep Dec

(b) Consider the following shell command and resulting output:

ls t* t.html test.png trash.html turtle2.py tc.htmk testSubprocess.py trashCans.csv turtle3.py tc.html th.html triangles.py

test: herd.py makeDirs* projectFiles/ i. What is the output for: ls t*.png

Answer Key: test.png

ii. What is the output for: ls t* | grep ".p" | sort

Answer Key: herd.py test.png

for col in range(mapShape[1]):

Answer Key: if elevations[row,col] <= 0: #Below sea level floodMap[row,col,2] = 1.0 #Set the blue channel to 100% else: #Above sea level floodMap[row,col,1] = 1.0 #Set the green channel to 100% #Save the image: plt.imsave(’floodMap.png’, floodMap)

  1. (a) What is the value (True/False):

i.

in1 = True in2 = False out = in1 and in

Answer Key: out = False

ii.

in1 = False in2 = False out = in1 and (in2 or not in1)

Answer Key: out = True

iii.

in1 = True in2 = False in3 = (in1 or in2) out = in1 and not in

Answer Key: out = False

iv.

in1 = False in2 = False

Answer Key: out1 = False out2 = False

(b) Design a circuit that takes a single input and always outputs True.

Answer Key:

  1. (a) Draw the output of the program: #Mystery program... import turtle

tH = turtle.Turtle()

for i in range(10,255,10): tH.color((i,i,i)) tH.forward(i) th.left(90)

Answer Key: (b) What is the output:

#Collisions program import folium import pandas as pd

inF = input(’Enter CSV file name: ’) outF = input(’Enter output file: ’) df = pd.read_csv(inF)

map311 = folium.Map(location=[40.768731, -73.964915], tiles="Cartodb Positron",zoom_start=

for index,row in df.iterrows(): lat = row["LATITUDE"] lon = row["LONGITUDE"] name = row["TIME"] newMarker = folium.Marker([lat, lon], popup=name) newMarker.add_to(map311)

map311.save(outfile=outF)

  1. Complete the following Python program, which creates a green turtle, draws a decagon (10-sided figure) to the window, and then prints a closing message. That is, write the functions setUp(), drawDecagon(), and conclusion():

import turtle

def main(): t = setUp() #creates a green turtle drawDecagon(t) #draws a decagon using the turtle conclusion() #prints goodbye

if name == "main": main()

Answer Key:

def setUp(): trey = turtle.Turtle() trey.color("green") return(trey)

def drawDecagon(t): for i in range(10): t.forward(100) t.right(360/10)

def conclusion():

print("Goodbye!")

  1. (a) What are the values of register, $s0 for the run of this MIPS program:

#Sample program that loops from 10 down to 0 ADDI $s0, $zero, 10 #set s0 to 10 ADDI $s1, $zero, 2 #use to decrement counter, $s AGAIN: SUB $s0, $s0, $s BEQ $s0, $zero, DONE J AGAIN DONE: #To break out of the loop Values of $s0:

Answer Key: 10 8 6 4 2 0 (b) Write a MIPS program where the register, $s0 loops through the values: 1,2,3,4,

Answer Key:

#Program that loops from 1 upto 5 ADDI $s0, $zero, 1 #set s0 to 1 ADDI $s1, $zero, 1 #use to increment counter, s ADDI $s2, $zero, 5 #set s2 to use for comparison AGAIN: ADD $s0, $s0, $s BEQ $s0, $s2, DONE J AGAIN DONE: #To break out of the loop

  1. What is the output of the following C++ programs?

(a)

//Mystery C++ #include using namespace std; int main() { cout << "Get your education" << endl; cout << "Don’t forget from "; cout << "whence you came\n"; }

Answer Key:

#Asks for 5 numbers and prints total total = 0 for i in range(5): n = float(input(’Enter a number: ’)) total = total + n print("Total is", total)

(b) Write a complete C++ program that repeatedly prompts the user for a number until one that is strictly larger than 0 is entered. Your program should print out the final number the user entered.

Answer Key: //Checks input for positive number #include using namespace std; int main() { cout << "Please enter age: "; int age = 0; cin >> age; while (age < 0) { cout << "You entered a negative number.\n"; cout << "Please enter age: "; cin >> age; } cout << "You entered your age as: " << age; return 0; }