8 Pages

final

Course: CS 101, Fall 2008
School: UVA
Rating:
 
 
 
 
 

Word Count: 1422

Document Preview

101 CS Fall 2005 Final Exam Name: _______________________________ Email ID: ________ This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Unlike midterm exams, you have a full 3 hours to work on this exam. This final exam is optional; you may choose not to have this exam be graded. If you do turn in the exam, we will grade it and include this grade in the calculation for your...

Register Now

Unformatted Document Excerpt

Coursehero >> Virginia >> UVA >> CS 101

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
101 CS Fall 2005 Final Exam Name: _______________________________ Email ID: ________ This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Unlike midterm exams, you have a full 3 hours to work on this exam. This final exam is optional; you may choose not to have this exam be graded. If you do turn in the exam, we will grade it and include this grade in the calculation for your final letter grade in the class. If you decide not to turn the exam in, please tear it up and turn in the pieces. Please sign the honor pledge here: Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Total ____ / 5 none ____ / 15 ____ / 20 ____ / 15 ____ / 20 ____ / 25 none ____ / 100 Note: When an integer type is required use int, when a floating-point type is required use double. 1. (1 point) What section are you in? ____ CS 101-E ____ CS 101-3 (lab 12-1:30 PM Fri) ____ CS 101-2 (lab 7-8:30 PM Thu) ____ CS 101-4 (lab 2-3:30 PM Fri) 2. (4 points) What is your overall impression of the class so far? Check only one in each column. ___ Too slow ___ Too fast ___ Just right ___ Too easy ___ Too hard ___ Just right ___ / 5 Page 1 of 8 CS 101 Fall 2005 Final Exam Name: _______________________________ Email ID: ________ The following questions ask you to code up a class to implement a queue. A queue, like the stack class we have discussed, is similar to an array or a vector in that it stores a list of elements. Unlike a stack, where new elements are always added to and removed from the same end of the stack, the elements in a queue are added to one end of the queue and removed from the other end. A queue is sometimes called a FIFO for "First In, First Out", since the first element in a series placed in a queue will be the first element removed from it (as opposed to a stack, or LIFO, where the last element of a series placed in a queue will be the first element removed). Think of a line at a grocery store people enter the line (queue) at one end, and leave the line (queue) at the other (at the cash register). We will say that elements are added to the head of the queue (called enqueing the element) and removed from the tail (called dequeueing). In the class that you implement, you will store the elements of the queue--integers in this case--in an array (not a Vector). For full credit, your implementation should use only a single array and should not create or copy additional arrays e.g. in the enqueue() or dequeue() methods. You may assume that the queue will never be required to store more than 1000 elements at once and size your array accordingly. Note, however, that the queue should be able to enqueue over 1000 items, as long as enough items are dequeued along the way that the queue never contains more than 1000 items all at once. Hint: you will probably want instance variables called "head" and "tail" to indicate where in the array elements will be added and removed. The elements of the queue will form a range in the array between the head and the tail positions. Note that this range may not be contiguous: if many elements are enqueued and dequeued, the head may need to "wrap around" to the beginning of the array (so that the elements of the queue go from array[tail] to array[array.length-1] and from array[0] to array[head]). For example, if you enqueue 1000 elements (so your queue is full), then dequeue 500, your queue will hold the remaining 500 elements in the last 500 positions of the array (positions 500 to 999). You can then enqueue 100 more elements. Thus, your queue will hold 600 elements: the first 500 in positions 500 to 999, the last 100 in positions 0 to 99. For full credit your code must correctly account for this "wrap-around" behavior; however, you will still receive substantial partial credit if your Queue class works correctly but does not support "wrap around". You will provide code for the following: Any necessary instance variables. Queue(): The default constructor. void enqueue(int item): Add the specified integer to the head of the queue. int dequeue(): Remove the integer from the tail of the queue and return it. int peek(): Return the integer at the tail of the queue without removing it. int size(): Return the number of elements currently stored in the queue. String toString(): Return a string suitable for printing the elements currently stored in the queue. boolean containsElement(int item): Search for the specified integer among the elements of the queue. To emphasize that you are writing a single functional class, we have written this up in the form of skeleton code for you to complete. The different code sections equate to exam questions, are and explained further in the comments along with their point values. Your complete answer to these questions should be a functioning Java class. Note that some of the method prototypes (i.e., return type & list of parameters) are incomplete and need to be filled out! Don't forget to count your braces, parentheses, etc. We also include the full code for a main() method to illustrate the use of the Queue class. [none] Page 2 of 8 CS 101 Fall 2005 Final Exam public class Queue { Name: _______________________________ Email ID: ________ // Question 3: 10 points // instance variables: give the code necessary to declare the instance variables // needed by this class, using the information given in the introduction. The // instance variables may be initialized here or in the constructor below. // Question 4: 5 points // Provide the code for the definition of the default constructor. You may // initialize your instance variables here or when they are defined above. ___ / 15 Page 3 of 8 CS 101 Fall 2005 Final Exam Name: _______________________________ Email ID: ________ // Question 5: 10 points // enqueue(): Add the specified integer to the head of the queue // // You may assume that enqueue() will never be called if it would cause // the queue to contain more than 1000 elements public void enqueue (int value) { // Question 6: 10 points // dequeue(): Remove the integer from the tail of the queue and return it // // You may assume that dequeue() will never be called if the queue is empty public int dequeue() { ___ / 20 Page 4 of 8 CS 101 Fall 2005 Final Exam Name: _______________________________ Email ID: ________ // Question 7: 5 points // peek(): Return the integer at the tail of the queue without removing it // // You may assume that peek() will never be called if the queue is empty. // Note that for the remaining questions you must also complete the prototype! peek () { // Question 8: 10 points // size(): Return the number of elements currently stored in the queue size () { ___ / 15 Page 5 of 8 CS 101 Fall 2005 Final Exam Name: _______________________________ Email ID: ________ // Question 9: 20 points // containsElement(): Return true if the queue contains the specified integer // // If the integer isn't present or if the queue is empty you should return false containsElement (int element) { ___ / 20 Page 6 of 8 CS 101 Fall 2005 Final Exam // // // // // // // // Name: _______________________________ Email ID: ________ Question 10: 25 points toString(): Return a String with the elements currently stored in the queue. The String should be of the form, "Queue[a, b, c]" where a,b,c are elements in the queue. The first element (a in this example) should be at the tail of the queue and the final element (c in this case) should be at the head. Of c...

Textbooks related to the document above:
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

UVA - CS - 494
CS 494 Homework 2: Due 27 Feb 2006In this homework, you will complete the first elaboration iteration for the project you described in the first homework. In particular, you will have a fully functioning prototype version of your system ready by th
UVA - CS - 202
CS/APMA 202Midterm 27 April 2005Name: _E-mail ID: _@virginia.eduPledge: _ __ _ Signature: _There are 75 minutes for this exam and 100 points on the test; don't spend too long on any one question! The 12 short answer questions require only
UVA - CS - 101
CS 101 Fall 2005 Midterm 1Name: _Email ID: _This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts (in particular, the final question is worth substantially more than any oth
UVA - CS - 101
CS101 Fall 2005 Midterm 2 Grading GuidelinesQuestion 3: 4 points, each answer worth 1 point Question 4: 3 points, there should be 3 numbers output, each worth a point. Question 5: 3 points, one for each value (j,k, flag) Question 6: 5 points a. 3 va
UVA - CS - 101
CS 101 Spring 2006 Midterm 2Name: _Email ID: _This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure to look over all the questions and plan your time accordingly
UVA - CS - 101
Pledged CS 101 Exam 3 Spring 2005Email Id _ Name _This pledged exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points, we recommend that you
UVA - CS - 101
CS 101 Final Exam Fall 2005Email Id _Name _This pledged exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points, we recommend that you do not
UVA - CS - 415
CS 415 Midterm Exam Spring 2002Name _KEY _ Email Address _ Student ID # _Pledge:This exam is closed note, closed book. Good Luck!Score Fortran Algol 60 Compilation Names, Bindings, Scope Functional Programming Total/100CS415Anderson Sp
UVA - CS - 415
INTERCALAaron Bloomfield CS 415 Fall 2005A note about the sourcesThe main sources for this lecture set are:The INTERCAL page in Wikipediahttp:/en.wikipedia.org/wiki/IntercalThe INTERCAL Programming Language Revised Reference Manual
UVA - CS - 445
TransformationsAaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)Graphics coordinate systems X is red Y is green Z is blue2Graphics coordinate systemsIf you are on the +z axis, and +y is
UVA - CS - 415
Names, Scopes and BindingsAaron Bloomfield CS 415 Fall 200511Binding A binding is an association between two things, such as a name and the thing it represents Example: int x When this statement is compiled, x is bound to a memory space2B
UVA - CS - 415
Debuggers, Analysis Tools and ProfilersAaron Bloomfield CS 415 Fall 20051What is a Debugger?"A software tool that is used to detect the source of program or script errors, by performing step-by-step execution of application code and viewing the
UVA - CS - 445
Rendering PipelineAaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by Greg Humphreys)3D Polygon RenderingMany applications use rendering of 3D polygons with direct illumination23D Polygon RenderingMany ap
UVA - CS - 445
LightingAaron Bloomfield CS 445: Introduction to Graphics Fall 2006Lighting Sogiven a 3-D triangle and a 3-D viewpoint, we can set the right pixels But what color should those pixels be? If were attempting to create a realistic image, we need
UVA - CS - 415
ScanningAaron Bloomfield CS 415 Fall 20051Parsing & Scanning In real compilers the recognizer is split into two phases Scanner: translate input characters to tokens Also, report lexical errors like illegal characters and illegal symbols Pars
UVA - CS - 445
Rendering Pipeline and Graphics HardwareAaron Bloomfield CS 445: Introduction to Graphics Fall 2006Overview Framebuffers How is the rasterized Rendering Pipeline scene kept in memory? Transformations Lighting Clipping Modeling Camera Vis
UVA - CS - 202
Set OperationsCS/APMA 202, Spring 2005 Rosen, section 1.7 Aaron Bloomfield1Sets of ColorsMonitor gamut (M) Printer gamut (P) Pick any 3 "primary" colors Triangle shows mixable color range (gamut) the set of colors2Set operations: Union 1
UVA - CS - 415
In More Depth.Grammars Parsing(Slides copied liberally from Ruth Anderson, Hal Perkins and others)04/19/09CS415 - Fall 20051Parsing The syntax of most programming languages can be specified by a context-free grammar (CGF) Parsing: Given a
UVA - CS - 202
Nested QuantifiersCS/APMA 202, Spring 2005 Rosen, section 1.4 Aaron Bloomfield1Multiple quantifiersYou can have multiple quantifiers on a statement x y P(x, y) "For all x, there exists a y such that P(x,y)" Example: x y (x+y = 0) xy P(x,y)
UVA - CS - 445
CS 445 Introduction to Computer GraphicsFall 2006 Aaron BloomfieldOverviewIntroductionWhat is computer graphics? What is it good for? What will I learn in this course? How much work will there be?ApplicationsSyllabusCoursework
UVA - CS - 415
CS 415: Programming LanguagesAlgol Aaron Bloomfield Fall 2005Historical perspectiveBy mid/late 50s a lot of PLs were out there Interest in universal language European and American groups got together in Zurich Result was Algol 58 8 people spe
UVA - CS - 445
General-Purpose Computation on Graphics HardwareDavid LuebkeUniversity of VirginiaCourse Introduction The GPU on commodity video cards has evolved into an extremely flexible and powerful processor Programmability Precision Power We are in
UVA - CS - 445
RasterizationAaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)The Rendering Pipeline: A TourTransform Illuminate Transform Clip Project RasterizeMode & C e l am ra Param te e rsRe ring Pipe nde
UVA - CS - 202
FunctionsCS 202 Epp section ? Aaron Bloomfield1Definition of a function A function takes an element from a set and maps it to a UNIQUE element in another set2Function terminologyf maps R to Z Domain R f Z Co-domainf(4.3) 4.3 4Pre-image
UVA - CS - 202
Propositional EquivalencesCS/APMA 202, Spring 2005 Rosen, section 1.2 Aaron Bloomfield1Tautology and ContradictionA tautology is a statement that is always truep p will always be true(Negation Law)A contradiction is a statement that is al
UVA - CS - 415
Objective Caml (Ocaml)Aaron Bloomfield CS 415 Fall 20051ML history ML first developed in late 1970's Stands for Meta Langauage Not a "pure" function language Has functions with side effects, imperative programming capabilities Haskell is a
UVA - CS - 202
Methods of ProofCS 202 Rosen section 1.5 Aaron Bloomfield1In this slide set.Rules of inference for propositions Rules of inference for quantified statements Ten methods of proof2Proof methods in this slide setLogical equivalences Ten pro
UVA - CS - 202
Boolean LogicCS 202, Spring 2007 Epp, sections 1.1 and 1.2 Aaron Bloomfield1Administratrivia HW 1: due next Friday Section 1.1 # 49, 52 Section 1.2 # 34, 44, 46 Today's lecture will be somewhat of a review Next week we will see applications
UVA - CS - 445
Making MoviesAaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Brogan)Making Movies Concept Storyboarding Sound Character Development Layout and look Effects Animation Lighting2Concept"Not
UVA - CS - 101
GUI programmingGraphical user interfacebased programmingWindchill Windchill There are several formulas for calculating the windchill temperature twc The one provided by U.S. National Weather Service and is applicable for a windspeed greater tha
UVA - CS - 101
Fall 2004 - CS 101: Test 1Name _UVA Email ID _I. Computing and programming fundamentals1. (4 points) Give two examples of non-PC computing devices.Part I Part II Part III2. (4 points) What does Java program compilation do?Total3. (4 poin
UVA - CS - 101
Fall 2004 - CS 101: Test 3Name _UVA Email ID _Page 1 _ / 10 1. (Bonus 2 points) What is your section? 101 Page 4 _ / 17 101E Page 5 _ / 25 Page 6 _ / 20 Page 2 _ / 10 Page 3 _ / 18Total _ /100 2. (5 points) What is the output of the following c
UVA - CS - 101
CS 101 Exam 1 Spring 200Email Id _ Name _This exam is open text book and closed notes. Different questions have different points associated with them with later occurring questions having more worth than the beginning questions. Because your goal
UVA - CS - 101
CS 101 / CS 101-Ehttp:/www.cs.virginia.edu/~cs101M/W 2:00-3:15 CHM 402 / MEC 205Instructors: CS 101 Aaron Bloomfield http:/www.cs.virginia.edu/~asbCS 101-E James Cohoon http:/www.cs.virginia.edu/~cohoonOffice: Olsson Hall, room 228D Office: O
UVA - CS - 101
Take care with floating-point valuesConsider double a = 1; double b = 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 double c = .9999999999999999; Two true expressions! c = b b != a Two false expressions! a = b b != c Problem lies with th
UVA - CS - 101
Testing and ExceptionsException Abnormal event occurring during program execution Examples Manipulate nonexistent files File file = new File(s); Scanner fileIn = new Scanner(file); Improper array subscripting int[] a = new int[3]; a
UVA - CS - 101
BooleanvaluesGatewaytodecisionmakingBackground Ourproblemsolvingsolutionssofarhavethestraightlineproperty TheyexecutethesamestatementsforeveryrunoftheprogrampublicclassDisplayForecast /main():applicationentrypoint publicstaticvoidmain(String[]a
UVA - CS - 101
Cir cleKeeps on r ol l i ng Pr oblem design a cir cle r epr esent at ionSome possi bl e questi ons to ask What ki nd of ci r cl e? Why not use an exi sti ng ci r cl e r epr esentati on? What pl ans do you have for the ci r cl e? What
UVA - CS - 101
ClassesPreparation Scenesofarhasbeenbackgroundmaterialandexperience Computingsystemsandproblemsolving Variables Types Inputandoutput Expressions Assignments Objects StandardclassesandmethodsReady ExperiencewhatJavaisreallyabout Designa
UVA - CS - 101
Review for exam 1CS 101 Aaron Bloomfield1Todays lectureAn overview of the review sections of chapters 1-3 Stop me if you want me to go over something in more detail!2Material you may not be comfortable withConstructorsI know there is a
UVA - CS - 101
Iteration 1Java loopingOptions while dowhile for Allow programs to control how many times a statement list is executed 2AveragingProblem Extract a list of positive numbers from standard input and produce their average Number
UVA - CS - 101
Programming with methods and classes 1MethodsInstance (or member) method Operates on a object (i.e., and instance of the class)String s = new String("Help every cow reach its " + "potential!"); int n = s.length(); Instance method
UVA - CS - 101
Using ObjectsChapter 3 Spring 2005 CS 101 Aaron Bloomfield 1About the assignment statementAssign the value 5 to the variable x int x; x = 5; 5 = x; NOT VALID! This is not a mathematical equals It's a Java assignment The variable you wan
UVA - CS - 101
JavabasicsInclassquiz What aretherule for an ide s ntifie in Java? r In what m thod doe a programbe What is there e s gin? turn typeof that m thod? What e param te doe it re e r(s) s quire ? What is thee xpone ntiation ope rator in Java? How do w
UVA - CS - 101
CS 101Chapter 1: Background Spring 2005 Aaron Bloomfield1Let's beginGoalTeach you how to program effectivelySkills and information to be acquired Mental model of computer and network behavior Problem solving Object-oriented design Jav
UVA - CS - 101
StaplesareourstapleBuilding upon our solutionWhydidthisprogramworkpublicclassStaplerSimulation{ publicstaticvoidmain(String[]args){ StaplermyStapler=newStapler(); System.out.println(myStapler); myStapler.fill(); System.out.println(myStapler); my
UVA - CS - 101
Arrays 1BackgroundProgrammer often need the ability to represent a group of values as a list List may be onedimensional or multidimensional Java provides arrays and the collection classes The Vector class is an example of a collection cla
UVA - CS - 101
ArraysContinued 1Consideredint[] v = new int[10]; int i = 7; int j = 2; int k = 4; v[0] = 1; v[i] = 5; v[j] = v[i] + 3; v[j+1] = v[i] + v[0]; v[v[j] = 12; System.out.println(v[2]); v[k] = stdin.nextInt();v 1v[0]0v[1]8v[2]6v[3]3v
UVA - CS - 101
Decisions,decisions,decisionsChapter5 Spring2005 CS101 AaronBloomfield1BackgroundOurproblemsolvingsolutionssofarhavethestraightlineproperty TheyexecutethesamestatementsforeveryrunoftheprogrampublicclassDisplayForecast /main():applicatione
UVA - CS - 101
Page 2Question 2 No partial creditQuestion 3 No partial creditQuestion 4 No partial creditQuestion 5 No partial creditQuestion 6 -1 if float instead of doubleQuestion 7 -1 if the word 'swap' was mentioned -3 if there are no words
UVA - CS - 101
A B CD E FThis file has 38 characters.
UVA - CS - 101
ABCDEFThisfilehas30characters.
UVA - CS - 415
Fortran lectureFortran history Why do we care? o Was one of the most influential programming languages of all time o It's development mirrors PL evolution o Was the de facto programming languages for many years o Was the first high level language
UVA - CS - 101
Spring 2007 CS 101EMichele CoBoolean Expressions, Precedence, and If StatementsDescription: The following questions demonstrate key concepts related to evaluating Boolean expressions and evaluation precedence. Directions: Discuss your reasoning
UVA - CS - 101
CS 101 Spring 2006 Final ExamName: _Email ID: _This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Unlike the midterm exams, you have a full 3 hours to work on this exam. Please sign the honor pledge here:Pa
UVA - CS - 101
CS 101 Spring 2007 Midterm 1Name: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be s
UVA - CS - 101
CS 101 Spring 2006 Midterm 3Name: _Email ID: _This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure to look over all the questions and plan your time accordingly
UVA - CS - 101
CS 101 Spring 2007 Midterm 2Name: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be s
UVA - CS - 101
CS 101 Fall 2006 Midterm 3Name: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sur
UVA - CS - 101
CS 101 Fall 2006 Final ExamName: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be su
UVA - CS - 101
CS 101 Fall 2006 Midterm 2Name: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sur