CS 1316 Exam 2 Fall 2009

Similar documents
CS 1316 Exam 3 Fall 2009

CS 1316 Exam 1 Summer 2009

CS 1316 Exam 2 Summer 2009

CS Exam 2 - Spring 2010

Exam Percentage: / 55 = %

CS 1301 Exam 1 Answers Fall 2009

CS 1301 Exam 1 Fall 2009

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2010

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

Your (printed!) Name: CS 1803 Exam 3. Grading TA / Section: Monday, Nov. 22th, 2010

CS 1301 Exam 2 Fall 2013

Instructor: Yu Wang 11/16/2012

Question: Total Points: Score:

CS 1301 Exam 1 Spring 2011

CS 1301 Exam 1 Fall 2011

CS 1301 Exam 3 Fall 2014

CS Exam 3 - Spring 2010

CS Exam 3 - Spring 2010

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

CS 1301 Exam 1 Fall 2014

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

CS 2316 Exam 1 Spring 2014

CS Exam 2 Name: Your Grading TA: This exam has 7 pages including the title page. Please check to make sure all pages are included.

CS 1301 Exam 1 Fall 2014

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

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

CS 1301 Exam 2 A Fall 2015

CS 170 Exam 2. Version: A Fall Name (as in OPUS) (print): Instructions:

Question: Total Points: Score:

Comp Intermediate Programming EXAM #1 February 16, 2004 Rice University - Instructors: Cox & Nguyen

CS 2316 Exam 3 Fall 2011

CS 2316 Exam 1 Spring 2013

CS 2316 Exam 4 Fall 2011

CS 1301 Exam 1 Spring 2015

CS 1803 Fall 2010 Exam 1

Question: Total Points: Score:

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Introduction to Programming Using Java (98-388)

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Question: Total Points: Score:

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

CS 2316 Exam 4 Fall 2012

CSC Java Programming, Fall Java Data Types and Control Constructs

CS 1301 Exam 2 A Fall 2015

CS Name : Grading TA:

This exam has 10 pages including the title page. Please check to make sure all pages are included.

CS 1301 Exam 1 Fall 2013

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

CS 1331 Fall 2016 Exam 2

CS 1301 Exam 3 Spring 2012

Place your name tag here

Question: Total Points: Score:

CS 190 Exam 2 Fall 2014

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

Question: Total Points: Score:

CS 1301 Exam 2 Fall 2014

CS 251 Intermediate Programming Methods and Classes

Practice Midterm 1 Answer Key

Java Primer 1: Types, Classes and Operators

Question Possible Points Earned Points Graded By GUI 22 SQL 24 XML 20 Multiple Choice 14 Total Points 80

Question: Total Points: Score:

CS 1803 Fall 2010 Exam 1

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

CS 231 Data Structures and Algorithms, Fall 2016

CS170 (005): Introduction to Computer Science Exam 2

Final Exam. COMP Summer I June 26, points

Section 004 Spring CS 170 Exam 1. Name (print): Instructions:

CS 2316 Exam 4 Fall 2012

CSCI 355 Lab #2 Spring 2007

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

CS 2316 Exam 4 Fall 2011

CS 1301 Exam 1 Spring 2014

Question: Total Points: Score:

CS 1301 Exam 1 Spring 2014

1 Inheritance (8 minutes, 9 points)

CSCI 355 LAB #2 Spring 2004

The Java language has a wide variety of modifiers, including the following:

CS 1301 Exam 3 A Spring 2015

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

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

CS 1301 Exam 3 Spring 2014

Brief Summary of Java

CS 2316 Exam 4 Spring 2012

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

CS 251 Intermediate Programming Methods and More

STUDENT LESSON A12 Iterations

1 Shyam sir JAVA Notes

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Lecture 14. 'for' loops and Arrays

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

CS 1301 Exam 2 Spring 2014

Objects and Iterators

CS 1301 Exam 1 Fall 2013

Java Bytecode (binary file)

COP 3330 Final Exam Review

Transcription:

1 / 7 Your Name: I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Georgia Tech community. CS 1316 Exam 2 Fall 2009 Section/Problem Points Earned Points Possible 1. Terms & Concepts 21 2. Short Answer 6 3. Program Comprehension 5 4. Sound Manipulation 15 5. List Question 14 6. Fix Replace 20 Total Points: 81

2 / 7 Your Name: 1. Terms & Concepts (21 points) For each of the terms below, write 1 or 2 sentences defining the term and proving you understand what your definition means. You may include an example if you think it will help your explanation. Be concise: 1. array homogeneous data stored together in memory. Easily indexed using the bracket operator (e.g. myarray[3] ). 2. block Section of code (statements) between brackets such as used by a for or while loop or conditional statement. 3. casting Specifying to java that it should treat one data type/object as another or convert primitive types. e.g. int q = (int) 35.5 4. class Definition of behaviors and fields as a blueprint from which objects are instantiated. 5. inheritance The process in which a subclass borrows or inherits behaviors and fields from it's superclass. 6. object Instantiation of a class, has it's own object fields that are different from all other objects of the same type/class. 7. static field (variable) A variable that belongs to a class and not object instances. (It can be accessed and modified by all objects of that class, but is shared between them.) 2. Short Answers ( 6 points) For each of the following questions, write a 2-4 sentence answer: 2a. How is sampled sound stored in a computer? What does each sample represent? The amplitude of a sound wave at each sample point in time is stored using a number between approximately -32K and 32K. For example, 220,50 Hz sampling takes that many samples a second. 2b. How are images stored in a computer? (How are colors for each pixel represented, how much space does a pixel take up in bits and bytes?) Each pixel in an image is represented by 3 eight bit integers (0-255) that represent the intensity of Red, Green and Blue light respectively.

3 / 7 Your Name: 3. Program Comprehension ( 5 points) The recursive function printit is shown below, what is output as a result of the call Print.printIt( rambling, 4);? public class Print { public static void printit(string s, int numchars) { if (numchars > 0 ) { System.out.print( s.charat(numchars 1) ); printit(s, numchars 1); Grading: bmar 5 points ( 1 point if missing a single letter, 1 points if it's vertical, otherwise, it's a zero) 4. Sound Manipulation (15 points) Write a static method called scaledmix which takes in as parameters two Sounds (A and B). The scaledmix method must scale the second (B) sound to be the same length as the first sound (A) and then mix the two sounds together equally. The resulting sound should be returned. You do not need to write an enclosing class, just a static method. Here is some information about three methods defined as part of the Sound class that you may want to use: int Sound Sound getlength() - Method to return the length of the sound as the number of samples. scale(double factor) Scale (in length) up or down myself by the given factor and return the result (1.0 returns the same, 2.0 doubles the length, and 0.5 halves the length) mix(sound mixin, double ratio) - Mix myself with the mixin sound, with a percent ratio of input that can vary from 0.0 to 1.0.

4 / 7 Your Name: public static Sound scaledmix( Sound A, Sound B) { double lengtha = A.getLength(); double lengthb = B.getLength(); B = B.scale( lengtha / lengthb ); Sound retval = A.mix(B, 0.5); return( retval); Grading: 4 points for header (static, Sound, Parameter types are Sound, A,B) 5 points for grading the correct factor (-1 if they didn't ensuring double division) 1 point for using scale 3 points for using mix (1 point for 0.5 ratio, other 2 for correct use) 2 points returning the sound. 5. List Question (14 points) Each element in a doubly linked list has a next pointer that holds a reference to the next node in the list, as well as a prev pointer that holds a reference to the previous node in the list. // Remove node q from a doubly linked list private void dodelete( Node q) { q.getprev().setnext( q.getnext() ); q.getnext().setprev( q.getprev() );

5 / 7 Your Name: 5a. List 3 examples where the code above will fail to properly maintain the doubly linked list structure or throw an exception when removing node Q: (6 points total, 2 per part) 1- Removing the First Node (2pts) 2-Removing the Last Node (2pts) 3-If Q is null (2 pts) (Length of list < 3 only gets 1 point, as it's a restatement of the above two) 5 b. Re-write the dodelete method above to fix the problems, so that it will correctly remove the node Q in all cases. (8 points total) // Remove node q from a doubly linked list private void dodelete( Node q) { // Make sure that q is not null. If it is, give up! if (q == null) { return(); // Make sure we are not the first node in the list before // trying to affect the node in front of us! if( q.getprev()!= null) { q.getprev().setnext( q.getnext() ); // Make sure we are not the last node in the list before // trying to affect the node behind us! if (q.getnext()!= null) { q.getnext().setprev( q.getprev() ); Grading: +2 for doing nothing if Q is null +3 for checking to make sure we are not the first node before attempting to modify the node in front of us. +3 for checking to make sure we are not the last node before attempting to modify the node behind us.

6 / 7 Your Name: 6. Fix Replace (20 points) Review the replace method in the appendix at the end of this test. The replace method will currently replace the contents of the sound with the contents of a newsound, if it matches oldsound. Rewrite the replace method so that it actually compares the sounds (sample-by-sample) rather than simply comparing the filenames to determine if the current sound is one that needs to be replaced. See the last page of the test appendix for source code and API functions that will be helpful. public void replace( Sound oldsound, Sound newsound) { Boolean sameflag; if ( oldsound.getlength()!= this.mysound.getlength() ){ sameflag = false; else { sameflag = true; for ( int I = 0; I < this.mysound.getlength(); i++) { // end for // end else if (sameflagg) { if (this.mysound.getsample(i).getvalue()!= oldsound.getsample(i).getvalue() ) { sameflag = false; // end if this.mysound = newsound; // end method. Grading: +3 Checks to see if the length is the same. If not, do nothing. +9 (If length is the same, iterates over the array and compares this.mysound-> oldsound) +5 detects whether or not they are equal +3 If sounds are equal, replaces the song, if not equal, does nothing.

7 / 7 Your Name: Test Appendix: /** * Replace my sound with the other sound if I match "oldsound" * Two sounds are equal if they have the same filename * @param oldsound sound to be replaced * @param newsound sound to put in its place */ public void replace(sound oldsound, Sound newsound) { if (this.getfilename().equals(oldsound.getfilename())) { // Replace my sound Samples. TODO SoundSamples [] ss = this.getsamples(); SoundSamples [] sssource = newsound.getsamples(); for(int i = 0; i < this.getlength(); i++ ) { ss[i]setvalue( sssource[i].getvalue()); // end for // end if file names are the same. API: // end method replace. Here are a few methods you may want to know about that the Sound object supports: SoundSample getsample(int index) - Method to create and return a SoundSample object for the given index. SoundSample[] getsamples() - Method to create and return an array of all SoundSample objects contained in this Sound. Here are a few methods you may want to know about that the SoundSample object supports: int getvalue() - Method to get the value of this sample as an int void setvalue(int value) - Method to set the value of this sample