1 Chapter 11- 2 Structured Types, Data Abstraction and Classes Dale/Weems.

Slides:



Advertisements
Similar presentations
Structure.
Advertisements

1 Classes and Data Abstraction Chapter What a Class ! ! Specification and implementation Private and public elements Declaring classes data and.
1 Object-Oriented Programming OOP. 2 Object-oriented programming is a new paradigm for program development in which the focus is on the data instead of.
1 Lecture 24 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
ADT Specification Example
1 Lecture 29 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long.
1 Lecture 25 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
A function (procedure) code to perform a task (carry out an algorithm) Return_type Func(parameters) ---- Func (arguments) --- Return value.
1 Abstract Data Type (ADT) a data type whose properties (domain and operations) are specified (what) independently of any particular implementation (how)
1 Class Constructors a class constructor is a member function whose purpose is to initialize the private data members of a class object the name of a constructor.
1 Review: Two Programming Paradigms Structural (Procedural) Object-Oriented PROGRAM PROGRAM FUNCTION OBJECT Operations Data OBJECT Operations Data OBJECT.
Data Structures 1- Course Syllabus. 2- Introduction about Data Structures.
More Storage Structures A Data Type Defined by You Characteristics of a variable of a specific ‘data type’ has specific values or range of values that.
1 Structured Types, Data Abstraction and Classes.
1 Basic Concepts of Object-Oriented Design. 2 What is this Object ? There is no real answer to the question, but we ’ ll call it a “ thinking cap ”. l.
Structured Data Types array array union union struct struct class class.
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
1 Chapter 10 Simple Data Types: Built-In and User- Defined.
SEN 909 OO Programming in C++ Final Exam Multiple choice, True/False and some minimal programming will be required.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
C++ Tutorial Hany Samuel and Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2006 by Douglas.
Chapter 10: Records (structs)
Cosc237/structures1 Structures aggregate data types record - single variable name for the whole collection composed of several variables - fields,BUT,
1 C++ Syntax and Semantics, and the Program Development Process.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems.
CPSC 252 Concrete Data Types Page 1 Overview of Concrete Data Types There are two kinds of data types: Simple (or atomic) – represents a single data item.
1 Chapter 14 Object-Oriented Software Development Dale/Weems.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 Chapter 10 Simple Data Types: Built-In and User- Defined.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems.
1 2 Data Design and Implementation Chapter 2 Data Design and Implementation.
3 ADT Unsorted List. List Definitions Linear relationship Each element except the first has a unique predecessor, and each element except the last has.
1 Data Structures and Algorithms Week 3 Data Abstraction: Part II Structured Types, and Classes.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
Classes Structured Programming 256 Chapter 8 Classes - Part I OOP & Class Object Terminology File Management.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Structures (aka records, structs) Textbook Chapter 11 sections:
1 Chapter 13-1 Applied Arrays: Lists and Strings Dale/Weems.
1 Structural Types, Data Abstractions and Classes.
1 Final Exam Tues 3/16/10 (2-3:50) (Same classroom) Old Textbook - Chapters 11-16, 18 Focus is on 15, 16 and 18 Final Exam Tues 3/16/10 (2-3:50) (Same.
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
1 Final Exam 20 Questions Final Exam 20 Questions Multiple choice and some minimal programming will be required.
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
1 Data Structures CSCI 132, Spring 2014 Lecture 2 Classes and Abstract Data Types Read Ch Read Style Guide (see course webpage)
1 Classes and Data Abstraction Chapter What a Class ! ! Specification and implementation Private and public elements Declaring classes data and.
1 Chapter 10 & 11 enum & Structured Types Dale/Weems.
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
1 Chapter 12 Classes and Abstraction. 2 Chapter 12 Topics Meaning of an Abstract Data Type Declaring and Using a class Data Type Using Separate Specification.
1 Structured Types, Data Abstraction and Classes.
Chapter 12 Classes and Abstraction
chapter 11 Structured Types, Data Abstraction, and Classes
Dale/Weems/Headington
C++ Data Types and Data Abstractions
Review: Two Programming Paradigms
Chapter Structured Types, Data Abstraction and Classes
C++ Data Types and Data Abstractions
Introduction to Structured Data Types and Classes
CS148 Introduction to Programming II
Classes and Data Abstraction
Introduction to Data Structure
Structures Structured Data types Data abstraction structs ---
Presentation transcript:

1 Chapter Structured Types, Data Abstraction and Classes Dale/Weems

2 Hierarchical Structures l The type of a struct member can be another struct type l This is called nested or hierarchical structures l Hierarchical structures are very useful when there is much detailed information in each record For example...

3 struct MachineRec Information about each machine in a shop contains: an idNumber, a written description, the purchase date, the cost, and a history (including failure rate, number of days down, and date of last service)

4 struct DateType { int month; // Assume int day;// Assume int year; // Assume }; struct StatisticsType { float failRate; DateTypelastServiced;// DateType is a struct type int downDays; }; struct MachineRec { int idNumber; string description; StatisticsType history; // StatisticsType is a struct DateType purchaseDate; float cost; }; MachineRec machine; 4

5 struct type variable machine 7000.idNumber.description. history.purchaseDate.cost.month.day.year 5719 “DRILLING…” failrate.lastServiced.downdays month.day.year machine.history.lastServiced.year has value 1999

6 Unions in C++ DEFINITION A union is a struct that holds only one of its members at a time during program execution. EXAMPLE union WeightType { long wtInOunces; int wtInPounds; Only one at a time float wtInTons; };

7 Using Unions union WeightType // Declares a union type { long wtInOunces; int wtInPounds; float wtInTons; }; WeightType weight; // Declares a union variable weight.wtInTons = 4.83; // Weight in tons is no longer needed // Reuse the memory space weight.wtInPounds = 35; 7

8 Abstraction l Abstraction is the separation of the essential qualities of an object from the details of how it works or is composed n Focuses on what, not how n Is necessary for managing large, complex software projects

9 Control Abstraction l Constrol abstraction separates the logical properties of an action from its implementation Search (list, item, length, where, found); l The function call depends on the function’s specification (description), not its implementation (algorithm)

10 Data Abstraction l Data abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIESIMPLEMENTATION What are the possible values?How can this be done in C++? What operations will be needed?How can data types be used?

11 Data Type set of values (domain) allowable operations on those values FOR EXAMPLE, data type int has domain operations +, -, *, /, %, >>, <<

12 Abstract Data Type (ADT) l An abstract data type is a data type whose properties (domain and operations) are specified (what) independently of any particular implementation (how) For example...

13 ADT Specification Example TYPE Time DOMAIN Each Time value is a time in hours, minutes, and seconds. OPERATIONS Set the time Print the time Increment by one second Compare 2 times for equality Determine if one time is “less than” another

14 Another ADT Specification TYPE ComplexNumber DOMAIN Each value is an ordered pair of real numbers (a, b) representing a + bi OPERATIONS Initialize the complex number Write the complex number Add Subtract Multiply Divide Determine the absolute value of a complex number

15 ADT Implementation l ADT implementation n Choose a specific data representation for the abstract data using data types that already exist (built-in or programmer-defined) n Write functions for each allowable operation

Several Possible Representations of ADT Time 3 int variables 3 strings 3-element int array Choice of representation depends on time, space, and algorithms needed to implement operations “10” “45” “27”

17 Some Possible Representations of ADT ComplexNumber struct with 2 float members 2-element float array real.imag

18 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long double

19 class Time Specification // Specification file (Time.h) class Time // Declares a class data type {// does not allocate memory public : // Five public function members void Set (int hours, int mins, int secs); void Increment (); void Write () const; bool Equal (Time otherTime) const; bool LessThan (Time otherTime) const; private : // Three private data members int hrs; int mins; int secs; }; 19

20 C++ classType l Facilitates re-use of C++ code for an ADT l Software that uses the class is called a client l Variables of the class type are called class objects or class instances l Client code uses class’s public member functions to manipulate class objects

21 Client Code Using Time #include “time.h” // Includes specification of the class using namespace std; int main () { Time currentTime; // Declares two objects of Time Time endTime; bool done = false; currentTime.Set (5, 30, 0); endTime.Set (18, 30, 0); while (! done) {... currentTime.Increment (); if (currentTime.Equal (endTime)) done = true; }; } 21

22 The End of Chapter 11 – Part 2