Problem Points Score Grader Total 75

Similar documents
Problem Points Score Grader Total 75

Problem Points Score Grader Total 100

Problem Points Score Grader Total 75

Final Examination CS 125 Introduction to Computer Science Fall Hours

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

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

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

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

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

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

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

Final Exam. COMP Summer I June 26, points

Practice Midterm 1. Problem Points Score TOTAL 50

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

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

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

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

CS1004: Intro to CS in Java, Spring 2005

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

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

Question: Total Points: Score:

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

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011

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

Midterm Exam CS 251, Intermediate Programming October 8, 2014

PROGRAMMING FUNDAMENTALS

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

Midterm Exam CS 251, Intermediate Programming March 12, 2014

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

CS 101 Exam 2 Spring Id Name

CIS 110 Introduction To Computer Programming. November 21st, 2011 Exam 2

CSCI 1226 Sample Midterm Exam

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007

CSE 142 Sample Midterm Exam #3

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

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

Midterm Examination (MTA)

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

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

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

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java

COS 126 General Computer Science Spring Written Exam 1

Course Outline. Introduction to java

CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016

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

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

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

Midterm Exam CS 251, Intermediate Programming March 6, 2015

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

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

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

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

Oct Decision Structures cont d

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

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

COSC 1010 Introduction to Computer Programming

CS 455 Midterm 2 Spring 2018 [Bono] Apr. 3, 2018

Practice Midterm 1 Answer Key

Getting started with Java

Topics. Chapter 5. Equality Operators

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

CS 307 Midterm 1 Fall 2007

Question: Total Points: Score:

Programming with Java

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

CSE 114 Midterm 1. Please leave one seat between yourself and each of your neighbors.

CS 132 Midterm Exam Spring 2004

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

Java Bytecode (binary file)

CS 305j Midterm 2 Fall 2006

Computer Programming, I. Laboratory Manual. Final Exam Solution

Mr. Monroe s Guide to Mastering Java Syntax

I. True/False: (2 points each)

COS 126 General Computer Science Fall Written Exam 1

Java Loop Control. Programming languages provide various control structures that allow for more complicated execution paths.

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

CSE 20. SAMPLE FINAL Version A Time: 180 minutes. The following precedence table is provided for your use:

COS 126 Midterm 1 Written Exam, Fall 2009

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

Full file at

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

I. True/False: (2 points each)

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Question: Total Points: Score:

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

SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1

CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010

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

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2013

COMP1006/ Summer Tutorial 1

1. An operation in which an overall value is computed incrementally, often using a loop.

Software Practice 1 Basic Grammar

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

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

I. True/False: (2 points each)

Transcription:

University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 125 Introduction to Computer Science 75 minutes permitted First, Last name: NetID: @ illinois.edu (please write legibly) Discussion Section (Day/Time or AY_): 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. 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 Likewise, you can use T.rlnI(), T.rlnC(), and T.rlnD() in place of TextIO.readlnInt(), TextIO.readlnChar(), and TextIO.readlnDouble(). 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 is more important than minor typos and syntax errors. Problem Points Score Grader 1 12 2 14 3 10 4 15 5 12 6 12 Total 75 CS125 Midterm Exam Spring 2009

1. Type Analysis 12 points (3 points each) For each of the code snippets below, there is zero, one or more type errors that the compiler would catch. Explain what the type error is, by indicating what types and operators are involved in the erroneous part of the expression. For example, if the code were int x = 4 + "hi";, then the error is "a variable of type int is being assigned the value of an expression of type String". In other words, you need to be specific about what types are involved; you canʼt just say this assignment is illegal in response to the above code. If there is no type error write "No T.E." (a) int t = TextIO.getlnInt(); char w = TextIO.getlnChar(); boolean invalid = ((t < 1) (t >= 28.0) && w); (b) double offset = (16 + 1) / 2.0; int average = (offset + 14.0 + 7) / 3; (c) String text = TextIO.getln(); text = text.touppercase(); int dist = text.length() - text.indexof("m"); TextIO.putln("The result is " + dist); (d) char[] quote = new char[]{'c','s','1','2','5'; TextIO.putln(quote[0] - 'A'); CS125 Midterm Exam Spring 2009 Page 2 of 9

2. Conditionals 14 Points Late Nite Food Inc, recommends food based on the user's preferences. Complete the program below to print out either "Pasta" "Meat" "Chocolate" or "Samples", using the following rules: Carnivores eat Meat provided they have $8 or greater to spend. Nibblers eat Chocolate provided they have more than $3 to spend. Nibblers eat Samples if they have zero dollars to spend. All others eat Pasta. You should add if-else statements and four output statements to the code below one to print each output. That is, do not print out P in three different places in the code your boolean expressions should be such that you do not have multiple statements in your code which print out the same food item. You may shorten your output to a single letter: P M C S (Pasta, Meat, Chocolate, Samples respectively). public class LateNiteFood { public static void main (String[] args){ TextIO.putln("Are you a Carnivore, Nibbler or Vegetarian?"); TextIO.putln("Type C N or V and press return"); char type = TextIO.getlnChar(); // assume either C N V TextIO.putln("How many dollars do you have to spend?"); int dollars = TextIO.getlnInt(); // assume a valid integer // end of main method // end of class CS125 Midterm Exam Spring 2009 Page 3 of 9

3. Loop Analysis 10 Points For this question, consider the following program. public class Mystery { public static void main(string[] args) { int t = 14; int x = 0; int iteration = 0; TextIO.putln(iteration + " " + t + " " + x); // Line A TextIO.putln("Space="+(int)' '); while(t>0) { x = x + (t % 2); t = t/2; iteration ++; TextIO.putln(iteration + " " + t + " " + x); 1. Write the Mystery program's output in the space below. The first two lines are completed for you. 0 14 0 Space=32 2. What is the new program's first output line when Line A is replaced with the following? TextIO.putln(iteration + ' ' + t + ' ' + x); // New Line A New output: 3. What is the new program's first output line when Line A is replaced with the following? TextIO.put(iteration + " " + t + " " + x + "\n"); // New Line A New output: 4. True or False? The last value of x equals the number of ones in the base 2 representation of 14? Your Answer: CS125 Midterm Exam Spring 2009 Page 4 of 9

4. Text Processing 15 Points Complete the following program to process the first 99 lines 1 of the Shawshank Redemption movie script. Your program will count the number of these lines that contain the word "ANDY" in any mix of uppercase or lowercase. After processing is complete, print the result in the following exact format: FOUND=10 ABSENT=89 Where 10 is replaced by the number of lines containing ANDY in any case and 89 is replaced by the number of lines that do not. You can assume the file is longer than 99 lines. public class Shawshank { public static void main(string[] args) { TextIO.readFile("ShawshankRedemptionScript.txt"); // end of main method // end of class 1 A regular line in a file; i.e. TextIO.getln() will return one line of script. CS125 Midterm Exam Spring 2009 Page 5 of 9

5. Arrays 12 Points public class VotingMachine { public static void main(string[] args) { TextIO.putln("Number of voters?"); int len = TextIO.getlnInt(); int[] votes; // Space 1: for(int i=0; ; ) { // Line A TextIO.putln("Voter "+i+": Candidate 1,2,or 3?"); votes[i]= TextIO.getlnInt(); // Assume 1 2 or 3 TextIO.putln("You choice:" + votes[i]); // Space 2: // Print Candidate 3's result first: for(int key=3; key>0; key--) { int count = 0; for(int i=0; i<len;i++) if(array[i] == key) { count++; TextIO.putln(key +":" + count); // for // main // class // Line B // Line C 1. Write code in space 1 to initialize the votes array to hold len integers. 2. Briefly describe the purpose of the code between Line B and the end of the program. 3. Complete Line A to read in all len voter choices. 4. Describe carefully the effect of swapping the order of Line B and Line C. Which candidate (1,2, or 3) could gain the most reported votes from this alteration? 5. Add code in "Space 2" area to modify just 1% of the voting array. If the 100th, 200th, 300th etc. voter chooses candidate two, change their vote to be candidate one. In all other scenarios, do not change the voter's choice. CS125 Midterm Exam Spring 2009 Page 6 of 9

6 (Last Question). Cipher 12 Points Complete the following encryption program. The program requests two strings from the user: A lookup pad, exactly 26 characters long, and the message to be encrypted. The program then prints the encrypted version of the message. The encrypted message is created as follows: The letter A is replaced by the first lookup character, letter B is replaced by the second lookup character and so on. The message contains only uppercase letters A to Z, and contains no spaces, punctuation, digits or other characters. Two examples: if the lookup pad is "ABCDEFGHIJKLMNOPQRSTUVWXYZ" then the encrypted message is identical to the original. If the pad is "ZYXWVUT " then message "ACEE" is encrypted as "ZXVV" public class Encrypt { public static void main(string[] args) { TextIO.putln("Lookup pad (Exactly 26 characters)?"); String lookup = TextIO.getln(); TextIO.putln("Message to encrypt (Only A-Z characters)?"); String mesg = TextIO.getln(); CS125 Midterm Exam Spring 2009 Page 7 of 9

Empty Page CS125 Midterm Exam Spring 2009 Page 8 of 9

Scratch paper CS125 Midterm Exam Spring 2009 Page 9 of 9