Sunteți pe pagina 1din 4

9/2

Chapter 2: Data Design and Implementation Lecture 3 1) Data Abstraction a) Problem: write a C++ program to simulate a tic tac toe game. i) Understand the problem (1) Restate the problem (2) Inputs (a) Token X O (3) Outputs (a) Token X O (b) X wins (c) O wins (d) Ties ii) Design the program (1) Board (a) 2 dimensional array (b) 1 dimensional array (c) string[9] A. Separates the logical properties of a data type from its implementation i) Logical Properties (1) What are the possible values? (2) What operating will be needed? ii) Implementation (1) How can this be done in C++? (2) How can data types be used?

B. Date Type i) Set of values (domains) ii) Allowable operations on those values C. Views of Data i) Application, User or Client Level (1) A way of modeling real-life data in a specific context ii) Logical or Abstract Level (1) An abstract view of the data values (the domain) and the set of operations to manipulate them iii) Implementation Level (1) A specific representation of the structure to hold the data items, and the coding of the operations in a programming language (if the operations are not already provided by the language) D. Abstract Data Type (ADT) i) Abstract Data Type is a data type where properties (domain and operations) are specified independently of any particular implementation (p68) ii) For example (1) ADT Specificaton Example 1 (a) TYPE (i) TimeType (b) DOMAIN (i) Each value is a time in hours, minutes, and seconds (c) OPERATIONS (i) Set the time (ii) Print the time (iii)Increment by one second (iv) Compare 2 times for equality

(v) Determine if one time is less than another (2) ADT Specification Example 2 (a) TYPE (i) ComplexNumberType (b) DOMAIN (i) Each value is an ordered pair of real numbers (a, b) representing a+ bi (c) OPERATIONS (i) Initialize the complex number (ii) Write the complex number (iii)Add (iv) Subtract

(v) Multiply (vi) (vii) Divide Determine the absolute value of a complex number

E. General Information i) An abstract date type encapsulated ONE data type and its operation as a logical unit. ii) The instance of an abstract data type is called an object iii) Data abstraction hides the data definition and the operation details from the users (information hiding) 2) Encapsulation A. Why encapsulate data? i) Data encapsulation is the separation of the representation of data from applications that use data at a logical level; a programming language feature that enforces information hiding (p67) ii) The purpose of encapsulation is to keep the programs intellectually manageable

iii) Encapsulation has the ability to combine data, and operations on that data, in a single unit. In C++ this is a class. B. First: ADT implementation mans i) Choosing a specific data representation for the ADT using existing data types (built-in or programmer-defined), and ii) Writing functions for each ADT operation. C. Possible representation of TimeType i) 3 int variables ii) 3 strings iii) 3 element 1 dimensional array D. Possible representations of ComplexNumberType 3) Information Hiding A. Why hide information? i) Information hiding has the ability to hide the implementation from the user. ii) Remember the user should only know what the object does, not how it does it. iii) With many people working on a programming project, information hiding ensures that all individuals will use objects in exactly the same way. iv) An example of information hiding is the use of private and public definition in a class.

S-ar putea să vă placă și