CS 455 Midterm Exam 1 Spring 2011 [Bono] Feb. 17, 2011

Similar documents
CS 455 Midterm Exam 1 Spring 2011 [Bono] Feb. 17, 2011

CS 455 Midterm Exam 1 Spring 2013 [Bono] Feb. 21, 2013

CS 455 Midterm Exam 1 Fall 2013 [Bono] Wednesday, Oct. 2, 2013

Midterm Exam 2 CS 455, Spring 2011

CS 455 Midterm 2 Fall 2017 [Bono] Nov. 7, 2017

CS 455 Midterm Exam 1 Spring 2015 [Bono] Thursday, Feb. 19, 2015

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

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

CS 455 Final Exam Fall 2016 [Bono] December 13, 2016

CS 455 Final Exam Spring 2017 [Bono] May 10, 2017

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

CS 455 Final Exam Fall 2015 [Bono] Dec. 15, 2015

CS 455 Midterm Exam 1 Fall 2015 [Bono] Thursday, Oct. 1, 2015

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

CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017

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

CS 455 Final Exam Spring 2018 [Bono] May 8, 2018

CS 455 Final Exam Fall 2013 [Bono] December 12, 2013

Midterm Exam 2 CS 455, Spring 2013

CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016

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

Midterm Exam 2 CS 455, Spring 2015

Midterm Exam 2 CS 455, Fall 2013

CS 455 Final Exam Spring 2015 [Bono] May 13, 2015

Midterm Exam 2 CS 455, Spring 2014

Midterm Exam 2 CS 455, Fall 2014

Midterm Exam 2 CS 455, Fall 2012

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

CS 111X - Fall Test 1

Object-Oriented Programming in Java

CS 455 Midterm Exam 2 Spring 2017 [Bono] Tuesday, April 4, 2017

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

OBJECTS AND CLASSES CHAPTER. Final Draft 10/30/2011. Slides by Donald W. Smith TechNeTrain.com

Fundamentos de programação

Final Exam. COMP Summer I June 26, points

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

Problem Grade Total

CS 113 MIDTERM EXAM 2 SPRING 2013

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

Software and Programming 1

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

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

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

2/9/2012. Chapter Four: Fundamental Data Types. Chapter Goals

Chapter 4 Fundamental Data Types. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

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

CS2102, B11 Exam 2. Name:

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

Practice Midterm 1. Problem Points Score TOTAL 50

Big Java. Fifth Edition. Chapter 3 Fundamental Data Types. Cay Horstmann

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

int: integers, no fractional part double: floating-point numbers (double precision) 1, -4, 0 0.5, , 4.3E24, 1E-14

Software and Programming 1

CS 314 Exam 2 Spring 2018

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

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

CSCI 102 Fall 2010 Exam #1

I. True/False: (2 points each)

University of Massachusetts Amherst, Electrical and Computer Engineering

A Previous CS 310 Final Exam

Midterm Exam CS 251, Intermediate Programming March 6, 2015

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

CSE 131 Introduction to Computer Science Fall Exam I

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

Points off Total off Net Score. CS 314 Final Exam Spring 2016

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

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

New York University Intro to Computer Science (CSCI-UA.101) Fall 2014 Midterm #1 Test G. Instructions:

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

Structure and Interpretation of Computer Programs

Question: Total Points: Score:

CS171 Midterm Exam. October 29, Name:

Structure and Interpretation of Computer Programs

CSE 11 Midterm Fall 2008

CSC 207H Fall L Java Quiz Duration 25 minutes Aids allowed: none

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

Midterm Exam. Sample Solutions

CIT Special final examination

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

Practice Midterm 1 Answer Key

CSE413 Midterm. Question Max Points Total 100

1 out of 3 points. 2 out of 3 points. 3 out of 8 points. 4 out of 6 points. 5 out of 5 points. 6 out of 6 points. Total. Birthday: Month: Day:

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

Exam Percentage: / 55 = %

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

CSE 1223: Exam II Autumn 2016

CSC 222: Object-Oriented Programming. Fall 2017

PRACTICE MIDTERM EXAM #2

EXAMINATION INSTRUCTIONS

Final Exam. Name: Student ID: Section: Signature:

ECE 2035 A Programming HW/SW Systems Spring problems, 5 pages Exam Three 13 April Your Name (please print clearly)

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

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

Structure and Interpretation of Computer Programs

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 1

CS 307 Midterm 2 Spring 2008

University of Maryland College Park Dept of Computer Science

EE 312 Fall 2017 Midterm 1 October 12, 2017

CS 161 Computer Security

Transcription:

Name: USC loginid (e.g., ttrojan): CS 455 Midterm Exam 1 Spring 2011 [Bono] Feb. 17, 2011 There are 4 problems on the exam, with 50 points total available. There are 7 pages to the exam, including this one; make sure you have all of them. There is also a double-sided one-page code handout that accompanies the exam. If you need additional space to write any answers, you may use the backs of exam pages (just direct us to look there). If you have scratch work in addition to your answer, circle your final answer, so we know what to grade. Put your name and USC ID number at the top of the exam. Please read over the whole test before beginning. Good luck! Remote DEN students only: Do not write on the backs of pages. If additional space is needed, ask proctor for additional blank page(s), put your name on them, and attach them to the exam. value score Problem 1 Problem 2 Problem 3 Problem 4 TOTAL 10 pts. 10 pts. 10 pts. 20 pts. 50 pts.

Problem 1 [10 pts.] Consider the following code fragment: (Note: more about Point class on code handout.) Point p1 = new Point(10, 20); Point p2 new Point(p1); Point p3 = p1; p1.translate(5, 10); p2.translate(5, 10); p3.translate(5, 10); System.out.println(p1 + + p2 + + p3); Part A [5]. In the space below, draw a box-and-pointer diagram (a.k.a., memory diagram) showing all object variables, objects, and their state as they have changed during the code sequence. Part B [3]. What is printed by the code? For the purpose of this problem assume a Point is printed as follows: [x, y] Part C [2]. How many Point objects are created by the code above? 2

Problem 2 [10 pts.] Change the CashRegister class from the textbook so a manager can track some information about the day s sales (the class itself and space for your answer is given on the next two pages). Here is a sample interaction to show the new functionality (calls to new methods shown in bold): CashRegister reg = new CashRegister(); reg.recordpurchase(3.95); reg.recordpurchase(22.99); System.out.println(... reg.gettotal()); reg.enterpayment(30); System.out.println(... reg.givechange()); // first customer finishes transaction reg.recordpurchase(7.24); reg.recordpurchase(7.24); reg.recordpurchase(42.50); System.out.println(... reg.gettotal()); reg.enterpayment(60); System.out.println(... reg.givechange()); // second customer finishes transaction... [many other sales take place throughout the day]... reg.recordpurchase(4.99); System.out.println(... reg.gettotal()); reg.enterpayment(10); System.out.println(... reg.givechange()); // last customer of the day finishes transaction // call new methods for end of the day processing System.out.println(... reg.gettotalsales()); System.out.println(... reg.avgsalespercustomer()); reg.reset(); // reset all totals for the next day 3

Problem 2 (cont.) Here and continued on the next page is the complete CashRegister class definition without the new functionality. Add your new code inline with the existing code or to the right of the code with arrows clearly indicating where your new code would be inserted. For your convenience we already added the empty method bodies in bold. A cash register totals up sales and computes change due. public class CashRegister { private double purchase; private double payment; Constructs a cash register with no money in it. public CashRegister() { purchase = 0; payment = 0; Records the sale of an item. @param amount the price of the item public void recordpurchase(double amount) { double total = purchase + amount; purchase = total; Gets total of all purchases made by this customer. public double gettotal() { return purchase; ; Enters the payment received from the customer. @param amount the amount of the payment public void enterpayment(double amount) { payment = amount; [CashRegister class definition continued next page] 4

Problem 2 (cont.) Computes the change due and resets the machine for the next customer. @return the change due to the customer public double givechange() { double change = payment - purchase; purchase = 0; payment = 0; return change; Returns total sales since the last reset(); if before first reset(), sales since it was created. @return total sales public double gettotalsales() { Computes the average sales per customer (how much each customer spent on average) since last reset(); if before first reset(), avg since it was created. @return average sales per customer public double avgsalespercustomer() { Resets the machine to initial state. (Zeroes out all sales, etc.) public void reset() { // end of class CashRegister 5

Problem 3 [10 pts. total] Implement the formatsentence method below that reads words from the given scanner until end of file printing them out formatted as a sentence. A sentence has one space between each word and a period right after the last word. Example input: The big went home dog Corresponding output: The big dog went home. // prints a version of text read from parameter in formatted as a // sentence. // if there are no words to read from in, prints nothing. public void formatsentence(scanner in) { 6

Problem 4 [20 pts. total] Implement the haspeak method, which tells us whether its array of int data values, when plotted, has a single peak. This means that the sequence of values consists wholly of an increasing part followed by a decreasing part. You may assume no two consecutive values in the array are the same (i.e., no flat areas). Here are several examples: vals: haspeak(vals): 3 7 false 7 3 false 3 5 9 2 true 3 5 9 3 2 true <empty> false vals: haspeak(vals): 3 5 2 true 3 2 1 false 3 5 2 3 false 2 false public boolean haspeak(int[] vals) { 7