cs127Final_f22_v3

pdf

School

CUNY Hunter College *

*We aren’t endorsed by this school

Course

13200

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

87

Uploaded by DeaconHornetPerson130

Report
Row: Seat: Final Exam F22 V3 CSci 127: Introduction to Computer Science Hunter College, City University of New York December 19, 2022 Exam Rules Show all your work. Your grade will be based on the work shown. The exam is closed book and closed notes with the exception of an 8 1/2” x 11” piece of paper filled with notes, programs, etc. When taking the exam, you may have with you pens and pencils, and your note sheet. You may not use a computer, calculator, tablet, phone, earbuds, or other electronic device. Do not open this exam 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 o ffi cial documents) as serious o enses 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: Email: Signature:
(Image from wikipedia commons)
EmpID: CSci 127 Final, F22, V3 1. (a) Fill in the code below to produce the output on the right: colors=’Red-Green-Blue-Yellow-Cyan’ i. green = colors[ ] print(green) Output: Green ii. yellow green = for s in yellow_green: print( ) Output: yellow green (b) Consider the following shell commands: $ pwd /usr/staff $ ls a.out hello.py p50_growth.cpp p60_binary.cpp i. What is the output for: $ rm a.out $ mv hello.py p1_hello.py $ mkdir progs $ mv *.cpp progs $ ls Output: ii. What is the output for: $ cd progs $ pwd Output: iii. What is the output for: $ cd .. $ ls | grep p | wc -l Output: 1
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F22, V3 2. (a) Select the color corresponding to the rgb values below: i. rgb = (100, 0, 0) black red cyan gray purple ii. rgb = "#FFFFFF" red green blue black white iii. What is rgb values for cyan? 0, 0, 1 0, 1, 1 1, 0, 0 1, 0, 1 1, 1, 0 iv. What is the binary number equivalent of decimal number 69? Decimal 69 = Binary v. What is the Decimal number equivalent to Hexadecimal A6? Hexadecimal A6 = Decimal (b) Given the list fruits below, fill in the code to produce the Output on the right: fruits = [’apple’, ’banana’, ’coconut’, ’dragon fruit’, ’elderberry’] i. for j in range( ): print(fruits[ ]) Output: coconut banana apple ii. import numpy as np import matplotlib.pyplot as plt img = np.ones( (10,10,3) ) img[ , ] = 0 plt.imshow(img) plt.show() Output: iii. import numpy as np import matplotlib.pyplot as plt img = np.ones( (10,10,3) ) img[ , ] = 0 plt.imshow(img) plt.show() Output: 2
EmpID: CSci 127 Final, F22, V3 3. (a) What is the value (True/False): i. in1 = True in2 = False out = not (not in1 or in2) True False ii. in1 = True in2 = False in3 = True out = not (in1 and not in2) or not in3 True False iii. in1 = True in2 = False in3 = in1 and not in2 out = not in1 and (in2 or not in3) True False iv. in1 = False in2 = True in3 = False True False (b) Draw a circuit that implements the logical expression: (not in1 and in2) or (in1 and (in2 or not in3)) 3
EmpID: CSci 127 Final, F22, V3 4. Consider the following functions: def count(mylist , target ): num_occur = 0 for num in mylist: if leq(num , target ): num_occur += 1 return num_occur def leq(s, t): return s <= t def main (): crr = [21, 32, -55, 91, -26, 72, 1] print(count(crr , 32)) (a) What are the formal parameters for leq() ? (b) What are the actual parameters for count() ? (c) How many calls are made to leq() after calling main() ? (d) What is the output after calling main() ? Output: 4
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F22, V3 5. Design an algorithm that asks the user for the name of a text file containing a grid of numbers and loads it into a 2D array of integers(think like an image without the color channel) and a threshold. The program outputs the sum of all elements in the grid that are larger than or equal to the threshold. For example, suppose the grid has values [[1 2] [3 4]] and the given threshold is 3. Then the sum is 3 + 4 = 7. Libraries: Input: Output: Design Pattern: Find Min Find Max Find All Principal Mechanisms (select all that apply): Single Loop Nested Loop Conditional (if/else) statement Indexing / Slicing split() groupby() Process (as a concise and precise LIST OF STEPS / pseudocode): (Assume libraries have already been imported.) 5
EmpID: CSci 127 Final, F22, V3 6. Consider the violations.csv dataset that reports violations issued by Business Integrity Com- mission for companies operating in the trade waste industry. A snapshot given in the image below: Assume we write import pandas as pd already. Fill in the Python program below: #Read input data into data frame: df = #Print the min value in column ’NUMBER OF COUNTS’. #Groups the data by ’VIOLATION ACCOUNT POSTCODE’ to extract data in 10474. zip10474 = #Print the average of FINE AMOUNT in zip10474. #Print the most common (aka top) TEN rules violated. #Hint: look at ’DESCRIPTION OF RULE’ and value_counts method. 6
EmpID: CSci 127 Final, F22, V3 7. Complete the following code in Python. Define diffFreq function, for strings s1 and s2, char ch, see whether s1 and s2 have di erent number of occurrences of ch. For example, the return of diffFreq(’abc’, ’acd’, ’a’) is false since ’a’ appears in same frequency in ’abc’ and ’acd’, but the return of diffFreq(’abc’, ’acd’, ’b’) is true since ’b’ has di erent number of occurrences in ’abc’ and ’acd’. Define existDiffFreq function, for strings s1, s2, and s3, check whether s1 and s2 have di erent number of occurrences for some letter in s3. For example, existDi Freq(’abcd’, ’bcae’, ’abc’) returns false, since each letter in s3 has the same frequency in s1 and s2, but existDi Freq(’abcd’, ’bcae’, ’abd’) returns true since letter ’d’ in s3 has di erent frequency in s1 and s2. Hints: once you encounter a letter in s3 that has di erent number of occurrences in s1 and s2, can you stop and know what existDiffFreq function should return immediately? What if after testing every letter in s3, and each one has the same number of occurrences in s1 and s2? 7
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F22, V3 8. (a) What does the MIPS program below print: Output: (b) Modify the program to print out string ”86420”. Shade in the box for each line that needs to be changed and rewrite the instruction below. Warning: you need to modify from the above code. Need to use j and beq commands. ADDI $sp, $sp, -5 # Set up stack ADDI $t0, $zero, 103 # Set $t0 at 103 (’g’) ADDI $s2, $zero, 4 # Use to test when you reach 4 SETUP: SB $t0, 0($sp) # Next letter in $t0 ADDI $sp, $sp, 1 # Increment the stack ADDI $s2, $s2, -1 # Decrement the counter by 1 ADDI $t0, $t0, 1 # Increase the letter by 1 BEQ $s2, $zero, DONE # Jump to DONE if s2 == 0 J SETUP # Else, jump back to SETUP DONE: ADDI $t0, $zero, 0 # Null (0) to terminate string SB $t0, 0($sp) # Add null to stack ADDI $sp, $sp, -4 # Set up stack to print ADDI $v0, $zero, 4 # 4 is for print string ADDI $a0, $sp, 0 # Set $a0 to stack pointer syscall # Print to the log 8
EmpID: CSci 127 Final, F22, V3 9. Fill in the C++ programs below to produce the Output on the right. (a) #include <iostream> using namespace std; int main() { for(int i = 3; i <= ; ) { cout << i-2 << endl; } return 0; } Output: 1 3 5 7 (b) #include <iostream> using namespace std; int main() { int size = 4; for (int i = 1; i <= size; i++) { for (int j = 0; j < size - i; j++) cout << " "; for (int j = 0; j < i; j++) cout << "*"; cout << endl; } return 0; } Output: (c) #include <iostream> using namespace std; int main(){ int m = 3; int n = 4; while ( m + n <= ) { cout << m << " " << n << endl; //update m n += 3 } return 0; } Output: 3 4 1 7 -1 10 -3 13 9
EmpID: CSci 127 Final, F22, V3 10. (a) Translate the following python program into a complete C++ program : num = - 1 while num < 25 or num > 75: num = int ( input ( ”Enter an i n t e g e r in [25 , 7 5 ] : ” )) print ( ”num =” , num) //include library and namespace //main function signature { //initialization //loop line //loop body { } //print num //return } 10
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F22, V3 (b) Write a C++ code. Declare variables for cm and inch. Declare variable for choice. If choice is 1, then enter number of inch, and convert it to cm and print the result out. Otherwise, enter number of cm, and convert it to inch and print the result out. 1 inch = 2.54 cm 1 cm = 1 / 2.54 inch Some sample input/output is as follows. Enter a choice: 1 Enter number of inch: 5 5 inch = 12.7 cm Enter a choice: 2 Enter number of cm: 2 2 cm = 0.787402 inch Just finish the code in main function. No need to write include library and main function signature and return statement. //declare variables inch and cm. //declare and obtain input for variable choice //Write if-statement when choice is 1, //input inch, convert to cm, and output result. //Write else-statement, input cm, convert to inch, and output result. 11
EmpID: CSci 127 Final, F22, V3 SCRATCH PAPER 12
Row: Seat: Final Exam, Version 3 CSci 127: Introduction to Computer Science Hunter College, City University of New York 23 May 2022 Exam Rules Show all your work. Your grade will be based on the work shown. The exam is closed book and closed notes with the exception of an 8 1/2” x 11” piece of paper filled with notes, programs, etc. When taking the exam, you may have with you pens and pencils, and your note sheet. You may not use a computer, calculator, tablet, phone, earbuds, or other electronic device. Do not open this exam 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 o ffi cial documents) as serious o enses 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: Email: Signature:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, S22, V3 1. (a) Fill in the code below to produce the Output on the right: workdays = "Monday?Tuesday?Wednesday?Thursday?" summer_months = "*June*July*August*" long_weekend = "Friday_Saturday_Sunday" seasons = "+Spring+Summer+Fall+Winter" i. print( ], ]) Output: Spring Tuesday ii. days = long weekend[ ].split( ) print("Our weekend has", len( ),"days.") Output: Our weekend has 3 days. iii. for d in print( ) Output: FRIDAY SATURDAY SUNDAY (b) Consider the following shell commands: $ pwd /Users/guest $ ls bronx.png circuit.txt nand.txt nyc.png temp i. What is the output for: $ mkdir logic $ mv *txt logic $ ls Output: ii. What is the output for: $ cd logic $ ls Output: iii. What is the output for: $ cd ../temp $ pwd Output: 1
EmpID: CSci 127 Final Exam, S22, V3 2. (a) Select the correct option. i. What color is tina after this command? tina.color(1.0,0.0,1.0) black red white gray purple ii. Select the SMALLEST Binary number: 1011 1101 1111 1010 1110 iii. Select the LARGEST Hexadecimal number: AA BA DC CC CD iv. What is the binary number equivalent to decimal 14? 1011 1101 1111 1010 1110 v. What is the hexadecimal number equivalent to decimal 170? AA BA DC CC CD (b) Fill in the code to produce the Output on the right: nums = [ 23, 45, 76, 23, 98, 45 , 11, 4, 33, 29, 5, 66] i. for i in range( , ): print(nums[i], end=" ") Output: 23 98 45 11 4 33 29 ii. for j in range( , , ): print(nums[j], end=" ") Output: 45 45 29 iii. import numpy as np import matplotlib.pyplot as plt img = np.ones( (11,11,3) ) img[ , , :] = 0 # black row img[ , , :] = 0 # black column plt.imshow(img) plt.show() Output: 2
EmpID: CSci 127 Final Exam, S22, V3 3. (a) What is the value (True/False): i. in1 = False in2 = False out = (not in1 and in2) or (not in1 or in2) True False ii. in1 = True in2 = False in3 = ( not in1 ) or ( not in2 ) out = (not in1 or not in2) and (not in2 and in3) True False iii. in1 = True in2 = False in3 = True True False (b) Draw a circuit that implements the logical expression: (not(not in1 or in2)) and (not(in2 and in3) or not in3) 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, S22, V3 4. Consider the following functions: def whoop(n, smile): for i in range(1,n+1): screech(i, smile) print() def screech(i, smirk): for j in range(i): print(smirk, end=’ ’) def main(): whoop(3, ’^_^’) (a) What are the formal parameters for screech() ? (b) What are the actual parameters for whoop() ? (c) How many calls are made to screech() after calling main() ? (d) What is the output after calling main() ? Output: 4
EmpID: CSci 127 Final Exam, S22, V3 5. Design an algorithm that asks the user for the name of an image file and the quarter [’TL’, ’TR’, ’BL’, ’BR’] they wish to ”black-out”, where ’TL’ stands for Top Left, ’BL’ stands for Bottom Right and so on. The algorithm then saves a new image where that quarter of the image is black. The name of the new image is ’XXblack.png’ where XX is replaced by one of [’TL’, ’TR’, ’BL’, ’BR’] that the user entered. You must write detailed pseudocode as a precise list of steps that completely and precisely describe the algorithm. Libraries (if any): Input: Output: Principal Mechanisms (select all that apply): Single Loop Nested Loop Conditional (if/else) statement Indexing / Slicing split() input() Process (as a concise and precise LIST OF STEPS / pseudocode): (Assume libraries, if any, have already been imported.) 5
EmpID: CSci 127 Final Exam, S22, V3 6. Consider boeing.csv from the ”Military Stocks during Russia-Ukraine War ” dataset from kaggle, reporting the Boeing Company’s stock prices (in USD $) from January 2010 to May 2022 Each row in the dataset corresponds to the stock values for one day of trading . A snapshot of the data is given in the image below: Fill in the Python program below: #Import the libraries for plotting and data frames #Prompt user for input file name: fin = #Read input data into data frame: boeing = #Print the average opening value print( ) #Print the lowest closing value print( ) #Create a new column called "Range" that computes #the difference between the highest and lowest value of the stock boeing["Range"] #Plot the newly computed range against the date boeing. plt.show() 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, S22, V3 7. Fill in the following functions that are part of a program that averages the color in an image: getData() : asks the user for the name of an image file and returns a numpy array of the pixels getAvg() : computes and returns the average (r, g, b) values in img avgImg() : returns an image of size rows, cols, with color r, g, b import numpy as np import matplotlib.pyplot as plt def getData(): """ Asks the user for the name of an image file Returns a numpy array of the pixels """ def getAvg(img): """ Computes and returns the average (r, g, b) values in img """ def avgImg(rows, cols, r, g, b): """ Creates and returns an image of size rows, cols, with color r, g, b """ 7
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, S22, V3 8. (a) What is printed by the MIPS program below: Output: (b) Modify the program to print out ”ZYXWV”. Shade in the box for each line that needs to be changed and rewrite the instruction below, or add instructions where necessary. ADDI $sp, $sp, -10 # Set up stack ADDI $s3, $zero, 1 # Store 1 in a register ADDI $t0, $zero, 90 # Set $t0 at 90 (Z) ADDI $s2, $zero, 10 # Use to test when you reach 10 SETUP: SB $t0, 0($sp) # Next letter in $t0 ADDI $sp, $sp, 1 # Increment the stack ADDI $s3, $s3, 1 # Increment the counter by 1 BEQ $s3, $s2, DONE # Jump to done if $s3 == 10 J SETUP # If not, jump back to SETUP for loop DONE: ADDI $t0, $zero, 0 # Null (0) to terminate string SB $t0, 0($sp) # Add null to stack ADDI $sp, $sp, -9 # Set up stack to print ADDI $v0, $zero, 4 # 4 is for print string ADDI $a0, $sp, 0 # Set $a0 to stack pointer for printing syscall # Print to the log 8
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, S22, V3 9. Fill in the C++ programs below to produce the Output on the right. (a) #include <iostream> using namespace std; int main() { for( ; i <=15; ) { cout << i-1 << endl; } return 0; } Output: 3 5 7 9 11 13 (b) #include <iostream> using namespace std; int main() { int n=12, m=-5; while(n+m ) { cout << n << " " << m << endl; n-=2; m++; } return 0; } Output: 12 -5 10 -4 8 -3 6 -2 4 -1 2 0 0 1 (c) #include <iostream> using namespace std; int main(){ for ( ) { for( ) { cout << i << j-i << " "; } cout << endl; } return 0; } Output: 88 87 86 85 84 83 82 81 80 77 76 75 74 73 72 71 70 66 65 64 63 62 61 60 55 54 53 52 51 50 44 43 42 41 40 33 32 31 30 9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, S22, V3 10. (a) Write a complete C++ program that repeatedly asks the user for two integers until their sum is even, then it outputs the sum: //include library and namespace //main function signature { //variable initialization //repeatedly ask for two integers until sum is even //output sum return 0; } 10
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, S22, V3 (b) Write a complete C++ program that asks the user for an amount and computes the number of years it takes to triple the amount, if it is subject to an increase of 5% each year. //include library and namespace //main function signature { //declare variables //obtain input //compute number of years it takes to triple amount at 5% yearly increase //Output number of years and tripled amount return 0; } 11
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Row: Seat: Final Exam, Version 1 CSci 127: Introduction to Computer Science Hunter College, City University of New York 20 December 2021 Exam Rules Show all your work. Your grade will be based on the work shown. The exam is closed book and closed notes with the exception of an 8 1/2” x 11” piece of paper filled with notes, programs, etc. When taking the exam, you may have with you pens and pencils, and your note sheet. You may not use a computer, calculator, tablet, phone, earbuds, or other electronic device. Do not open this exam 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 o ffi cial documents) as serious o enses 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: Email: Signature:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, F21, V1 1. (a) Given the quote in the code below, fill in the code to produce the Output on the right: quote = ’ "Every moment is a fresh beginning." -T.S Eliot-’ i. print(quote[ ]) Output: T.S Eliot ii. print(quote[2:7]. ) Output: EVERY iii. print("This quote has", end=" ") print(quote.count( )-2, "words.") Output: This quote has 6 words. (b) Fill in the code below to produce the Output on the right: i. numbers = "1, 2, 3, 4, 5" num list = numbers. ii. for n in num_list : print( ) Output: 2 3 4 5 6 (c) Consider the following shell commands: $ ls bronx.html logo.png queens.html snow.png i. What is the output for: $ mkdir maps images $ mv *html maps $ ls Output: ii. What is the output for: $mv *.png images $ cd maps $ ls | grep ee Output: iii. What is the output for: $ cd ../ $ ls Output: 1
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, F21, V1 2. (a) Select the color corresponding to the rgb values below: i. rgb = (255, 255, 255) black red white gray purple ii. rgb = "#AB0000" black red white gray purple iii. rgb = (1.0, 0.0, 1.0) black red white gray purple iv. Select the SMALLEST Hexadecimal number: 0F 99 A0 FF C3 v. What is the Binary number equivalent to decimal 40? 110100 011101 101000 000111 101010 (b) Given the list words below, fill in the code to produce the Output on the right: words = [ "fast", "clear", "light", "hot", "cold"] i. for i in range( ): print(words[i], end=" ") Output: fast clear light ii. for j in range( , , ): print(words[j], end=" ") Output: clear cold iii. import numpy as np import matplotlib.pyplot as plt im = np.ones( (10,10,3) ) im[ , , :] = 0 plt.imshow(im) plt.show() Output: iv. import numpy as np import matplotlib.pyplot as plt im = np.ones( (10,10,3) ) im[ , , :] = 0 plt.imshow(im) plt.show() Output: 2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, F21, V1 3. (a) What is the value (True/False): i. in1 = False in2 = True out = not in1 and in2 True False ii. in1 = False in2 = True in3 = in1 or not in2 out = not(in1 or not in2) and not in3 True False iii. in1 = True in2 = True in3 = False True False (b) Draw a circuit that implements the logical expression: (in1 and in2) or not(in1 or not in2) (c) Fill in the circuit with the gate-symbol or gate-name that implements the logical expression: (not in1 or in2) and not(not(in2 and in3) or in3) 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, F21, V1 4. Consider the following functions: def count_larger(l, n): count = 0 for i in range(len(l)): if compare(l[i], n): count += 1 return count def compare(num, comp): return num > comp def main(): numbers = [21, 34, 69, 62, 82, 46, 15] print(count_larger(numbers, 50)) (a) What are the formal parameters for compare() ? (b) What are the actual parameters for count larger ? (c) How many calls are made to compare() after calling main() ? (d) What is the output after calling main() ? Output: 4
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, F21, V1 5. Design an algorithm that asks the user for the name of a text file containing a grid of numbers and loads it into a 2D array of integers (think like an image without the color channel), then outputs the index (row, col) of the LARGEST number in the array. Libraries: Input: Output: Design Pattern: Search Find Min Find Max Find All Principal Mechanisms (select all that apply): Single Loop Nested Loop Conditional (if/else) statement Indexing / Slicing split() input() Process (as a concise and precise LIST OF STEPS / pseudocode): (Assume libraries have already been imported.) 5
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, F21, V1 6. Consider the open restaurants.csv dataset for restaurant reopening applications under Phase Two of the New York Forward Plan to place outdoor seating in front of their business on the sidewalk and/or roadway. Each row in the dataset corresponds to an application . A snapshot of the data is given in the image below: Fill in the Python program below: #Import the libraries for data frames #Prompt user for input file name: csvFile = #Read input data into data frame: df = #Print the number of applications for each Seating Interest # (i.e. number of applications for sidewalk, number for roadway, etc.) print( ) #Group the data by Borough to extract applications in Queens #use groupby and get_group queens = #Print the largest sidewalk area in Queens print( ) 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, F21, V1 7. Consider the Python program below to display the multiplication table for an input number. Fill- in the functions based on the comments and the overall program. Pay attention to the sample output in the comments in-order to implement the function correctly. Note that the sample output for print mult talbe is not complete to save space, your function must display the full multiplication table. # Displays multiplication table n # Example output multiplication table of 3: # 3 X 1 = 3 # 3 X 2 = 6 # . . . # 3 X 9 = 27 # 3 X 10 = 30 def print mult table(n): # Validate the input to be between 1 and 10 # If the input is not in the expected range, # keep asking for the number. # Example output: # Please enter a number between 1 and 10. # Display the multiplication table of? def validate input(num): # Display multiplication table of an input number in range 1 - 10 def main(): num = int(input("Display multiplication table of? ")) num = validate_input(num) #print the multiplication table of num print_mult_table(num) 7
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, F21, V1 8. (a) What does the MIPS program below print: Output: (b) Modify the program to print out Hall! Shade in the box for each line or line-pair that needs to be changed and rewrite the instruction below. If the line needs to be deleted, write Delete . ADDI $sp, $sp, -7 ADDI $t0, $zero, 72 # store 72 in $t0 SB $t0, 0($sp) ADDI $t0, $zero, 101 # store 101 in $t0 SB $t0, 1($sp) ADDI $t0, $zero, 108 # store 108 in $t0 SB $t0, 2($sp) ADDI $t0, $zero, 108 # store 108 in $t0 SB $t0, 3($sp) ADDI $t0, $zero, 111 # store 111 in $t0 SB $t0, 4($sp) ADDI $t0, $zero, 33 # store 33 in $t0 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 # Set $a0 to stack pointer syscall # Print to the log 8
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, F21, V1 (c) Modify the MIPS program below to count from 30 to 0, down by 5. Shade in the box for each line that needs to be changed and rewrite the instruction below. ADDI $s0, $zero, 30 #set s0 to 30 ADDI $s1, $zero, 3 #set s1 to 3 ADDI $s2, $zero, 15 #use to compare for branching AGAIN: SUB $s0, $s0, $s1 BEQ $s0, $s2, DONE J AGAIN DONE: #To break out of the loop (d) After the modification, how many times is the line labeled AGAIN: executed? 9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, F21, V1 9. Fill in the C++ programs below to produce the Output on the right. (a) #include <iostream> using namespace std; int main() { for(int i = 0; i <=30; ) { cout << i*2 << endl; } return 0; } Output: 0 20 40 60 (b) #include <iostream> using namespace std; int main() { int count = 5; int num = 2; while(count && num ) { cout << count << " " << num << endl; count -=1; if(count % 2 == 0) num -=1; } return 0; } Output: 5 2 4 1 3 1 2 0 1 0 (c) #include <iostream> using namespace std; int main(){ for (int i = 5; ; i--) { cout << "Still counting!" << endl; } return 0; } Output: Still counting! Still counting! Still counting! Still counting! Still counting! Still counting! Still counting! Still counting! Still counting! Still counting! 10
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, F21, V1 10. (a) Translate the following python program into a complete C++ program : for i in range(0,10,2): for j in range(i,0,-1): print(i, j) //include library and namespace //main function signature { //outer loop line //inner loop line //loop body //return } 11
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, F21, V1 (b) Write a complete C++ program that asks the user for their age and outputs the age category on a new line as follows: "Child" if the user is 18 or younger "Adult" if the user is older than 18 but less than 65 "Senior" otherwise //include library and namespace //main function signature { //declare variables //obtain input //output age category //return } 12
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, S22, V3 SCRATCH PAPER (page left intentionally blank) 13
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Row: Seat: Final Exam, Version 1 CSci 127: Introduction to Computer Science Hunter College, City University of New York 16 December 2019 Exam Rules Show all your work. Your grade will be based on the work shown. The exam is closed book and closed notes with the exception of an 8 1/2” x 11” piece of paper filled with notes, programs, etc. When taking the exam, you may have with you pens and pencils, and your note sheet. You may not use a computer, calculator, tablet, phone, earbuds, or other electronic device. Do not open this exam 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 o ffi cial documents) as serious o enses 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: Email: Signature:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F19, V1 1. (a) What will the following Python code print: i. pioneers = "Lovelace,Ada-Fleming,Williamina-Hopper,Grace" num = pioneers.count(’,’) num = num + pioneers.count(’-’) print(pioneers[len(pioneers)-num:]) Output: ii. names = pioneers.split(’-’) l = names[0].split(’,’) print(l[1].upper()) Output: iii. for n in names: print(n[0]+’.’) Output: (b) Consider the following shell commands: $ pwd /Users/login/csci127 $ ls elev.csv p50.py p60.py snow.csv i. What is the output for: $ mkdir hwk $ mv *py hwk $ ls Output: ii. What is the output for: $ cd hwk $ ls | grep ^p Output: iii. What is the output for: $ cd ../ $ pwd Output: 1
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F19, V1 2. (a) Consider the code: import turtle thomasH = turtle.Turtle() i. After the command: thomasH.color("#000000") , what color is thomasH ? black red white gray purple ii. After the command: thomasH.color("#AB0000") , what color is thomasH ? black red white gray purple iii. Fill in the code below to change thomasH to be the brightest blue: thomasH.color("# ") iv. Fill in the code below to change thomasH to be the color white: thomasH.color("# ") (b) Fill in the code to produce the output on the right: i. for i in range( ): print(i, end=" ") Output: 0 1 2 3 4 5 6 7 ii. for j in range( , , ): print(i, end=" ") Output: -5 -3 -1 1 iii. import numpy as np import matplotlib.pyplot as plt im = np.ones( (10,10,3) ) im[:, :5,:] = 0 plt.imshow(im) plt.show() Output: iv. import numpy as np import matplotlib.pyplot as plt im = np.ones( (10,10,3) ) im[0:: , 0:: , :] = 0 plt.imshow(im) plt.show() Output: 2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F19, V1 3. (a) What is the value (True/False): i. in1 = True in2 = False out = in1 or (not in2) True False ii. in1 = True in2 = False out = (in1 or not in2) and in2 True False iii. in1 = False in2 = True in3 = in1 or not in2 out = not in2 or in3 True False iv. in1 = True in2 = False in3 = False True False (b) Draw a circuit that implements the logical expression: not in2 or not (in1 or in2) (c) Fill in the circuit that implements the logical expression: (in1 and (in1 or in3)) or ((not in2) or (in2 and (not in3)) 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F19, V1 4. (a) Draw the output for the function calls: 1: import turtle 2: tara = turtle.Turtle() 3: tara.shape(’turtle’) 4: def ramble(tex, side): 5: if side <= 0: 6: tex.stamp() 7: elif side <= 10: 8: for i in range(3): 9: tex.left(120) 10: tex.forward(20) 11: else: 12: tex.right(90) 13: tex.forward(side) 14: ramble(tex, side//2) i. ramble(tara,5) ii. ramble(tara,160) (b) What are the formal parameters for ramble() : (c) If you call ramble(tara, 5) , which branches of the function are tested (check all that apply): The block of code at Line 6. The block of code at Lines 8-10. The block of code at Lines 12-14. None of these blocks of code (lines 6, 8-10, 12-14) are visited from this invocation (call). (d) If you call ramble(tara, 160) , which branches of the function are tested (check all that apply): The block of code at Line 6. The block of code at Lines 8-10. The block of code at Lines 12-14. None of these blocks of code (lines 6, 8-10, 12-14) are visited from this invocation (call). 4
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F19, V1 5. Design an algorithm that rotates an image by 180 degrees (upside down image). For simplicity, you may assume a square image (i.e. same height and length) Libraries: Input: Output: Process (as a list of steps): 5
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F19, V1 6. Given the FiveThirtyEight dataset containing data on nearly 3 million tweets sent from Twitter handles connected to the Internet Research Agency, a Russian “troll factory”, a snapshot given in the image below: Fill in the Python program below: #P6,V1: extracts trolls with highest number of followers #Import the libraries for data frames and plotting data: #Prompt user for input file name: csvFile = #Read input data into data frame: trolls = #Group tweets by author and organize by the number of followers trollFollowers = trolls.groupby([" "])[" "].max() #Print the top 3 authors/trolls with largest number of followers print(trollFollowers[ : ] ) #Generate a bar plot of the top 3 authors/trolls with largest number of followers trollFollowers. plt.show() 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F19, V1 7. Write a complete Python program that prompts the user for the name of an .png (image) file and prints the fraction of pixels that are primarily red. A pixel is primarly red if the red value is over 90% and the green and blue values are less than 10%. #Import the packages for images and arrays: #Ask user for image name and read into img: #Get height and width: #Initialize counter: #Loop through all the pixels & update count if primarily red: #Compute and print fraction: 7
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F19, V1 8. (a) What does the MIPS program below print: Output: (b) Modify the program to print out 26 consecutive letters in decreasing order (’Z’ down to ’A’). Shade in the box for each line that needs to be changed and rewrite the instruction below. ADDI $sp, $sp, -11 # Set up stack ADDI $s3, $zero, 1 # Store 1 in a registrar ADDI $t0, $zero, 74 # Start $t0 at 74 (J) ADDI $s2, $zero, 64 # Use to test when you reach 64 SETUP: SB $t0, 0($sp) # Next letter in $t0 ADDI $sp, $sp, 1 # Increment the stack SUB $t0, $t0, $s3 # Decrease the letter by 1 BEQ $t0, $s2, DONE # Jump to done if $t0 == $s2 J SETUP # If not, jump back to SETUP for loop DONE: ADDI $t0, $zero, 0 # Null (0) to terminate string SB $t0, 0($sp) # Add null to stack ADDI $sp, $sp, -11 # Set up stack to print ADDI $v0, $zero, 4 # 4 is for print string ADDI $a0, $sp, 0 # Set $a0 to stack pointer for printing syscall # Print to the log 8
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F19, V1 9. What is the output of the following C++ programs? (a) //Quote by Grace Hopper #include <iostream> using namespace std; int main() { cout << "One accurate measurement "; cout << "is \nworth a thousand "; cout << "expert "; cout << "opinions. "<<endl<<"G.H."; return 0; } Output: (b) #include <iostream> using namespace std; int main() { double num = 0; double tot = 0; while (tot < 10) { cout <<"Please enter amount\n"; cin >> num; tot += num; } cout << tot << endl; return 0; } Given the input: 5, 3, 4 Output: (c) #include <iostream> using namespace std; int main(){ int i, j; for (i = 1; i < 5; i++){ for (j = 0; j < i; j++){ if(j % 2 == 0) cout << "X"; else cout << "O"; } cout << endl; } return 0; } Output: 9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F19, V1 10. (a) Translate the following python program into a complete C++ program : #Python Loops, V1 for i in range(25,101,25): print(i+1, i+2) //include library and namespace //function signature { //loop line //loop body //return } 10
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final, F19, V1 (b) The number of Instagram monthly active users grew from 130 million in 2013 to 1000 million (1 billion) in 2019. The average annual growth rate can then be estimated as avgGrowth = %growth number-of-years = 100 · 1000 - 130 130 2019 - 2013 = 134% We can thus estimate the average annual growth: avgGrowth = 134% . Write a complete C++ program that asks the user for a year greater than 2013 (assume user complies) and prints the estimated number (in millions) of monthly active Instagram users in that year. //include library and namespace //function signature { //initialize variables //obtain input //calculate users //output users //return } 11
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Final Exam, Version 3 CSci 127: Introduction to Computer Science Hunter College, City University of New York 19 December 2018 Exam Rules Show all your work. Your grade will be based on the work shown. The exam is closed book and closed notes with the exception of an 8 1/2” x 11” piece of paper filled with notes, programs, etc. When taking the exam, you may have with you pens and pencils, and your note sheet. You may not use a computer, calculator, tablet, smart watch, or other electronic device. Do not open this exam 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 o ffi cial documents) as serious o enses 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: Email: Signature:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, F18, V3 1. (a) What will the following Python code print: i. s = "avram,henriette;dolciani,mary;rees,mina" a = s[6:11] print(a.upper()) Output: ii. names = s.split(’;’) print(names[-1]) Output: iii. b,c = names[0],names[1] print(b[:5]) Output: iv. for n in names: w = n.split(’,’) print(w[1],w[0]) Output: (b) Consider the following shell commands: $ ls nyc.csv p53.cpp p54.cpp p55.cpp trees.csv i. What is the output for: $ ls *.cpp Output: ii. What is the output for: $ ls *.cpp | wc -l Output: iii. What is the output for: $ mkdir ccProgs $ echo "Created folder: ccProgs" Output: 1
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, F18, V3 2. (a) For each row below containing a binary, decimal, and hexadecimal number, circle the largest value in the row (or “All Equal” if all three entries have the same value): Binary: Decimal: Hexadecimal: All Equal a) 11 10 9 All Equal b) 111 5 5 All Equal c) 101010 32 21 All Equal d) 1000000 64 40 All Equal e) 11111110 254 FF All Equal (b) Fill in the code below to make an image in which a pixel is white if it has an entry of 0 in the array elevations . Otherwise, the pixel should be colored blue. # Takes elevation data of NYC and displays coastlines import numpy as np import matplotlib.pyplot as plt elevations = np.loadtxt(’elevationsNYC.txt’) #Base image size on shape (dimensions) of the elevations: mapShape = elevations.shape + (3,) floodMap = np.zeros(mapShape) for row in range(mapShape[0]): for col in range(mapShape[1]): #Save the image: plt.imsave(’floodMap.png’, floodMap) 2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, F18, V3 3. (a) What is the value (True/False): i. in1 = False in2 = True out = in1 and in2 out = ii. in1 = True in2 = True out = not in1 or (in2 and not in1) out = iii. in1 = False in2 = True and not in1 in3 = in1 and in2 out = in1 or not in3 out = iv. in1 = True in2 = False out = (b) Design a circuit that implements the logical expression: (in1 or (in1 and not in2)) or (in3 and not in3) 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, F18, V3 4. (a) For the following code: def v3(anoop, madison): def startV3(shelly): if anoop > madison: jack = 5 return madison rachael = 20 else: alexandra = v1(jack+shelly,rachael) return -1 return alexandra i. What are the formal parameters for v3() : ii. What are the formal parameters for startV3() : iii. What does startV3(20) return: (b) Given the function definition: def sorted(ls): for i in range(4): print(ls) for j in range(3): if ls[j] > ls[j+1]: ls[j],ls[j+1] = ls[j+1],ls[j] i. What is the output for sorted([20,10,0,5]) ? ls[0] ls[1] ls[2] ls[3] ii. What is the output for sorted(["Nicky","Maria","Ferdi","Andrey"]) ? ls[0] ls[1] ls[2] ls[3] 4
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, F18, V3 5. Design an algorithm that prints out all the street trees in your zip code from the NYC Urban Forest OpenData. Specify the inputs and outputs for your algorithm and give the design in pseudocode. In your pseudocode, specify any libraries that you would need for your design. Input: Output: Process: 5
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, F18, V3 6. Fill in the Python program that will: prompt the user for the name of a CSV file, prompt the user for the name of a column in that CSV file, print out the maximum value of the column, and displays a bar plot of the column entered (with "Year" as the x-axis). #P6,V3: prints max of a column in a CSV file & makes a plot #Import the libraries for data frames and displaying images: #Prompt user for file name: #Prompt user for column name: df = pd.read_csv(fileName) #Compute maximum value of the column: print("Maximum is ", M) #Display a bar plot of "Year" vs. column entered by user: 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, F18, V3 7. Complete the following program, by writing the functions: getInput() : returns the number of turtles the user entered, setUp() : sets up a graphics window and turtle, and drawLines() : repeat 10 times: n steps, turn left 60 degrees. import turtle def getInput(): """ Prompts for a whole number. Returns the number entered. """ def setUp(): """ Creates a graphics window and turtle. Returns both. """ def drawLines(t,n): """ Takes a turtle and n as input. Repeats 10 times: n steps, turn left 60 degrees. """ def main(): n = getInput() #get number of lines to be drawn w,t = setUp() #sets up a graphics window and turtle drawLines(t,n) #repeat 10 times: n steps, turn left 60 degrees if __name__ == ’__main__’: main() 7
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, F18, V3 8. (a) What is the output for a run of this MIPS program: #Loop through every other letter: ADDI $sp, $sp, -6 # Set up stack ADDI $t0, $zero, 65 # Start $t0 at 65 (A) ADDI $s2, $zero, 75 # Use to test when you reach 75 (K) SETUP: SB $t0, 0($sp) # Next letter in $t0 ADDI $sp, $sp, 1 # Increment the stack ADDI $t0, $t0, 2 # Increment the letter BEQ $t0, $s2, DONE # Jump to done if $t0 == 75 J SETUP # If not, jump back to SETUP for loop DONE: ADDI $t0, $zero, 0 # Null (0) to terminate string SB $t0, 0($sp) # Add null to stack ADDI $sp, $sp, -6 # Set up stack to print ADDI $v0, $zero, 4 # 4 is for print string ADDI $a0, $sp, 0 # Set $a0 to stack pointer for printing syscall # print to the log Output: (b) Indicate what modifications are needed to the MIPS program (repeated below) so that it prints out the first 10 upper case letters: ABCDEFGHIJ ? #Loop through every other letter: ADDI $sp, $sp, -6 # Set up stack ADDI $t0, $zero, 65 # Start $t0 at 65 (A) ADDI $s2, $zero, 75 # Use to test when you reach 75 (K) SETUP: SB $t0, 0($sp) # Next letter in $t0 ADDI $sp, $sp, 1 # Increment the stack ADDI $t0, $t0, 2 # Increment the letter BEQ $t0, $s2, DONE # Jump to done if $t0 == 75 J SETUP # If not, jump back to SETUP for loop DONE: ADDI $t0, $zero, 0 # Null (0) to terminate string SB $t0, 0($sp) # Add null to stack ADDI $sp, $sp, -6 # Set up stack to print ADDI $v0, $zero, 4 # 4 is for print string ADDI $a0, $sp, 0 # Set $a0 to stack pointer for printing syscall # print to the log 8
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, F18, V3 9. What is the output of the following C++ programs? (a) //Lyrics by Lopez & Lopez #include <iostream> using namespace std; int main() { cout << "Let the storm rage "; cout << "on\nThe cold never "; cout << bothered me anyway"; cout << endl; return(0); } Output: (b) //More Elsa #include <iostream> using namespace std; int main() { int count = 2; while (count > 0) { cout <<"Let it go, "; count--; } cout << "\nThat perfect girl "; cout << "is gone\n"; return(0); } Output: (c) //Stars and srtipes #include <iostream> using namespace std; int main() { int i, j; for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) if (j % 2 == 0) cout << "*"; else cout << "-"; cout << endl; } return(0); } Output: 9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, F18, V3 10. (a) Translate the following program into a complete C++ program : #Python Loops, V3: for i in range(0,101,2): print(i) (b) Write a complete C++ program that asks the user for a whole number between -31 and 31 and prints out the number in “two’s complement” notation, using the following algorithm: i. Ask the user for a number, n. ii. If the number is negative, print a 1 and let x = 32 + n. iii. If the number is not negative, print a 0 and let x = n. iv. Let b = 16. v. While b > 0 . 5: If x > = b then print 1, otherwise print 0 Let x be the remainder of dividing x by b. Let b be b/2. 10
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, S22, V3 SCRATCH PAPER (page left intentionally blank) 13
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
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 o ffi cial documents) as serious o enses 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:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, S18, V1 1. (a) What will the following Python code print: i. a = "Jan&Feb&Mar&Apr&May&Jun" print(a.count("&")) Output: ii. b = a.split("&") print(b[0]) Output: iii. mo = b[-1].upper() print(mo) Output: iv. for c in mo: print(c.lower()) Output: (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* Output: ii. What is the output for: $ ls -l | grep "Apr" Output: iii. What is the output for: $ ls -l | grep "Apr" | wc -l Output: 1
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, S18, V1 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
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, S18, V1 3. (a) What is the value (True/False): i. in1 = True in2 = False out = in1 and in2 out = ii. in1 = False in2 = True out = not in1 and (in2 or not in1) out = iii. in1 = True in2 = False or not in1 in3 = in1 and in2 out = in1 or not in3 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
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, S18, V1 4. (a) Draw the output for the function calls: 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) i. ramble(tess,0) 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
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, S18, V1 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
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, S18, V1 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
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, S18, V1 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): ( x 1 - x 2) 2 + ( y 1 - y 2) 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
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, S18, V1 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 #use to compare for branching AGAIN: SUB $s0, $s0, $s1 BEQ $s0, $s2, DONE J AGAIN DONE: #To break out of the loop Values of $s0: (b) Write a MIPS program where the register, $s0 loops through the values: 4,8,12 8
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, S18, V1 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; } Output: (b) //Greetings! #include <iostream> using namespace std; int main() { cout << "Hi" << endl; int x = 2; while (x > 2) { cout <<"Again\n"; x--; } cout << "Bye" } Output: (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; } } Output: 9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, S18, V1 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 = 2 r - . 25 rf f = 0 . 95 f + . 1 rf 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
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
EmpID: CSci 127 Final Exam, S22, V3 SCRATCH PAPER (page left intentionally blank) 13
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Final Exam, Version 1 CSci 127: Introduction to Computer Science Hunter College, City University of New York 13 December 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 exam 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 o ffi cial documents) as serious o enses 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:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, V1, F17 1. (a) What will the following Python code print: s = "FridaysSaturdaysSundays" num = s.count("s") days = s[:-1].split("s") print("There are", num, "fun days in a week") mess = days[0] print("Two of them are", mess, days[-1]) result = "" for i in range(len(mess)): if i > 2: result = result + mess[i] print("My favorite", result, "is Saturday.") Output: (b) Consider the following shell command and resulting output: ls *.html closestCUNY.html nycMap.html t.html th.html cunySenior.html recyc.html tc.html trash.html i. What is the output for: ls *p.html Output: ii. What is the output for: ls *.html | grep r | grep e Output: 1
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, V1, F17 2. (a) After executing the Python code, write the name of the turtle: import turtle turtle.colormode(255) dennis = turtle.Turtle() dennis.color(0,255,0) matt = turtle.Turtle() matt.color(0,0,0) tim = turtle.Turtle() tim.color("#CCCCCC") harmon = turtle.Turtle() harmon.color("#990000") i. which is black: ii. which is pink: iii. which is the brightest green: iv. which is gray: (b) Write the Python code for the following algorithm: function makeLowerCase(inMsg) create an empty message for each letter in inMsg: code = the Unicode of the letter if code <= 90 code = code + 32 convert the code to the corresponding Unicode character concatenate the character to the beginning of the message return the message 2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, V1, F17 3. (a) What is the value (True/False) of out : i. in1 = False in2 = True out = in1 or in2 out = ii. in1 = False in2 = False out = not in1 and (in1 or in2) out = iii. in1 = True in2 = False in3 = (in1 and in2) out = in1 or not in3 out = iv. in1 = True in2 = True out = (b) Design a circuit that takes three inputs that: returns false if all three inputs are false, and returns true otherwise. 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, V1, F17 4. (a) Draw the output of the program: #Mystery program... import turtle th = turtle.Turtle() for i in range(5): th.forward(100) th.left(360/5) Output: (b) What is the output: #Mystery program def select(nums): m = nums[0] for n in nums: if n > m: m = n print(m) return(m) def truncate(userList): if len(userList) < 4: best = select(userList) else: best = select(userList[:4]) print("Best is", best) i. For truncate([10,20]) ? Output: ii. For truncate([1,3,5,4]) ? Output: iii. For truncate([1,2,3,4,100]) ? Output: 4
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, V1, F17 5. Write a complete Python program that asks the user for the name of a png file and prints the number of pixels that are bright red (the fraction of red is above 0.75 and the fraction of green, and the fraction of blue are below 0.25). 5
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, V1, F17 6. Using folium , write a complete Python program that asks the user for name of the output file, and creates a map with markers for the following locations: Hunter College (latitude: 40.768731 and longitude: -73.964915) Empire State Building (latitude: 40.748441 and longitude: -73.985664) Statue of Liberty (latitude: 40.689249 and longitude: -74.0445) Each marker should include a pop-up message with the name of the location. 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, V1, F17 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 borough population, and makeGraph() : makes a graph 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 plot of x versus y column in DataFrame df """ 7
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, V1, F17 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 AGAIN: SUB $s0, $s0, $s1 BEQ $s0, $zero, DONE J AGAIN DONE: #To break out of the loop Values of $s0: (b) Write a MIPS program where the register, $s0 loops through the values: 2,4,6,8,10 8
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, V1, F17 9. What is the output of the following C++ programs? (a) //William Bulter Yeats #include <iostream> using namespace std; int main() { cout << "Education is not " << endl; cout << "the filling of a pail,\n but "; cout << "the lighting of a fire.\n"; } Output: (b) //Mystery C++, #2 #include <iostream> using namespace std; int main() { float count = 8.0; while (count > 2) { cout << count << "\n"; count = count/2; } count << "Boom!\n"; } Output: (c) //Mystery C++, #3 #include <iostream> using namespace std; int main() { for (int i = 0; i < 5; i++) { for (int j = 5; j > i; j--) { if (j % 2 == 1) cout << "+"; else cout << "-"; } cout << endl; } } Output: 9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: EmpID: CSci 127 Final, V1, F17 10. (a) Write a complete Python program to print the fine for speeding. The program must read the speed from user input, then compute and print the fine. The fine is $15 for each mph over 60 and less than or equal to 70, and $20 for each additional mph over 70. For example, if the speed is 63 mph, then the fine would be $45 = $15 x 3. If the speed is 72 mph, then the fine would be $190 = $15 x 10 + $20 x 2. (b) Write a complete C++ program that repeatedly prompts the user for the year they were born until they enter a number that is 2017 or smaller. Your program should print out the final number the user entered: 10
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help