Problem Points Score Grader Total 75

Similar documents
Problem Points Score Grader Total 75

Problem Points Score Grader Total 75

Problem Points Score Grader Total 100

Final Examination CS 125 Introduction to Computer Science Fall Hours

Spring 2012 Final Examination 3 hours CS 125 Introduction to Computer Science

CS 101 Fall 2005 Midterm 2 Name: ID:

CS 122/132 Midterm Exam Winter 2003

McGill University School of Computer Science COMP-202A Introduction to Computing 1

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

CS 305j Midterm 2 Fall 2006

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CS 101 Spring 2007 Midterm 2 Name: ID:

Practice Midterm 1. Problem Points Score TOTAL 50

Final Exam. COMP Summer I June 26, points

Practice Midterm 1 Answer Key

Midterm Exam CS 251, Intermediate Programming October 8, 2014

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

CS 132 Midterm Exam Spring 2004

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

CS 101 Fall 2006 Midterm 1 Name: ID:

CSI 1100 / 1500 Fall 2004 Introduction to Computer Science I Final Examination

CS 307 Midterm 1 Fall 2007

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

CS164: Midterm I. Fall 2003

CIS 110 Introduction to Computer Programming Summer 2014 Midterm. Name:

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

Second Examination Solution

CS 101 Spring 2006 Final Exam Name: ID:

Program development plan

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013

Question: Total Points: Score:

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Programming with Java

EXAMINATION INSTRUCTIONS

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination

CIS 110 Introduction to Computer Programming Summer 2016 Midterm. Recitation # (e.g., 201):

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

CS 134 Midterm Fall 2006

CIS 110 Introduction to Computer Programming Summer 2018 Midterm. Recitation ROOM :

Question: Total Points: Score:

Spring Semester 10 Exam #1 Dr. Dillon. (02/18)

The data in the table are arranged into 12 rows and 12 columns. The process of printing them out can be expressed in a pseudocode algorithm as

CS 134 Midterm Fall 2006

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

AP Computer Science A Summer Assignment 2017

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

Spring Semester 08, Dr. Punch. Exam #1 (2/12), form 1 A

CS 101 Fall 2006 Midterm 3 Name: ID:

CS 455 Midterm Exam 2 Fall 2015 [Bono] Nov. 10, 2015

Mr. Monroe s Guide to Mastering Java Syntax

COMP 401 Midterm. Tuesday, Oct 18, pm-3:15pm. Instructions

CS 312 Exam 2 Fall KG Kris Megan Roman Sonika

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

Oct Decision Structures cont d

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CIS 110 Introduction to Computer Programming. 13 February 2013 Make-Up Midterm Midterm

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

EXAMINATION INSTRUCTIONS

CIS 110 Fall 2014 Introduction to Computer Programming 8 Oct 2014 Midterm Exam Name:

CS111: PROGRAMMING LANGUAGE II

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

CS 170 Exam 1. Version: B Fall Name (as on OPUS):

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

PROGRAMMING FUNDAMENTALS

CS 305j Midterm 1 Fall 2007

Course Outline. Introduction to java

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

Following is the general form of a typical decision making structure found in most of the programming languages:

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

I. True/False: (2 points each)

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Faculty of Science Midterm. COMP-202B - Introduction to Computing I (Winter 2008)

CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 3* * 3 17 % 9-20 % (26 / 7) "2"

I. True/False: (2 points each)

CS 170 Exam 1. Version: C Fall Name (as on OPUS):

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Midterm Exam CS 251, Intermediate Programming March 12, 2014

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Midterm Exam 2 CS 455, Fall 2013

Question: Total Points: Score:

Introduction to Computer Science Midterm 3 Fall, Points

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

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

Prelim One Solution. CS211 Fall Name. NetID

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CS1004: Intro to CS in Java, Spring 2005

Problem Grade Total

COS 126 Midterm 1 Written Exam, Fall 2009

Transcription:

University of Illinois at Urbana-Champaign Department of Computer Science First Examination Fall 2010 CS 125 Introduction to Computer Science 90 minutes permitted First name: Last name: NetID: @ illinois.edu (Please write legibly) Discussion Section: AY (We will return your exam manuscript to you in this section) AYA Tues 9:00am-10:50 AYB Tues 11:00am-12:50 AYC Tues 1:00pm- 2:50 AYD Tues 3:00pm- 4:50 AYE Wed 9:00am-10:50 AYF Wed 11:00am-12:50 AYG Wed 3:00pm- 4:50 AYH Wed 5:00pm- 6:30 This is a closed book and closed notes exam. No electronic aids are allowed. You must turn this exam booklet in before leaving. You should have 9 sheets total including one scratch sheet. The last sheet is scratch paper; you may detach it while taking the exam, but must turn it in with the exam when you leave. You should not write any additional methods for any problem in this exam; you only complete the main() method for that problem. Also, you are not allowed to use the break, continue,or switch statements on this exam. Unless we say otherwise in the specific problem, you can assume all values entered by the user will be acceptable input for that program. If you believe a question is ambiguous or contains an error, write down your assumptions and answer accordingly. When you write code, you may use a shorthand for System.out and TextIO input and output methods provided it is obvious to the graders which method you are using. For example it is acceptable to use Sopln in place of System.out.println and to use Sopt in place of System.out.print. For full marks correct syntax is required: Ensure all statements include a semicolon and the correct use of upper/lower case, single quotes and double quotes. However a syntactically correct but flawed program will earn a low score i.e. semantics and correctness are more important than minor typos and syntax errors. Problem Points Score Grader 1 12 2 10 3 14 4 15 5 12 6 12 Total 75

1. Type Analysis 12 points (3 points each) For each of the code snippets below, there are zero, one or more type errors that the compiler would catch. If there are one or more types error circle "YES" and explain what the type error(s) are. Indicate what types and operators are involved in the erroneous part of the expression. Circle "No" if there is no type error. Examples: Example int a=4+"hi"; true==3 int c=6*3; Response Yes: A string value is being assigned to an integer variable. Yes: An integer value is being compared with a boolean. No. (a) double[] data = new double[10]; int result = (data[9] + 4) / 2.0; Circle the correct response (YES or NO). If "YES" then specify the types and the operation involved that cause the type error. Type Error(s)? If yes, explain: YES / NO (b) double t = 1 + TextIO.getlnInt(); boolean result = (t!= true) (t > 5); Type Error(s)? If yes, explain: YES / NO (c) String text = TextIO.getln(); int pos = text.length()/2; int offset = (text.charat(pos) - 'A'); Type Error(s)? If yes, explain: YES / NO (d) String text = TextIO.getln(); int mid = text.length()/2; boolean x = mid > text.indexof("::"); Type Error(s)? If yes, explain: YES / NO CS125 Midterm Exam I Fall 2010 Page 2 of 9

2. Execution Analysis 10 points (a) Read the code below then answer the four questions on the right. int a = 1, b = 2, c = 3, d=0; boolean e = true; boolean f = false; while(a<c &&!f) { c = TextIO.getlnInt(); d ++; e = (2*a == c + b); b = c; if(d>10 e) f = true; } TextIO.putln(d); What is the smallest value that can be printed? Choose one variable ('a' to 'f') that best illustrates the following concepts. One-way flag Follower/Previous value Stepper/Iteration counter (b) Add Java code below to print the value of the first element of A multiplied by the last element of A. public static void main(string[] args) { int A[] = new int[] {10,20,30,... more values not shown}; } (c) Carefully analyze the following code. What will it print when executed? For partial credit show your working. for (int a = 0; a < 5; a++) for (int b = a; b > 0; b--) TextIO.put(a); Output : (d) Write one value for x that will cause y to be incremented in the code below. int x = not shown ; Your answer: x= int y =0; if( (x%2!= 0) && (x<0) && (y++ < 10)) TextIO.putln(); // y should now be one. CS125 Midterm Exam I Fall 2010 Page 3 of 9

3. Conditional Cheesy Poofs 14 Points Foods4U Corp recommends food based on the user's cravings. Complete the program below to print one of B, C, P, or S, corresponding to Bacon, Candy, Poofs & Spaghetti respectively, using the following rules: If none of the other rules are satisfied, then cheesy-poofs are recommended. Cravings for Protein or Salt get Bacon Strips if they have more than $5 to spend. Cravings for Carbs get either Candy if they have $1, $2 or $3, or Spaghetti if they have more than $3 to spend. Read the following carefully: Complete the given code below. Use only if-else statements and four output statements one to print each output. That is, do not print out B in two different places in the code, or assign it to a variable your boolean expressions should be such that you do not have multiple statements in your code which print out the same letter. Do not create any additional variables or methods. public class Foods4UWizard { public static void main (String[] args){ TextIO.putln("Do you crave Carbs, Salt or Protein?"); TextIO.putln("Type C, S, or P and press return"); char crave = TextIO.getlnChar(); // assume either C, S, or P TextIO.putln("Dollars you can spend on this food?"); int dollars = TextIO.getlnInt(); // assume a valid integer // Please continue over-leaf or on spare page if you need more space. } // end of main method } // end of class CS125 Midterm Exam I Fall 2010 Page 4 of 9

4. Text Processing (There is no spoon) 15 Points Complete the following program to process only the first 64 lines from a text file, which is far longer. Use TextIO.getln() to read the next line from the text file. Your program will determine if there are any empty lines (i.e. zero length) before a line starting with "SPOO", in upper-, lower- or mixed case. There may be other characters on the same line after spoo. Your program will also determine the length of the longest line read. After processing is complete, print the result in the following exact format shown below. Do not print anything else. MAX=81 FOUNDEMPTYBEFORE=yesno Where 81 is replaced by the length of the longest line and yesno is either the word YES or NO. Print "YES" if at least one empty line was found before the "spoo..." line (upper/lower/mixed case eg. SpOo), "NO" in all other cases (e.g. there is no "spoo" line). The following string methods may be useful:.equals(string),.length(),.charat(int),.tochararray(),.indexof(string),.touppercase(). public class SpoonReader { public static void main(string[] args) { TextIO.readFile("spoon.txt"); } // end of main method } // end of class CS125 Midterm Exam I Fall 2010 Page 5 of 9

5. Party Manager (and I know I'm on the invite list) 12 Points public class PartyInvite { public static void main(string[] args) { TextIO.putln("Number of people?"); int len = TextIO.getlnInt(); A: String[] names = boolean[] invited = int total =0; B: for(int i=0; ) { C: TextIO.putln("Name & Invitation for person "+(i+1)+"?"); names[i]= TextIO.getln(); invited[i]= TextIO.getln().equals("Y"); D: } // for loop ends here E: TextIO.putln("Total invites:" + total); TextIO.putln("Do not allow in:"); } // main } // class (a) Write code in response area A to respectively set names and invited variables to new String and boolean arrays of length len. (b) Complete the for-loop at response area B to read in all len people. Note C and D are inside the for-loop. (c) Add additional code at C so that if the most recently entered name equals your nickname then you are always invited (i.e. your boolean entry is true even if user entered "N"). (d). Write code in response area D such that the variable total will be equal to the total number of invited guests (including yourself). (e) Write code in response area E to print out the names of unwanted (uninvited) people. Print one name per line. Do not print anything else. CS125 Midterm Exam I Fall 2010 Page 6 of 9

6. Cipher (Last Question) 12 points You want to decode a message from your secret admirer using a modified Caesar cipher. Your admirer usually mapped every letter of the alphabet to another letter of the alphabet a fixed distance away (i.e., for shift 3 they changed A to D, B to E, Z to C, etc.) but this time they are more cunning. The message contains only capital letters A,B,C Z or spaces (there are no other character types). Space always decodes to a space. Complete the program below: Take a line of encoded text as input from the user (assume it only includes characters A...Z and spaces) and then print the decoded message. The shift is initially 3, thus 'D' should decode to 'A' and 'A' to 'X' etc. But each time you come across a space character, increase the shift distance by one. Assume there are less than 22 spaces in the message. Example: if the user enters "FFF FF F" Your program will print "CCC BB A". public class MySecretAdmirer { public static void main(string[] args) { TextIO.putln("Please enter the secret (all caps & spaces)"); String secret = TextIO.getln(); // Write your code here to decode and print the message // String methods.charat(int) and.length() may be useful. } // end of main method } // end of class LAST QUESTION. GO BACK AND CHECK YOUR WORK. CS125 Midterm Exam I Fall 2010 Page 7 of 9

Empty Page CS125 Midterm Exam I Fall 2010 Page 8 of 9

Scratch paper - you may detach it while taking the exam, but must turn it in with the exam when you leave. CS125 Midterm Exam I Fall 2010 Page 9 of 9