Array. 9 January 2015 OSU CSE 1
|
|
- Juliana Griffith
- 6 years ago
- Views:
Transcription
1 Array 9 January 2015 OSU CSE 1
2 Array The Array component family allows you to manipulate arrays in a way that overcomes surprising limitations of built-in Java arrays, but retains the time/space performance of built-in arrays Another generic type like Sequence and Set A best practice alternative from the OSU CSE components to the built-in Java array (more like built-in arrays than Sequence is) 9 January 2015 OSU CSE 2
3 Problems With Built-in Arrays Suppose you want to declare an array of type T, where T is a generic parameter, e.g.: T[] table = new T[100]; Oops; this won t compile! The reason is complicated, having to do with backward compatibility when Java generics were introduced and the inability to call a constructor for type T, among other oddities 9 January 2015 OSU CSE 3
4 Problems With Built-in Arrays Or, suppose you want to declare an array of type Queue<T>, e.g.: Queue<T>[] table = new Queue<T>[100]; Oops; this won t compile either! Yet this is exactly the kind of thing you want to do when creating a hashtable: the buckets are collections of a parameterized type 9 January 2015 OSU CSE 4
5 Workarounds There are various workarounds that can be used, but they are ugly and generate warnings that you should generally heed rather than ignore These problems do not arise with the Array component family, so it can (and should) be used in many cases where you might be inclined to try built-in Java arrays 9 January 2015 OSU CSE 5
6 The Intuition The rather simple idea is to provide a generic interface Array<T> that provides the same functionality as built-in arrays, but where the entries may be of any type T The data representation used in Array1L<T> is a built-in array But this data representation is hidden from the client, along with one of the workarounds mentioned earlier 9 January 2015 OSU CSE 6
7 Interfaces and Classes Standard extends extends Iterable ArrayKernel extends Array implements Array1L 9 January 2015 OSU CSE 7
8 Interfaces and Classes Standard extends extends Iterable ArrayKernel ArrayKernel has contracts for four methods: setentry entry maybeexamined length extends Array implements Array1L 9 January 2015 OSU CSE 8
9 Interfaces and Classes Standard Array has contracts for Iterable two methods: extends replaceentry extends exchangeentries ArrayKernel Array Array1L extends implements 9 January 2015 OSU CSE 9
10 Interfaces and Classes There is really Standard abstract Iterable class as usual in the chain here, but it is not extends shown extends because these slides describe the client view, ArrayKernel and a client needs only interface Array and class Array1L. extends Array Array1L implements 9 January 2015 OSU CSE 10
11 Mathematical Model ARRAY_MODEL is ( entries: string of T, examinableindices: finite set of integer) exemplar a constraint for all i: integer where (i is in a.examinableindices) (0 <= i and i < a.entries ) type ArrayKernel is modeled by ARRAY_MODEL 9 January 2015 OSU CSE 11
12 Mathematical Model ARRAY_MODEL is ( entries: string of T, examinableindices: finite set of integer) exemplar a constraint for all i: integer The set examinableindices where (i is keeps in a.examinableindices) track of the indices in the Array that have been initialized (0 <= i and by i a < call a.entries ) to setentry, because only these indices may be type ArrayKernel is examined modeled by a by call ARRAY_MODEL to entry. 9 January 2015 OSU CSE 12
13 Constructor from int There is no no-argument constructor, but there is a constructor with one parameter int n Requires: n >= 0 Ensures: this.entries = n and this.examinableindices = {} 9 January 2015 OSU CSE 13
14 Example Code State Array<Integer> ai = new Array1L<>(3); 9 January 2015 OSU CSE 14
15 Example Code State Array<Integer> ai = new Array1L<>(3); ai = (<?,?,?>, {}) 9 January 2015 OSU CSE 15
16 Example All we know from the constructor Code contract is that the length of this string of integer is 3; we do not know its actual value. Array<Integer> ai = new Array1L<>(3); State ai = (<?,?,?>, {}) 9 January 2015 OSU CSE 16
17 setentry void setentry(int i, T x) Sets the entry at index i of this to x. Aliases: reference x Updates: this Requires: 0 <= i and i < this.entries Ensures: this.entries = #this.entries[0, i) * <x> * #this.entries[i+1, #this.entries ) and this.examinableindices = #this.examinableindices union {i} 9 January 2015 OSU CSE 17
18 Example Code State ai = (<?,?,?>, {}) z = 70 ai.setentry(1, z); 9 January 2015 OSU CSE 18
19 Example Code State ai = (<?,?,?>, {}) z = 70 ai.setentry(1, z); ai = (<?, 70,?>, {1}) z = 70 9 January 2015 OSU CSE 19
20 Example Note the alias created here, which Code you cannot see in the tracing table; you should be able to draw the appropriate diagram showing it. State ai = (<?,?,?>, {}) z = 70 ai.setentry(1, z); ai = (<?, 70,?>, {1}) z = 70 9 January 2015 OSU CSE 20
21 Another Example Code State ai = (<?, -8,?>, {1}) z = 70 ai.setentry(1, z); 9 January 2015 OSU CSE 21
22 Another Example Code State ai = (<?, -8,?>, {1}) z = 70 ai.setentry(1, z); ai = (<?, 70,?>, {1}) z = 70 9 January 2015 OSU CSE 22
23 entry T entry (int i) Reports the entry at index i of this. Aliases: reference returned by entry Requires: i is in this.examinableindices Ensures: <entry> = this.entries[i, i+1) 9 January 2015 OSU CSE 23
24 entry T entry(int i) i is within bounds, i.e.: Reports the entry at position 0 <= i iof this. and i < this.entries Aliases: reference returned by entryat Note that this implies the index Requires: i is in this.examinableindices Ensures: <entry> = this.entries[i, i+1) 9 January 2015 OSU CSE 24
25 Example Code State ai = (<?, 70, -3>, {1, 2}) z = 584 z = ai.entry(1); 9 January 2015 OSU CSE 25
26 Example Code State ai = (<?, 70, -3>, {1, 2}) z = 584 z = ai.entry(1); ai = (<?, 70, -3>, {1, 2}) z = 70 9 January 2015 OSU CSE 26
27 Example Note the alias Code created here, which you cannot see in the tracing table; you should be able to draw the appropriate diagram showing it. z = ai.entry(1); State ai = (<?, 70, -3>, {1, 2}) z = 584 ai = (<?, 70, -3>, {1, 2}) z = 70 9 January 2015 OSU CSE 27
28 maybeexamined boolean maybeexamined(int i) Reports whether the entry at index i of this may be examined using entry. Ensures: maybeexamined = i is in this.examinableindices 9 January 2015 OSU CSE 28
29 Example Code State ai = (<?, 70, -3>, {1, 2}) boolean ok = ai.maybeexamined(1); 9 January 2015 OSU CSE 29
30 Example Code State ai = (<?, 70, -3>, {1, 2}) boolean ok = ai.maybeexamined(1); ai = (<?, 70, -3>, {1, 2}) ok = true 9 January 2015 OSU CSE 30
31 length int length() Reports the length of this. Ensures: length = this.entries 9 January 2015 OSU CSE 31
32 replaceentry T replaceentry(int i, T x) Replaces the entry at index i of this with x, and returns the old entry at that index. Aliases: reference x Updates: this.entries Requires: i is in this.examinableindices Ensures: this.entries = #this.entries[0, i) * <x> * #this.entries[i+1, #this ) and <replaceentry> = #this.entries[i, i+1) 9 January 2015 OSU CSE 32
33 Example Code State ai = (<?, 70, -3>, {1, 2}) z = 58 w = 94 w = ai.replaceentry(2, z); 9 January 2015 OSU CSE 33
34 Example Code State ai = (<?, 70, -3>, {1, 2}) z = 58 w = 94 w = ai.replaceentry(2, z); ai = (<?, 70, 58>, {1, 2}) z = 58 w = -3 9 January 2015 OSU CSE 34
35 Example Note the alias Code created here, which you cannot see in the tracing table; you should be able to draw the appropriate diagram showing it. State ai = (<?, 70, -3>, {1, 2}) z = 58 w = 94 w = ai.replaceentry(2, z); ai = (<?, 70, 58>, {1, 2}) z = 58 w = -3 9 January 2015 OSU CSE 35
36 Another Example Code State ai = (<?, 70, -3>, {1, 2}) z = 58 z = ai.replaceentry(2, z); 9 January 2015 OSU CSE 36
37 Another Example Code State ai = (<?, 70, -3>, {1, 2}) z = 58 z = ai.replaceentry(2, z); ai = (<?, 70, 58>, {1, 2}) z = -3 9 January 2015 OSU CSE 37
38 Another Example This use of Code the method avoids creating an alias: it swaps z with the entry previously at index 2. State ai = (<?, 70, -3>, {1, 2}) z = 58 z = ai.replaceentry(2, z); ai = (<?, 70, 58>, {1, 2}) z = -3 9 January 2015 OSU CSE 38
39 exchangeentries void exchangeentries(int i, int j) Exchanges entries at indices i and j of this. Updates: this.entries Requires: {i, j} is subset of this.examinableindices Ensures: this.entries = [#this.entries with entries at indices i and j exchanged] 9 January 2015 OSU CSE 39
40 Example Code State ai = (<?, 70, -3>, {1, 2}) ai.exchangeentries(1, 2); 9 January 2015 OSU CSE 40
41 Example Code State ai = (<?, 70, -3>, {1, 2}) ai.exchangeentries(1, 2); ai = (<?, -3, 70>, {1, 2}) 9 January 2015 OSU CSE 41
42 iterator Iterator<T> iterator() Returns an iterator over a set of elements of type T. Ensures: ~this.seen * ~this.unseen = [string of entries of this.entries, in order by increasing index, where index is in this.examinableindices] 9 January 2015 OSU CSE 42
43 Resources OSU CSE Components API: Array 9 January 2015 OSU CSE 43
More About Heaps. 14 June 2017 OSU CSE 1
More About Heaps 14 June 2017 OSU CSE 1 Complete Binary Tree As Array To use an Array to represent a complete binary tree, you need more information: An int index of the root of the tree of interest There
More informationJava Interfaces. 6 April 2016 OSU CSE 1
Java Interfaces 6 April 2016 OSU CSE 1 Conceptual Framework A firm conceptual foundation for understanding and designing modern software recognizes: Modern software consists of potentially large numbers
More informationRepeated Arguments. 26 April 2013 OSU CSE 1
Repeated Arguments 26 April 2013 OSU CSE 1 Sources of Aliasing Aliased references for mutable types can cause trouble, so it is important to know how aliases might arise One way (which is easy to recognize
More informationSet4. 8 February 2019 OSU CSE 1
Set4 8 February 2019 OSU CSE 1 Documenting Set4 (and Map4) By now you understand hashing and its benefits. But the algorithms we are using are not trivial, and make a lot of assumptions about the representation.
More informationCIS 341 Final Examination 4 May 2017
CIS 341 Final Examination 4 May 2017 1 /14 2 /15 3 /12 4 /14 5 /34 6 /21 7 /10 Total /120 Do not begin the exam until you are told to do so. You have 120 minutes to complete the exam. There are 14 pages
More informationClass object initialization block destructor Class object
In this segment, I will review the Java statements and primitives that relate explicitly to Object Oriented Programming. I need to re-enforce Java s commitment to OOP. Unlike C++, there is no way to build
More informationKernel Implementations I. 27 June 2013 OSU CSE 1
Kernel Implementations I 27 June 2013 OSU CSE 1 So, What s Inside the Computer? Consider any popular video game, e.g., Nintendo Wii bowling Are there bowling balls and bowling pins inside the game console
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationKernel Implementations III. 6 May 2013 OSU CSE 1
Kernel Implementations III 6 May 2013 OSU CSE 1 Implementing a Kernel Class From the examples so far, you should see there are two major questions to address: Q1: What data representation (a.k.a. data
More information3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.
3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.
More informationCantor s Diagonal Argument for Different Levels of Infinity
JANUARY 2015 1 Cantor s Diagonal Argument for Different Levels of Infinity Michael J. Neely University of Southern California http://www-bcf.usc.edu/ mjneely Abstract These notes develop the classic Cantor
More information} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.
Class #10: Understanding Primitives and Assignments Software Design I (CS 120): M. Allen, 19 Sep. 18 Java Arithmetic } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = 2 + 5 / 2; 3.
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #29 Arrays in C
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #29 Arrays in C (Refer Slide Time: 00:08) This session will learn about arrays in C. Now, what is the word array
More informationCSE373 Fall 2013, Second Midterm Examination November 15, 2013
CSE373 Fall 2013, Second Midterm Examination November 15, 2013 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please
More informationExam 1 - (20 points)
Exam 1 - (20 points) Answer all of the following questions. READ EACH QUESTION CAREFULLY. Fill the correct bubble on your scantron sheet. Each correct answer is worth 1 point (unless otherwise stated).
More informationLecture 8: Iterators and More Mutation
Integrated Introduction to Computer Science Fisler, Nelson Contents 1 Traversing Lists 1 2 Motivating Iterators 2 3 Writing an Iterator 3 4 Writing Sum with an Iterator 4 Objectives By the end of this
More informationLecture 5 Sorting Arrays
Lecture 5 Sorting Arrays 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning, Rob Simmons We begin this lecture by discussing how to compare running times of functions in an abstract,
More informationWhat is the Java Collections Framework?
1 of 13 What is the Java Collections Framework? To begin with, what is a collection?. I have a collection of comic books. In that collection, I have Tarzan comics, Phantom comics, Superman comics and several
More informationLecture Notes on Memory Layout
Lecture Notes on Memory Layout 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 11 1 Introduction In order to understand how programs work, we can consider the functions,
More informationModule 11. Collections and Iterators. Adapted from Absolute Java, Rose Williams, Binghamton University
Module 11 Collections and Iterators Adapted from Absolute Java, Rose Williams, Binghamton University Parameterized Classes and Generics Beginning with version 5.0, Java allows class and method definitions
More informationCMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists
CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists Due on Tuesday February 24, 2015, 8:30 a.m. Marc Liberatore and John Ridgway Morrill I N375 Section 01 @ 10:00 Section 02 @ 08:30 1 CMPSCI
More informationBinary Search. Roland Backhouse February 5th, 2001
1 Binary Search Roland Backhouse February 5th, 2001 Outline 2 An implementation in Java of the card-searching algorithm is presented. Issues concerning the correctness of the implementation are raised
More informationintroduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion
introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion Today s video will talk about an important concept in computer science which is
More informationExpressions and Casting
Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence
More informationAt this time we have all the pieces necessary to allocate memory for an array dynamically. Following our example, we allocate N integers as follows:
Pointers and Arrays Part II We will continue with our discussion on the relationship between pointers and arrays, and in particular, discuss how arrays with dynamical length can be created at run-time
More informationCOS 126 General Computer Science Spring Written Exam 1
COS 126 General Computer Science Spring 2017 Written Exam 1 This exam has 9 questions (including question 0) worth a total of 70 points. You have 50 minutes. Write all answers inside the designated spaces.
More informationCIS 341 Final Examination 3 May 2011
CIS 341 Final Examination 3 May 2011 1 /16 2 /20 3 /40 4 /28 5 /16 Total /120 Do not begin the exam until you are told to do so. You have 120 minutes to complete the exam. There are 12 pages in this exam.
More informationDiscover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.
Java SE11 Development Java is the most widely-used development language in the world today. It allows programmers to create objects that can interact with other objects to solve a problem. Explore Java
More informationType Checking. Chapter 6, Section 6.3, 6.5
Type Checking Chapter 6, Section 6.3, 6.5 Inside the Compiler: Front End Lexical analyzer (aka scanner) Converts ASCII or Unicode to a stream of tokens Syntax analyzer (aka parser) Creates a parse tree
More informationJava Loose Ends. 11 December 2017 OSU CSE 1
Java Loose Ends 11 December 2017 OSU CSE 1 What Else? A few Java issues introduced earlier deserve a more in-depth treatment: Try-Catch and Exceptions Members (static vs. instance) Nested interfaces and
More informationObjectives for this class meeting. 1. Conduct review of core concepts concerning contracts and pre/post conditions
CSE1720 Click to edit Master Week text 01, styles Lecture 02 Second level Third level Fourth level Fifth level Winter 2015! Thursday, Jan 8, 2015 1 Objectives for this class meeting 1. Conduct review of
More informationPointers. A pointer is simply a reference to a variable/object. Compilers automatically generate code to store/retrieve variables from memory
Pointers A pointer is simply a reference to a variable/object Compilers automatically generate code to store/retrieve variables from memory It is automatically generating internal pointers We don t have
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Object-Oriented Programming Intro Department of Computer Science University of Maryland, College Park Object-Oriented Programming (OOP) Approach to improving software
More informationJava Collections Framework. 24 April 2013 OSU CSE 1
Java Collections Framework 24 April 2013 OSU CSE 1 Overview The Java Collections Framework (JCF) is a group of interfaces and classes similar to the OSU CSE components The similarities will become clearly
More informationCS162: Introduction to Computer Science II. Primitive Types. Primitive types. Operations on primitive types. Limitations
CS162: Introduction to Computer Science II Primitive Types Java Fundamentals 1 2 Primitive types The eight primitive types in Java Primitive types: byte, short, int, long, float, double, char, boolean
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and
More informationCS6301 PROGRAMMING AND DATA STRUCTURES II QUESTION BANK UNIT-I 2-marks ) Give some characteristics of procedure-oriented language. Emphasis is on doing things (algorithms). Larger programs are divided
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #43 Multidimensional Arrays In this video will look at multi-dimensional arrays. (Refer Slide Time: 00:03) In
More information2. [20] Suppose we start declaring a Rectangle class as follows:
1. [8] Create declarations for each of the following. You do not need to provide any constructors or method definitions. (a) The instance variables of a class to hold information on a Minesweeper cell:
More informationBig-O-ology. Jim Royer January 16, 2019 CIS 675. CIS 675 Big-O-ology 1/ 19
Big-O-ology Jim Royer January 16, 2019 CIS 675 CIS 675 Big-O-ology 1/ 19 How do you tell how fast a program is? Answer? Run some test cases. Problem You can only run a few test cases. There will be many
More informationCMPSCI 187: Programming With Data Structures. Lecture 6: The StringLog ADT David Mix Barrington 17 September 2012
CMPSCI 187: Programming With Data Structures Lecture 6: The StringLog ADT David Mix Barrington 17 September 2012 The StringLog ADT Data Abstraction Three Views of Data Java Interfaces Defining the StringLog
More informationCollections, Maps and Generics
Collections API Collections, Maps and Generics You've already used ArrayList for exercises from the previous semester, but ArrayList is just one part of much larger Collections API that Java provides.
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More informationProcedural programming. [verb-oriented] Tell the computer to do this. (Spring 2012)
2/26/12 Object Oriented Programming CS 112 Introduction to Programming Procedural programming. [verb-oriented] Tell the computer to do this. (Spring 2012) Lecture #21: Designing Data Types Tell the computer
More informationEECS 2011 M: Fundamentals of Data Structures
EECS 2011 M: Fundamentals of Data Structures Suprakash Datta Office: LAS 3043 Course page: http://www.eecs.yorku.ca/course/2011m Also on Moodle S. Datta (York Univ.) EECS 2011 W18 1 / 19 Iterators and
More informationCSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)
Name: Email address: Quiz Section: CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will
More informationCSE331 Winter 2014, Midterm Examination February 12, 2014
CSE331 Winter 2014, Midterm Examination February 12, 2014 Please do not turn the page until 10:30. Rules: The exam is closed-book, closed-note, etc. Please stop promptly at 11:20. There are 100 points
More informationFall 2017 Mentoring 9: October 23, Min-Heapify This. Level order, bubbling up. Level order, bubbling down. Reverse level order, bubbling up
CSM B Heaps & Hashing Fall 0 Mentoring : October 3, 0 Min-Heapify This. In general, there are 4 ways to heapify. Which ways actually work? Level order, bubbling up Level order, bubbling down Reverse level
More informationCSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.
CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please stop promptly
More informationCS162: Introduction to Computer Science II
CS162: Introduction to Computer Science II Java Fundamentals 1 Primitive Types 2 1 Primitive types: Primitive types byte, short, int, long, float, double, char, boolean Example: int size = 42; size is
More informationProtection Levels and Constructors The 'const' Keyword
Protection Levels and Constructors The 'const' Keyword Review: const Keyword Generally, the keyword const is applied to an identifier (variable) by a programmer to express an intent that the identifier
More informationInf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics
Inf1-OP Inf1-OP Exam Review Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein School of Informatics March 20, 2017 Overview Overview of examinable material: Lectures Week 1
More informationPrograms as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects
CS256 Computer Science I Kevin Sahr, PhD Lecture 11: Objects 1 Programs as Models remember: we write programs to solve realworld problems programs act as models of the real-world problem to be solved one
More informationClass API. Class API. Constructors. CS200: Computer Science I. Module 19 More Objects
CS200: Computer Science I Module 19 More Objects Kevin Sahr, PhD Department of Computer Science Southern Oregon University 1 Class API a class API can contain three different types of methods: 1. constructors
More informationAnnouncements/Follow-ups
Announcements/Follow-ups Midterm #2 Friday Everything up to and including today Review section tomorrow Study set # 6 online answers posted later today P5 due next Tuesday A good way to study Style omit
More informationTHE CATHOLIC UNIVERSITY OF EASTERN AFRICA A. M. E. C. E. A
THE CATHOLIC UNIVERSITY OF EASTERN AFRICA A. M. E. C. E. A MAIN EXAMINATION P.O. Box 62157 00200 Nairobi - KENYA Telephone: 891601-6 Fax: 254-20-891084 E-mail:academics@cuea.edu AUGUST - DECEMBER 2015
More informationCONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays
CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types COMP-202 Unit 6: Arrays Introduction (1) Suppose you want to write a program that asks the user to enter the numeric final grades of 350 COMP-202
More informationVector and Free Store (Vectors and Arrays)
DM560 Introduction to Programming in C++ Vector and Free Store (Vectors and Arrays) Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark [Based on slides by Bjarne
More informationCompuScholar, Inc. Alignment to Nevada "Computer Science" Course Standards
CompuScholar, Inc. Alignment to Nevada "Computer Science" Course Standards Nevada Course Details: Course Name: Computer Science Primary Cluster: Information and Media Technologies Standards Course Code(s):
More informationLecture Topics. Administrivia
ECE498SL Lec. Notes L8PA Lecture Topics overloading pitfalls of overloading & conversions matching an overloaded call miscellany new & delete variable declarations extensibility: philosophy vs. reality
More informationQUIZ. What is wrong with this code that uses default arguments?
QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code
More informationCSE 331 Software Design and Implementation. Lecture 14 Generics 2
CSE 331 Software Design and Implementation Lecture 14 Generics 2 Zach Tatlock / Spring 2018 Big picture Last time: Generics intro Subtyping and Generics Using bounds for more flexible subtyping Using wildcards
More informationC++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 6: User-Defined Functions I In this chapter, you will: Objectives Learn about standard (predefined) functions and discover
More information1 10 3:30 5: :30 1:30 206, ICICS/CS
Department of Computer Science Undergraduate Events Events this week Resume Editing Drop-In Session Date: Mon., Feb 1 Time: 11 am 2 pm Location: Rm 255, ICICS/CS EADS Info Session Date: Mon., Feb 1 Time:
More informationCSE 143 SAMPLE MIDTERM
CSE 143 SAMPLE MIDTERM 1. (5 points) In some methods, you wrote code to check if a certain precondition was held. If the precondition did not hold, then you threw an exception. This leads to robust code
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 7a Andrew Tolmach Portland State University 1994-2016 Values and Types We divide the universe of values according to types A type is a set of values and a
More informationANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions
Birkbeck (University of London) Software and Programming 1 In-class Test 1.1 8 Feb 2018 Student Name Student Number Answer all questions 1. Consider the following sequence of Java statements: int i = 3;
More information1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides
1B1b Inheritance Agenda Introduction to inheritance. How Java supports inheritance. Inheritance is a key feature of object-oriented oriented programming. 1 2 Inheritance Models the kind-of or specialisation-of
More informationCOEN244: Class & function templates
COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library
More informationTemplates Templates are functions or classes that are parameterized. We have already seen a few in STL:
Templates Templates are functions or classes that are parameterized. We have already seen a few in STL: std::vector< int > std::vector< double > std::list< std::vector< >> std::unordered_map< int, bool
More informationCS61B Lecture #2. Public Service Announcements:
CS61B Lecture #2 Please make sure you have obtained an account, run register, and finished the survey today. In the future (next week), the password required for surveys and such will be your account password
More informationSyntax of Eiffel: a Brief Overview
Syntax of Eiffel: a Brief Overview EECS3311 A: Software Design Fall 2018 CHEN-WEI WANG Escape Sequences Escape sequences are special characters to be placed in your program text. In Java, an escape sequence
More informationCSE 230 Computer Science II (Data Structure) Introduction
CSE 230 Computer Science II (Data Structure) Introduction Fall 2017 Stony Brook University Instructor: Shebuti Rayana Basic Terminologies Data types Data structure Phases of S/W development Specification
More informationEXAM Computer Science 1 Part 1
Maastricht University Faculty of Humanities and Science Department of Knowledge Engineering EXAM Computer Science 1 Part 1 Block 1.1: Computer Science 1 Code: KEN1120 Examiner: Kurt Driessens Date: Januari
More informationAdvanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II
Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Ad hoc-polymorphism Outline Method overloading Sub-type Polymorphism Method overriding Dynamic
More informationCS S-08 Arrays and Midterm Review 1
CS112-2012S-08 Arrays and Midterm Review 1 08-0: Arrays ArrayLists are not part of Java proper 08-1: Arrays Library class Created using lower-level Java construct: Array Arrays are like a stripped-down
More informationObject Orientated Analysis and Design. Benjamin Kenwright
Notation Part 2 Object Orientated Analysis and Design Benjamin Kenwright Outline Review What do we mean by Notation and UML? Types of UML View Continue UML Diagram Types Conclusion and Discussion Summary
More information1007 Imperative Programming Part II
Agenda 1007 Imperative Programming Part II We ve seen the basic ideas of sequence, iteration and selection. Now let s look at what else we need to start writing useful programs. Details now start to be
More informationCommands, and Queries, and Features. Syntax of Eiffel: a Brief Overview. Escape Sequences. Naming Conventions
Commands, and Queries, and Features Syntax of Eiffel: a Brief Overview EECS3311 A: Software Design Fall 2018 CHEN-WEI WANG In a Java class: Attributes: Data Mutators: Methods that change attributes without
More informationArray Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)
Array Basics: Outline Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and Constants
More informationPolymorphism. CMSC 330: Organization of Programming Languages. Two Kinds of Polymorphism. Polymorphism Overview. Polymorphism
CMSC 330: Organization of Programming Languages Polymorphism Polymorphism Definition Feature that allows values of different data types to be handled using a uniform interface Applicable to Functions Ø
More informationExpressions and Casting. Data Manipulation. Simple Program 11/5/2013
Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence
More informationCS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find
CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS
More informationThe compilation process is driven by the syntactic structure of the program as discovered by the parser
Semantic Analysis The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic routines: interpret meaning of the program based on its syntactic structure
More informationCOS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism
COS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism Ibrahim Albluwi Composition A GuitarString has a RingBuffer. A MarkovModel has a Symbol Table. A Symbol Table has a Binary
More informationMaterial from Recitation 1
Material from Recitation 1 Darcey Riley Frank Ferraro January 18, 2011 1 Introduction In CSC 280 we will be formalizing computation, i.e. we will be creating precise mathematical models for describing
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationDO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N.
CS61B Fall 2013 UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division Test #2 Solutions DO NOT P. N. Hilfinger REPRODUCE 1 Test #2 Solution 2 Problems
More informationIMACS: AP Computer Science A
IMACS: AP Computer Science A OVERVIEW This course is a 34-week, 4 classroom hours per week course for students taking the College Board s Advanced Placement Computer Science A exam. It is an online course
More informationJava Comparable interface
Java Comparable interface Recall that to define a binary search tree, the elements that we are considering must be comparable to each other, meaning that there must be a well-defined ordering. For strings
More informationWhat is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one
Iterators What is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one 9-2 2-2 What is an Iterator? An iterator is an abstract data
More informationLecture Notes on Contracts
Lecture Notes on Contracts 15-122: Principles of Imperative Computation Frank Pfenning Lecture 2 August 30, 2012 1 Introduction For an overview the course goals and the mechanics and schedule of the course,
More informationCISC-124. This week we continued to look at some aspects of Java and how they relate to building reliable software.
CISC-124 20180129 20180130 20180201 This week we continued to look at some aspects of Java and how they relate to building reliable software. Multi-Dimensional Arrays Like most languages, Java permits
More informationInf1-OOP. OOP Exam Review. Perdita Stevens, adapting earlier version by Ewan Klein. March 16, School of Informatics
Inf1-OOP OOP Exam Review Perdita Stevens, adapting earlier version by Ewan Klein School of Informatics March 16, 2015 Overview Overview of examinable material: Lectures Topics S&W sections Week 1 Compilation,
More informationJava How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationExercise 8 Parametric polymorphism November 18, 2016
Concepts of Object-Oriented Programming AS 2016 Exercise 8 Parametric polymorphism November 18, 2016 Task 1 Consider the following Scala classes: class A class B extends A class P1[+T] class P2[T
More informationDefault arguments, documentation
, documentation Comp Sci 1570 Introduction to C++ Outline 1 2 to functions A default parameter (also called an optional parameter or a default argument) is a function parameter that has a default value
More informationCONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17
List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code
More informationFundamentals of Programming Session 15
Fundamentals of Programming Session 15 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More information