Inheritance and Virtual Functions. Linked lists.
|
|
- Britney Scott
- 7 years ago
- Views:
Transcription
1 Inheritance and Virtual Functions. Linked lists. 26th CS427 Lecture 12.2, 11am, 22nd March 2012 CS427 Inheritance and Virtual Functions. Linked lists. 1/27
2 In today s class 1 Recall... Inheritance 2 Replacing members 3 virtual 4 Limitations of arrays 5 Linked lists 6 Example of a linked list function 7 Building the list addtoend 8 Further linked list operations 9 The End... CS427 Inheritance and Virtual Functions. Linked lists. 2/27
3 Recall... Inheritance Inheritance Given a class, construct from it a new class that has properties of the original class, plus some new ones. The original class is called the base class. The new one, is called the derived class. The derived class will inherit All the data members of the base class, though they can only be accessed directly if they are specified as protected by the base class (instead of private). The ordinary function members, but not constructors, destructors, or the assignment operator. The syntax for defining a derived class class Derived : public Base CS427 Inheritance and Virtual Functions. Linked lists. 3/27
4 Replacing members Suppose, for example, that a base class has a method void PrintData(void). It is possible to make a derived class that also contains a (new) method call void PrintData(void). The version of PrintData(void) from the derived class will superceed the one from the base class. However, the original one does not disappear, it can still be called, but you need to use the base class name and scope resolution operator. Note If the base and derived classes have functions with the same names, but different signatures, then the function is overloaded, not replaced. CS427 Inheritance and Virtual Functions. Linked lists. 4/27
5 Replacing members class Point { protected : i n t x ; public : Point ( i n t X=0) { x=x ; } ; i n t GetX ( void ) { return ( x ) ; } ; void SetX ( i n t X) { x=x ; } ; void PrintData ( void ) ; } ; void Point : : PrintData ( void ) { cout ( x ) n ; } 01Replacement.cpp link CS427 Inheritance and Virtual Functions. Linked lists. 5/27
6 Replacing members class TwoPoint : public P o i n t { private : i n t y ; public : TwoPoint ( i n t X=0, i n t Y=0) { x=x ; y=y ; } ; i n t GetY ( void ) { return ( y ) ; } ; void SetY ( i n t Y) { y=y ; } ; void PrintData ( void ) ; } ; void TwoPoint : : PrintData ( void ) { cout ( x, y ) n ; } CS427 Inheritance and Virtual Functions. Linked lists. 6/27
7 Replacing members i n t main ( void ) { Point b ; TwoPoint d ; b. SetX ( 1 2 ) ; cout b= ; b. PrintData ( ) ; d. SetX ( 1 ) ; d. SetY ( 2 ) ; cout nd= ; d. PrintData ( ) ; } cout C a l l i n g the Point version of P r i n t Data : ; cout d= ; d. Point : : PrintData ( ) ; return ( 0 ) ; CS427 Inheritance and Virtual Functions. Linked lists. 7/27
8 virtual There are other times when we need to take care which of two functions that have the same signature and belonging the base and derived class is called. In particular, consider the following code segment: Point d, b ; b = new Point ( 3 ) ; d = new TwoPoint ( 5, 6 ) ; Here b and d are both pointers to the type Point, but created using dynamically memory allocation. In particular, d in initialised as an instance of the TwoPoint class. But, if we call (*d).printdata() (or, equivalently, d->printdata() it is base::printdata() that is called. If we want Derived::PrintData() to be called, then in the definition of Point, we put virtual before the definition of PrintData(). This is shown in 02Virtual.cpp link CS427 Inheritance and Virtual Functions. Linked lists. 8/27
9 virtual As a more natural example of when a virtual function might be required, consider the following implementation for items stored in a library. Items in the library all have, at the least, a title and a call-number. The base class item includes private members string title and int CallNumber. There are methods that print the title and call number, and a method printrecord that does both. class item { protected : s t r i n g t i t l e ; i n t CallNumber ; public : item ( s t r i n g t =, i n t n=0) { t i t l e = t ; CallNumber=n ; } ; void s e t T i t l e ( s t r i n g t ) { t i t l e = t ; } ; void setcallnumber ( i n t n ) { CallNumber=n ; } ; void p r i n t T i t l e ( void ) { cout t i t l e ; } ; void printcallnumber ( void ) { cout CallNumber ; } ; void printrecord ( void ) ; } ; CS427 Inheritance and Virtual Functions. Linked lists. 9/27
10 virtual The code for the printrecord method is: void item : : printrecord ( void ) { cout t i t l e : ; p r i n t T i t l e ( ) ; cout ( c a l l number : ; printcallnumber ( ) ; cout ) endl ; } CS427 Inheritance and Virtual Functions. Linked lists. 10/27
11 virtual Next we have a derived class specifically for books. It has a different form of call number in this case, based on the Dewey Decimal system. Each book s call number is made up of two integers. The first represents the broad category (e.g., 005=Computer programming) and the second the specific subject (e.g., 100=Software Engineering). class Book : public i t e m { private : i n t Category ; i n t Subject ; public : Book ( s t r i n g t =, i n t c =0, i n t s =0) { t i t l e = t ; Category=c ; Subject=s ; } ; void setcallnumber ( i n t c, i n t s ) { Category=c ; Subject=s ; } ; void printcallnumber ( void ) ; } ; void Book : : printcallnumber ( void ) { cout s e t f i l l ( 0 ) setw ( 3 ) Category. Subject ; } CS427 Inheritance and Virtual Functions. Linked lists. 11/27
12 virtual So if we declare an object of type book, and call its method printrecord. But printrecord was inherited from the base class. That is, book::printrecord is the same as item::printrecord. So it will call item::printcallnumber. That is not what we intended. If we change the definition of item::printcallnumber in the base class to specify that it is virtual, then the binding that is done at compile time is changed, and even though printrecord is inherited from item, we ll find that book::printrecord will call book::printcallnumber. The full example is given in 03Library.cpp link CS427 Inheritance and Virtual Functions. Linked lists. 12/27
13 Limitations of arrays For many applications, such as your GradeBook project, it may seem natural to store the data is a dynamically sized arrays of objects. However, arrays are very rigid. For example, it is not clear how to add a new item to the middle of the list. delete an item allocate extra memory on the fly. To deal with these issues, we could use a linked list: an object that includes as one of its members a link to another object. These ideas featured in you Cs209 class. Now we ll review how they work in C There are many operations one would like to perform on a linked list: Output the items in the list Add a new item to the end of the list Add a new item to the middle of the list Delete item, etc. CS427 Inheritance and Virtual Functions. Linked lists. 13/27
14 Linked lists A linked list is a collection of nodes, each of which has Some data element, sometimes called Cargo, A link (i.e., a pointer) to the next node in the list. If a node is implemented as a class in C++, it might also need methods to get and set the next node on the list. Here is part of a very basic example which you can find in 04OneTwoThree.cpp link 04OneTwoThree.cpp 11 class Node { friend i n t Length ( Node head ) ; 13 private : i n t data ; 15 Node next ; public : 17 Node ( void ) { next=null ; } ; void setnext ( Node n ) { next=n ; } ; 19 Node getnext ( void ) { return ( next ) ; } ; void setdata ( i n t d ) { data=d ; } ; 21 i n t getdata ( void ) { return ( data ) ; } ; } ; CS427 Inheritance and Virtual Functions. Linked lists. 14/27
15 Linked lists Now use this class: i n t main ( void ) 26 { Node f i r s t, second, t h i r d ; 28 f i r s t. setdata ( 1 ) ; 30 f i r s t. setnext (&second ) ; second. setdata ( 2 ) ; 32 second. setnext (& t h i r d ) ; t h i r d. setdata ( 3 ) ; 34 cout Number of items i n l i s t : 36 Length (& f i r s t ) endl ; system ( pause ) ; CS427 Inheritance and Virtual Functions. Linked lists. 15/27
16 Example of a linked list function The Length() function takes a linked list and computes the number of elements in the list. Length() is a simple list function, but it demonstrates several concepts which will be used in later, more complex list functions i n t Length ( Node head ) { 45 Node c u r r e n t =head ; i n t count =0; 47 while ( c u r r e n t = NULL) 49 { count ++; 51 c u r r e n t = current >next ; } 53 return ( count ) ; } CS427 Inheritance and Virtual Functions. Linked lists. 16/27
17 Example of a linked list function There are two common features of linked lists demonstrated in Length() 1 Pass The List By Passing The Head Pointer The linked list is passed in to Length() via a single head pointer. The pointer is copied from the caller into the head variable local to Length(). 2 Iterate Over The List With A Local Pointer The code to iterate over all the elements is very typical: while (current = NULL) { //... current = current->next; } CS427 Inheritance and Virtual Functions. Linked lists. 17/27
18 Example of a linked list function The key ideas of this example are 1 The local pointer, current in this case, starts by pointing to the same node as the head pointer with current = head; So when the function exits, the value of head there has not changed. 2 The while loop tests for the end of the list with (current = NULL) This catches the empty list case 3 At the end of the while loop we have the line current = current->next; This advances the local pointer to the next node in the list. When there are no more links, this sets the pointer to NULL. CS427 Inheritance and Virtual Functions. Linked lists. 18/27
19 Building the list Now we ll develop some functions to add an items to a list. The full code is given in In 05addToList.cpp link The new functions are printlist addtostart and addtoend First, the following lines gets added to the class definition of Node 05addtoList.cpp friend i n t Length ( Node head ) ; 13 friend void p r i n t L i s t ( Node head ) ; friend void addtostart ( Node &head, i n t Data ) ; 15 friend void addtoend ( Node &head, i n t Data ) ; Note that pointer to the head of the list is passed by reference to the addtostart and addtoend functions. This is because they have to change the value of head in the calling function. CS427 Inheritance and Virtual Functions. Linked lists. 19/27
20 Building the list The printlist function is the simplest: 66 void p r i n t L i s t ( Node head ) { 68 Node c u r r e n t =head ; i n t count =0; 70 while ( c u r r e n t = NULL) 72 { cout Link count contains 74 current >data endl ; c u r r e n t = current >next ; 76 count ++; } 78 } CS427 Inheritance and Virtual Functions. Linked lists. 20/27
21 Building the list Next we ll write the addtostart function: it creates a new link at the head of the list (like a stack). It performs four operations: 1 Allocate memory for the new link, using new 2 Store the new data in the new link 3 Set the.next pointer of the new node to point to the current head of the list. 4 Change the old head pointer so that it points to the new head of the list. This last part is importance: because the function must change to value of a variable belonging to the calling function, we have to pass the address by reference. CS427 Inheritance and Virtual Functions. Linked lists. 21/27
22 Building the list The addtostart functions is defined as / 81 add a l i n k at the s t a r t of the l i s t. Since the head of the l i s t i s being changed 83 i t must be passed by reference / 85 void addtostart ( Node &headref, i n t NewData ) { 87 Node newnode = new Node ; 89 newnode >setdata ( NewData ) ; newnode >setnext ( headref ) ; 91 headref=newnode ; 93 } Note: we could write a much shorter version of this function if we had a more sophisticated constructor. CS427 Inheritance and Virtual Functions. Linked lists. 22/27
23 Building the list addtoend Adding a new link to the top of the list is the easiest way of adding a link. However, more often we often want to add something to the end (tail) of the list. Generally this should not change the value of the head of the list. But, because we have to allow for the case of the list being empty, we have to pass by reference. CS427 Inheritance and Virtual Functions. Linked lists. 23/27
24 Building the list addtoend 96 / / Adding to the end of the list. If the list / / is empty then the head gets chagned. So 98 / / we much pass by reference void addtoend ( Node &headref, 100 i n t NewData ) { 102 Node newnode = new Node ; newnode >setdata ( NewData ) ; 104 newnode >setnext (NULL ) ; 106 i f ( headref==null) / / if list is empty headref=newnode ; 108 else / / Find the end of the list { 110 Node c u r r e n t =headref ; while ( current >next = NULL) 112 c u r r e n t = current >next ; 114 current >next=newnode ; } 116 } Adding a new link to the top of the list is the easiest way of adding a link. However, more often we often want to add something to the end (tail) of the list. Usually this should not change the value of the head of the list. But, because we have to allow for the case of the list being empty, we have to pass by reference. CS427 Inheritance and Virtual Functions. Linked lists. 24/27
25 Further linked list operations There are many other operations that one could do on linked lists, other implementation issues, and variants. These include Using template to allow generic data types for the cargo. See 06LListTempate.cpp link for an example. Functions to copy lists. insert a link in the middle of the list, delete a link from a list delete all items in a list, and deallocate the associated memory implement doubly-linked lists; here each link has a reference to the previous link as well as the next. CS427 Inheritance and Virtual Functions. Linked lists. 25/27
26 The End... The final paper has 6 questions. You should attempt 4. 3 Questions on Software Engineering. Overview, and so could over any part of the course. It will, however, include the Waterfall model of the software lifecycle. Requirements; Specification; Logic and Predicate Calculus. Design (including Pseudocode, Finite State Machines, Data Flow Diagrams, ADTs, OOD), the coding and testing phases. 3 questions on C++ programming. Any topic covered in class or labs may be asked including: basic I/O and file I/O; functions: including overloading, default parameter lists, pass-by-reference, classes, including constructors and destructors; private, public, protected; operator overloading and friend functions. static variables. templates inheritance, including virtual functions (but not) Linked Lists Full marks for FOUR questions. There is no sample paper, but many of the Revision Exercises are of exam standard. CS427 Inheritance and Virtual Functions. Linked lists. 26/27
27 The End... The final exam will be worth 70%. The remaining 30% will come from In-class C test ( 5) lab programming assignments. Software engineering assignments the Project. For details, see web-site. The end CS427 Inheritance and Virtual Functions. Linked lists. 27/27
Data Structures Using C++ 2E. Chapter 5 Linked Lists
Data Structures Using C++ 2E Chapter 5 Linked Lists Test #1 Next Thursday During Class Cover through (near?) end of Chapter 5 Objectives Learn about linked lists Become aware of the basic properties of
More informationLinked List as an ADT (cont d.)
Linked List as an ADT (cont d.) Default constructor Initializes list to an empty state Destroy the list Deallocates memory occupied by each node Initialize the list Reinitializes list to an empty state
More informationGlossary of Object Oriented Terms
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
More informationStorage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
More informationObject Oriented Software Design II
Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February
More informationClasses and Pointers: Some Peculiarities (cont d.)
Classes and Pointers: Some Peculiarities (cont d.) Assignment operator Built-in assignment operators for classes with pointer member variables may lead to shallow copying of data FIGURE 3-22 Objects objectone
More informationPROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON
PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London
More informationC++FA 5.1 PRACTICE MID-TERM EXAM
C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer
More informationPART-A Questions. 2. How does an enumerated statement differ from a typedef statement?
1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members
More information13 Classes & Objects with Constructors/Destructors
13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.
More informationC++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
More informationThe C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
More informationData Structures Using C++ 2E. Chapter 5 Linked Lists
Data Structures Using C++ 2E Chapter 5 Linked Lists Doubly Linked Lists Traversed in either direction Typical operations Initialize the list Destroy the list Determine if list empty Search list for a given
More informationCmpSci 187: Programming with Data Structures Spring 2015
CmpSci 187: Programming with Data Structures Spring 2015 Lecture #12 John Ridgway March 10, 2015 1 Implementations of Queues 1.1 Linked Queues A Linked Queue Implementing a queue with a linked list is
More informationCS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator=
CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator= We already know that the compiler will supply a default (zero-argument) constructor if the programmer does not specify one.
More informationMultichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is
Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations
More informationMAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) -----------------------------------------
=============================================================================================================================== DATA STRUCTURE PSEUDO-CODE EXAMPLES (c) Mubashir N. Mir - www.mubashirnabi.com
More informationALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)
ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology) Subject Description: This subject deals with discrete structures like set theory, mathematical
More informationBoolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)
Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the
More informationIS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction
IS0020 Program Design and Software Tools Midterm, Feb 24, 2004 Name: Instruction There are two parts in this test. The first part contains 50 questions worth 80 points. The second part constitutes 20 points
More informationCourse: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1
Definition Course: Programming II - Abstract Data Types The ADT Stack The ADT Stack is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit insertions
More informationLecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists
Lecture 11 Doubly Linked Lists & Array of Linked Lists In this lecture Doubly linked lists Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for a Sparse
More informationBSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering
BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security & BSc. (Hons.) Software Engineering Cohort: BIS/05/FT BCNS/05/FT BSE/05/FT Examinations for 2005-2006 / Semester
More informationAn Incomplete C++ Primer. University of Wyoming MA 5310
An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages
More informationEl Dorado Union High School District Educational Services
El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.
More informationCpt S 223. School of EECS, WSU
Abstract Data Types 1 Topics Abstract Data Types (ADTs) Some basic ADTs: Lists Stacks Queues 2 Primitive Data Type vs. Abstract Data Types Primitive DT: ADT: programmer progra ammer Interface (API) e.g.,
More informationKITES TECHNOLOGY COURSE MODULE (C, C++, DS)
KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL
More informationCpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing
CpSc212 Goddard Notes Chapter 6 Yet More on Classes We discuss the problems of comparing, copying, passing, outputting, and destructing objects. 6.1 Object Storage, Allocation and Destructors Some objects
More informationWORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER
WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER Course Outline (2015) Basic Programming With Procedural & Object Oriented Concepts (C, C++) Training Office# Road: 11, House: 1 A, Nikunja 2, Khilkhet,
More informationPolymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism
Polymorphism Problems with switch statement Programmer may forget to test all possible cases in a switch. Tracking this down can be time consuming and error prone Solution - use virtual functions (polymorphism)
More informationSources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
More informationCourse: Programming II - Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1
Definition Course: Programming II - Abstract Data Types The ADT Queue The ADT Queue is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit addition
More informationCOMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.
COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms 1 Activation Records activation declaration location Recall that an activation
More informationADVANCED SCHOOL OF SYSTEMS AND DATA STUDIES (ASSDAS) PROGRAM: CTech in Computer Science
ADVANCED SCHOOL OF SYSTEMS AND DATA STUDIES (ASSDAS) PROGRAM: CTech in Computer Science Program Schedule CTech Computer Science Credits CS101 Computer Science I 3 MATH100 Foundations of Mathematics and
More informationCurriculum Map. Discipline: Computer Science Course: C++
Curriculum Map Discipline: Computer Science Course: C++ August/September: How can computer programs make problem solving easier and more efficient? In what order does a computer execute the lines of code
More informationA binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:
Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)
More informationOpenCL Static C++ Kernel Language Extension
OpenCL Static C++ Kernel Language Extension Document Revision: 04 Advanced Micro Devices Authors: Ofer Rosenberg, Benedict R. Gaster, Bixia Zheng, Irina Lipov December 15, 2011 Contents 1 Overview... 3
More informationShort Notes on Dynamic Memory Allocation, Pointer and Data Structure
Short Notes on Dynamic Memory Allocation, Pointer and Data Structure 1 Dynamic Memory Allocation in C/C++ Motivation /* a[100] vs. *b or *c */ Func(int array_size) double k, a[100], *b, *c; b = (double
More informationLecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c
Lecture 3 Data structures arrays structs C strings: array of chars Arrays as parameters to functions Multiple subscripted arrays Structs as parameters to functions Default arguments Inline functions Redirection
More informationIntroduction to Programming System Design. CSCI 455x (4 Units)
Introduction to Programming System Design CSCI 455x (4 Units) Description This course covers programming in Java and C++. Topics include review of basic programming concepts such as control structures,
More informationSoftware Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009
Software Engineering Concepts: Testing Simple Class Example continued Pointers & Dynamic Allocation CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009 Glenn G. Chappell Department
More informationJava (12 Weeks) Introduction to Java Programming Language
Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short
More information7.1 Our Current Model
Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.
More informationCS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team
CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A
More informationObject Oriented Software Design II
Object Oriented Software Design II C++ intro Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 26, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 26,
More informationCS107L Handout 04 Autumn 2007 October 19, 2007 Custom STL-Like Containers and Iterators
CS107L Handout 04 Autumn 2007 October 19, 2007 Custom STL-Like Containers and Iterators This handout is designed to provide a better understanding of how one should write template code and architect iterators
More informationStacks. Linear data structures
Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations
More informationSyllabus Introduction to C++ Programming and Numerical Analysis Spring 2016
Syllabus Introduction to C++ Programming and Numerical Analysis Spring 2016 lead instructor: office: web: class time: Professor Johan Walden F655 walden@haas.berkeley.edu http://www.haas.berkeley.edu/faculty/walden.html
More informationLinked Lists Linked Lists, Queues, and Stacks
Linked Lists Linked Lists, Queues, and Stacks CSE 10: Introduction to C Programming Fall 200 Dynamic data structure Size is not fixed at compile time Each element of a linked list: holds a value points
More informationData Structures and Algorithms Lists
Data Structures and Algorithms Lists Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/19 5-0: Abstract Data Types An
More informationC++ Programming Language
C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract
More informationLecture 12 Doubly Linked Lists (with Recursion)
Lecture 12 Doubly Linked Lists (with Recursion) In this lecture Introduction to Doubly linked lists What is recursion? Designing a node of a DLL Recursion and Linked Lists o Finding a node in a LL (recursively)
More informationClasses and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:
In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our
More informationC++FA 3.1 OPTIMIZING C++
C++FA 3.1 OPTIMIZING C++ Ben Van Vliet Measuring Performance Performance can be measured and judged in different ways execution time, memory usage, error count, ease of use and trade offs usually have
More informationLab Experience 17. Programming Language Translation
Lab Experience 17 Programming Language Translation Objectives Gain insight into the translation process for converting one virtual machine to another See the process by which an assembler translates assembly
More informationCourse MS10975A Introduction to Programming. Length: 5 Days
3 Riverchase Office Plaza Hoover, Alabama 35244 Phone: 205.989.4944 Fax: 855.317.2187 E-Mail: rwhitney@discoveritt.com Web: www.discoveritt.com Course MS10975A Introduction to Programming Length: 5 Days
More informationLINKED DATA STRUCTURES
LINKED DATA STRUCTURES 1 Linked Lists A linked list is a structure in which objects refer to the same kind of object, and where: the objects, called nodes, are linked in a linear sequence. we keep a reference
More informationBasics of I/O Streams and File I/O
Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading
More informationUnordered Linked Lists
Unordered Linked Lists Derive class unorderedlinkedlist from the abstract class linkedlisttype Implement the operations search, insertfirst, insertlast, deletenode See code on page 292 Defines an unordered
More informationJava Application Developer Certificate Program Competencies
Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle
More informationLinked Lists, Stacks, Queues, Deques. It s time for a chainge!
Linked Lists, Stacks, Queues, Deques It s time for a chainge! Learning Goals After this unit, you should be able to... Differentiate an abstraction from an implementation. Define and give examples of problems
More informationStack Allocation. Run-Time Data Structures. Static Structures
Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,
More informationIntegrating the C++ Standard Template Library Into the Undergraduate Computer Science Curriculum
Integrating the C++ Standard Template Library Into the Undergraduate Computer Science Curriculum James P. Kelsh James.Kelsh@cmich.edu Roger Y. Lee lee@cps.cmich.edu Department of Computer Science Central
More informationAn Internet Course in Software Development with C++ for Engineering Students
An Internet Course in Software Development with C++ for Engineering Students Yosef Gavriel, Robert Broadwater Department of Electrical and Computer Engineering Virginia Tech Session 3232 Abstract This
More informationCEC225 COURSE COMPACT
CEC225 COURSE COMPACT Course GEC 225 Applied Computer Programming II(2 Units) Compulsory Course Duration Two hours per week for 15 weeks (30 hours) Lecturer Data Name of the lecturer: Dr. Oyelami Olufemi
More informationlanguage 1 (source) compiler language 2 (target) Figure 1: Compiling a program
CS 2112 Lecture 27 Interpreters, compilers, and the Java Virtual Machine 1 May 2012 Lecturer: Andrew Myers 1 Interpreters vs. compilers There are two strategies for obtaining runnable code from a program
More informationIntroduction to data structures
Notes 2: Introduction to data structures 2.1 Recursion 2.1.1 Recursive functions Recursion is a central concept in computation in which the solution of a problem depends on the solution of smaller copies
More informationwww.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk
CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling
More informationYou are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:
Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from
More informationData Types. Abstract Data Types. ADTs as Design Tool. Abstract Data Types. Integer ADT. Principle of Abstraction
bstract ata Types Previous lectures: algorithms and their efficiency analysis. oming lectures: data structures In this lecture: bstract data types Ts as a design tool Examples: integer T, List T ata Types
More informationJ a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
More informationQuestions 1 through 25 are worth 2 points each. Choose one best answer for each.
Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in
More informationAnalysis of a Search Algorithm
CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,
More informationNode-Based Structures Linked Lists: Implementation
Linked Lists: Implementation CS 311 Data Structures and Algorithms Lecture Slides Monday, March 30, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org
More informationADTs,, Arrays, Linked Lists
1 ADTs,, Arrays, Linked Lists Outline and Required Reading: ADTs ( 2.1.2) Arrays ( 1.5) Linked Lists ( 4.3.1, 4.3.2) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic Abstract Data Type (ADT) 2 abstract
More informationLinked List Problems
Linked List Problems By Nick Parlante Copyright 1998-99, Nick Parlante Abstract This document presents 18 linked list problems covering a wide range of difficulty. Most obviously, these problems are useful
More informationCS107L Handout 02 Autumn 2007 October 5, 2007 Copy Constructor and operator=
CS107L Handout 02 Autumn 2007 October 5, 2007 Copy Constructor and operator= Much of the surrounding prose written by Andy Maag, CS193D instructor from years ago. The compiler will supply a default (zero-argument)
More informationThe ADT Binary Search Tree
The ADT Binary Search Tree The Binary Search Tree is a particular type of binary tree that enables easy searching for specific items. Definition The ADT Binary Search Tree is a binary tree which has an
More informationData Structures, Practice Homework 2, with Solutions (not to be handed in)
Data Structures, Practice Homework 2, with Solutions (not to be handed in) 1. Carrano, 4th edition, Chapter 7, Exercise 4. Consider a function int Queue::getNumberOfElements() const that returns the number
More informationEfficient Batch Scheduling Procedures for Shared HPC Resources
Efficient Batch Scheduling Procedures for Shared HPC Resources Fountanas Angelos 35354s05-38g August 22, 2008 MSc in High Performance Computing The University of Edinburgh Year of Presentation: 2008 Abstract
More information1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++
Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The
More informationIt has a parameter list Account(String n, double b) in the creation of an instance of this class.
Lecture 10 Private Variables Let us start with some code for a class: String name; double balance; // end Account // end class Account The class we are building here will be a template for an account at
More information10CS35: Data Structures Using C
CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a
More information3 Pillars of Object-oriented Programming. Industrial Programming Systems Programming & Scripting. Extending the Example.
Industrial Programming Systems Programming & Scripting Lecture 12: C# Revision 3 Pillars of Object-oriented Programming Encapsulation: each class should be selfcontained to localise changes. Realised through
More informationMoving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
More informationName: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
More informationCollections and iterators
Objects First With Java A Practical Introduction Using BlueJ Grouping objects Collections and iterators 2.0 Concepts covered so far Abstraction Modularization Classes define types Class and object diagrams
More informationProblem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class
CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class This homework is to be done individually. You may, of course, ask your fellow classmates for help if you have trouble editing files,
More informationMasters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013
Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper
More informationCommon Data Structures
Data Structures 1 Common Data Structures Arrays (single and multiple dimensional) Linked Lists Stacks Queues Trees Graphs You should already be familiar with arrays, so they will not be discussed. Trees
More informationLab 2: Swat ATM (Machine (Machine))
Lab 2: Swat ATM (Machine (Machine)) Due: February 19th at 11:59pm Overview The goal of this lab is to continue your familiarization with the C++ programming with Classes, as well as preview some data structures.
More informationChapter 5 Functions. Introducing Functions
Chapter 5 Functions 1 Introducing Functions A function is a collection of statements that are grouped together to perform an operation Define a function Invoke a funciton return value type method name
More informationC++ Overloading, Constructors, Assignment operator
C++ Overloading, Constructors, Assignment operator 1 Overloading Before looking at the initialization of objects in C++ with constructors, we need to understand what function overloading is In C, two functions
More informationCh 7-1. Object-Oriented Programming and Classes
2014-1 Ch 7-1. Object-Oriented Programming and Classes May 10, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497;
More informationDebugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go
Debugging ESE112 Java Programming: API, Psuedo-Code, Scope It is highly unlikely that you will write code that will work on the first go Bugs or errors Syntax Fixable if you learn to read compiler error
More information17. Friendship and Inheritance
- 117 - Object Oriented Programming: 17. Friendship and Inheritance Friend functions In principle, private and protected members of a class cannot be accessed from outside the same class in which they
More informationWhat is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...
What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control
More informationJava Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
More informationComputer Programming C++ Classes and Objects 15 th Lecture
Computer Programming C++ Classes and Objects 15 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2013 Eom, Hyeonsang All Rights Reserved Outline
More informationBCS2B02: OOP Concepts and Data Structures Using C++
SECOND SEMESTER BCS2B02: OOP Concepts and Data Structures Using C++ Course Number: 10 Contact Hours per Week: 4 (2T + 2P) Number of Credits: 2 Number of Contact Hours: 30 Hrs. Course Evaluation: Internal
More information