Data Abstraction: The Walls

Slides:



Advertisements
Similar presentations
Linear Lists – Array Representation
Advertisements

Lists Chapter 8 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 12 Separate Compilation and Namespaces. Abstract Data Type (ADT) ADT: A data type consisting of data and their behavior. The abstraction is that.
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
A Bag Implementation that Links Data Chapter 3 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Object Oriented Programming & Software Engineering.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Main Index Contents 11 Main Index Contents Model for a Queue Model for a Queue The Queue The Queue ADTQueue ADT (3 slides) Queue ADT Radix Sort Radix Sort.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Typical operations on data –Add data.
Chapter 3 Array-Based Implementations CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Data Abstraction: The Walls
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley CHAPTER 3 Data.
Object Oriented Data Structures
Bags Chapter 1 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
Introduction to STL and the vector container class CS342 Data Structures Based on Ford & Topp.
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
 A Collection class is a data type that is capable of holding a group of items.  In Java, Collection classes can be implemented as a class, along with.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Abstract Data Types and a review of C++ programming concepts CS 400/600 – Data Structures.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
1 Chapter 13-1 Applied Arrays: Lists and Strings Dale/Weems.
Bag Implementations that Use Arrays Chapter 2 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions.
Container Classes  A container class is a data type that is capable of holding a collection of items.  In C++, container classes can be implemented as.
1 Chapter 13-2 Applied Arrays: Lists and Strings Dale/Weems.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Array-Based Implementations Chapter 3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
1 Linked Lists Chapter 3. 2 Objectives You will be able to: Describe an abstract data type for lists. Understand and use an implementation of a List ADT.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 4 Ming Li Department of Computer.
1 Data Structures CSCI 132, Spring 2014 Lecture 2 Classes and Abstract Data Types Read Ch Read Style Guide (see course webpage)
1 C++ Classes and Data Structures Course link…..
1 Data Structures CSCI 132, Spring 2016 Notes_ 5 Stacks.
1 CS162: Introduction to Computer Science II Abstract Data Types.
DATA STRUCTURES 1st exam solution. Question 1(1/3) Suppose we have the ADT Bag which has the following operations: bool isEmpty(): tests whether Bag is.
Link-Based Implementations
Chapter Topics The Basics of a C++ Program Data Types
Data Abstraction: The Walls
Data Abstraction: The Walls
Chapter 1 Data Abstraction: The Walls
Homework 4 questions???.
CSC113: Computer Programming (Theory = 03, Lab = 01)
CSC113: Computer Programming (Theory = 03, Lab = 01)
A Bag Implementation that Links Data
A Bag Implementation that Links Data
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 4 Link Based Implementations
Chapter 3 Array-Based Implementations
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Name: Rubaisha Rajpoot
Adapted from Pearson Education, Inc.
Chapter 11 Generic Collections
Array-Based Implementations
Doubly Linked List Implementation
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Array-Based Implementations
Pointers & Dynamic Data Structures
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Bag Implementations that Use Arrays
Data Abstraction: The Walls
An Introduction to STL.
Recitation 2 CS0445 Data Structures
Copyright ©2012 by Pearson Education, Inc. All rights reserved
© 2016 Pearson Education, Ltd. All rights reserved.
Presentation transcript:

Data Abstraction: The Walls CS 302 Data Structures Data Abstraction: The Walls

Object-Oriented Concepts Encapsulation: Objects combine data and operations Inheritance: Classes inherit properties from other classes Polymorphism: Objects determine appropriate operations at execution

Figure 1-1 The task sort is a module separate from the MyProgram module

Specifications So, What is a specification? Basically an operational contract Documents use and limitations of a method Specifies data flow Does not specify HOW the module will perform its task Specifies pre- and post-conditions

Figure 1-2: Tasks communicate through a slit in the wall

Figure 1-3: A revised implementation communicates through the same slit in the wall

Figure 1-4: A dispenser of chilled water, crushed ice, and ice cubes

Figure 1-7: UML notation for the class Bag

Code Documentation Doxygen: doxygen.org Appendix I

/** @file BagInterface.h */ # ifndef _BAG_INTERFACE # define _BAG_INTERFACE # include < vector > template < class ItemType > class BagInterface { public: /** Gets the current number of entries in this bag. @return The integer number of entries currently in the bag. */ virtual int getCurrentSize () const = 0; /** Sees whether this bag is empty. @return True if the bag is empty, or false if not. */ virtual bool isEmpty () const = 0; /** Adds a new entry to this bag. @post If successful, newEntry is stored in the bag and the count of items in the bag has increased by 1. @param newEntry The object to be added as a new entry. @return True if addition was successful, or false if not. */ virtual bool add (const ItemType & newEntry) = 0; /** Removes one occurrence of a given entry from this bag, if possible. @post If successful, anEntry has been removed from the bag and the count of items in the bag has decreased by 1. @param anEntry The entry to be removed. @return True if removal was successful, or false if not. */ virtual bool remove (const ItemType & anEntry) = 0; /** Removes all entries from this bag. @post Bag contains no items, and the count of items is 0. */ virtual void clear () = 0; /** Counts the number of times a given entry appears in bag. @param anEntry The entry to be counted. @return The number of times anEntry appears in the bag. */ virtual int getFrequencyOf (const ItemType & anEntry) const = 0; /** Tests whether this bag contains a given entry. @param anEntry The entry to locate. @return True if bag contains anEntry, or false otherwise. */ virtual bool contains (const ItemType & anEntry) const = 0; /** Empties and then fills a given vector with all entries that are in this bag. @return A vector containing all the entries in the bag. */ virtual vector < ItemType > toVector () const = 0; } ; // end BagInterface

int main () { } ; // end main # include < iostream > // For cout and cin # include < string > // For string objects # include "Bag.h" // For ADT bag using namespace std; int main () { string clubs [] = {"Joker", "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}; // Create our bag to hold cards. Bag < string > grabBag; // Place six cards in the bag. grabBag.add (clubs [1]); grabBag.add (clubs [2]); grabBag.add (clubs [4]); grabBag.add (clubs [8]); grabBag.add (clubs [10]); grabBag.add (clubs [12]); // Get friends guess and check it. int guess = 0; while (!grabBag.isEmpty ()) { cout << "What is your guess?" << "(1 for Ace to 13 for King):"; cin >> guess; // Is card in the bag? if (grabBag.contains (clubs [guess])) // Good guess remove card from the bag. cout << "You get the card!\n"; grabBag.remove (clubs [guess]); } else cout << "Sorry, card was not in the bag.\n"; } // end if } // end while cout << "No more cards in the bag. Game over!\n"; return 0; } ; // end main

End of Chapter 1