Abstract Data Types. Lecture 23 Section 7.1. Robb T. Koether. Hampden-Sydney College. Wed, Oct 24, 2012

Similar documents
Binary Tree Implementation

The Class Construct Part 2

Binary Tree Implementation

The Class Construct Part 1

Stacks and their Applications

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

The Critical-Path Algorithm

Minimal Spanning Trees

Sampling Distribution Examples Sections 15.4, 15.5

Implementing Linked Lists

Density Curves Sections

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

Rotations and Translations

Scope and Parameter Passing

The Decreasing-Time Algorithm

Street-Routing Problems

Friends and Unary Operators

Solving Recursive Sequences by Iteration

The Graphics Pipeline

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

The string Class. Lecture 21 Sections 2.9, 3.9, Robb T. Koether. Wed, Oct 17, Hampden-Sydney College

Scope and Parameter Passing

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

Binary Tree Applications

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 26, 2014

Boxplots. Lecture 17 Section Robb T. Koether. Hampden-Sydney College. Wed, Feb 10, 2010

Linked Lists. Lecture 16 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 22, 2017

The Model Stack. Lecture 8. Robb T. Koether. Hampden-Sydney College. Wed, Sep 6, 2017

Boolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

The Projection Matrix

Introduction to Classes

Recursive Descent Parsers

The Projection Matrix

Scheduling and Digraphs

The Graphics Pipeline

The Pairwise-Comparison Method

Inheritance: The Fundamental Functions

The Traveling Salesman Problem Brute Force Method

Building the Abstract Syntax Trees

List Iterator Implementation

XPath Lecture 34. Robb T. Koether. Hampden-Sydney College. Wed, Apr 11, 2012

List Iterators. Lecture 27 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

Function Usage. Lecture 15 Sections 6.3, 6.4. Robb T. Koether. Hampden-Sydney College. Mon, Oct 1, 2018

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

Mipmaps. Lecture 35. Robb T. Koether. Hampden-Sydney College. Wed, Nov 18, 2015

The Mesh Class. Lecture 26. Robb T. Koether. Wed, Oct 28, Hampden-Sydney College

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

LR Parsing - Conflicts

The Constructors. Lecture 7 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 1, 2017

List Iterators. Lecture 34 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 24, 2013

Recursive Linked Lists

XPath. Lecture 36. Robb T. Koether. Wed, Apr 16, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, / 28

The Coefficient of Determination

Displaying Distributions - Quantitative Variables

The Plurality-with-Elimination Method

Recursion. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 17, 2018

The Traveling Salesman Problem Nearest-Neighbor Algorithm

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Fri, Feb 16, 2018

The CYK Parsing Algorithm

Magnification and Minification

Ambient and Diffuse Light

Chapter 13: Introduction to Classes Procedural and Object-Oriented Programming

PHP Queries and HTML Forms Lecture 23

XML Attributes. Lecture 33. Robb T. Koether. Hampden-Sydney College. Wed, Apr 25, 2018

Inheritance: The Fundamental Functions

Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

The Normal Distribution

Dynamic Allocation of Memory

Dynamic Allocation of Memory

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Mon, Feb 22, 2016

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

The Mesh Class. Lecture 23. Robb T. Koether. Hampden-Sydney College. Wed, Oct 18, 2017

Total Orders. Lecture 41 Section 8.5. Robb T. Koether. Hampden-Sydney College. Mon, Apr 8, 2013

Basic CSS Lecture 17

This page intentionally left blank

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Mon, Jan 20, 2014

Specular Reflection. Lecture 19. Robb T. Koether. Hampden-Sydney College. Wed, Oct 4, 2017

Function Definition Syntax Tree

Aggregation. Lecture 7 Section Robb T. Koether. Hampden-Sydney College. Wed, Jan 29, 2014

Introduction to Databases

Recognition of Tokens

Webpage Navigation. Lecture 27. Robb T. Koether. Hampden-Sydney College. Mon, Apr 2, 2018

The Traveling Salesman Problem Cheapest-Link Algorithm

Introduction to Compiler Design

Programming Languages

Programming Languages

Form Validation. Lecture 25. Robb T. Koether. Hampden-Sydney College. Wed, Mar 23, 2018

The Constructors. Lecture 6 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 26, 2018

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

Nondeterministic Programming in C++

DTDs and XML Attributes

XQuery FLOWR Expressions Lecture 35

Triggers. Lecture 14. Robb T. Koether. Hampden-Sydney College. Wed, Feb 14, 2018

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

The Standard Template Library Classes

jquery Lecture 34 Robb T. Koether Wed, Apr 10, 2013 Hampden-Sydney College Robb T. Koether (Hampden-Sydney College) jquery Wed, Apr 10, / 29

Integer Overflow. Lecture 8 Section 2.5. Robb T. Koether. Hampden-Sydney College. Mon, Jan 27, 2014

Recursion. Lecture 26 Sections , Robb T. Koether. Hampden-Sydney College. Mon, Apr 6, 2015

Shading Triangles. Lecture 37. Robb T. Koether. Hampden-Sydney College. Mon, Nov 30, 2015

The View Frustum. Lecture 9 Sections 2.6, 5.1, 5.2. Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2011

Transcription:

Abstract Data Types Lecture 23 Section 7.1 Robb T. Koether Hampden-Sydney College Wed, Oct 24, 2012 Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 1 / 19

1 Abstract Data Types 2 The Rectangle Class The Member Functions The Data Members 3 Assignment Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 2 / 19

Outline 1 Abstract Data Types 2 The Rectangle Class The Member Functions The Data Members 3 Assignment Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 3 / 19

Abstract Data Types An abstract data type (ADT) is a data type for which only its interface is described. The ADT is described through the prototypes of its public member functions. The ADT does not include the implementation details. The client programmer does not need to concern himself with the implementation details. Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 4 / 19

Example of an ADT Consider a Rectangle class. The client programmer is concerned only with manipulating rectangles. He is not concerned with how they are represented internally. However, it is important that the results of his manipulations conform to his expectations, based on his abstract notion of a rectangle. Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 5 / 19

Outline 1 Abstract Data Types 2 The Rectangle Class The Member Functions The Data Members 3 Assignment Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 6 / 19

Outline 1 Abstract Data Types 2 The Rectangle Class The Member Functions The Data Members 3 Assignment Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 7 / 19

A Rectangle Class The client uses only the public member functions. Create a rectangle. Destroy a rectangle. Copy a rectangle. Draw a rectangle. Move a rectangle to a new location. Change the length of a rectangle. Find the area of a rectangle. And so on. Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 8 / 19

Rectangle Interface Rectangle Constructors // Constructors Rectangle(); Rectangle(const Rectangle& r); Rectangle(double len, double wid); Rectangle(double len, double wid, const Point& cen); The above is a possible interface for the Rectangle class. The class continues on the following slides. Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 9 / 19

Rectangle Interface Rectangle Inspectors and Mutators // Inspectors double getlength() const; double getwidth() const; Point getcenter() const; // Mutators void setlength(double len); void setwidth(double wid); void setcenter(const Point& cen); Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 10 / 19

Rectangle Interface Rectangle Facilitators // Facilitators void input(istream& in); void output(ostream& out) const; // Operators istream& operator>>(istream& in, Rectangle& r); ostream& operator<<(ostream& out, const Rectangle& r); Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 11 / 19

Rectangle Interface Other Rectangle Functions // Other member functions void draw(ostream& out) const; double perimeter() const; double area() const; Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 12 / 19

Outline 1 Abstract Data Types 2 The Rectangle Class The Member Functions The Data Members 3 Assignment Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 13 / 19

Rectangle Class Implementation Rectangle Data Members // Data members private: double left; // Left x double right; // Right x double top; // Top y double bottom; // Bottom y The implementation of the Rectangle class refers to the choice of data members and how they are used to implement the member functions. The above is a possible implementation. Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 14 / 19

Rectangle Class Implementation Rectangle Data Members // Data members private: double left; double bottom; double length; double width; // Left x // Bottom y // Length // Width Another possible implementation is the above. Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 15 / 19

Rectangle Class Implementation Rectangle Data Members // Data members private: Point bottomleft; Point topright; // Bottom left corner // Top right corner Yet another possible implementation. Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 16 / 19

Rectangle Class Implementation The client would not care which implementation was used because he would not be able to tell the difference. Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 17 / 19

Outline 1 Abstract Data Types 2 The Rectangle Class The Member Functions The Data Members 3 Assignment Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 18 / 19

Assignment Assignment Read Section 7.1. Robb T. Koether (Hampden-Sydney College) Abstract Data Types Wed, Oct 24, 2012 19 / 19