Data Abstraction and Structures Using C - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Data Abstraction and Structures Using C

Description:

A data type whose properties (domain and operations) are specified independently ... is used between the variable name and the member identifier to access individual ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 17
Provided by: sylvi160
Category:
Tags: abstraction | data | do | domain | for | have | name | pay | structures | to | using | why

less

Transcript and Presenter's Notes

Title: Data Abstraction and Structures Using C


1
Data Abstraction and Structures Using
C Headington and Riley Chapter 5 C Records
(structs) Slides by Sylvia Sorkin, Community
College of Baltimore County - Essex
2
Data Abstraction
  • Separation of a data types logical properties
    from its implementation.

LOGICAL PROPERTIES IMPLEMENTATION
What are the possible values? How can
this be done in C? What operations will be
needed? How can data types be used?
3
Abstract Data Type (ADT)
  • A data type whose properties (domain and
    operations) are specified independently of any
    particular implementation.

4
Data from 3 different levels
  • Application (or user) level modeling real-life
    data in a specific context. WHY
  • Logical (or ADT) level abstract view of the
    domain and operations. WHAT
  • Implementation level specific representation of
    the structure to hold the data items, and the
    coding for operations. HOW

5
Viewing a library from 3 different levels
  • Application (or user) level Library of Congress,
    or Baltimore County Public Library.
  • Logical (or ADT) level domain is a collection of
    books operations include check book out, check
    book in, pay fine, reserve a book.
  • Implementation level representation of the
    structure to hold the books, and the coding for
    operations.

6
Structured Data Type
  • A structured data type (or data structure) is a
    type which
  • stores a collection of individual data components
    under one variable name,
  • has rules that determine how the individual data
    components can be accessed.

7
C Built-In Data Types
Simple
Structured
Integral
Floating
array struct union class
char short int long enum
float double long double
8
Records
  • A record is a linear, direct-access data
    structure with heterogeneous components called
    members or fields. For example . . .

9
C structs
  • C defines a struct to be a class whose members
    are all, by default, public.
  • All operations that apply to C classes also
    apply to structs.

10
struct CarType
  • struct CarType
  • int year
  • char maker10
  • float price
  • CarType thisCar //CarType variables
  • CarType myCar

11
Accessing struct members
  • The member selection operator (period . ) is used
    between the variable name and the member
    identifier to access individual members of a
    record (struct or class) type variable.
  • EXAMPLES
  • myCar.year
  • thisCar.maker4

12
Aggregate struct operations
  • Operations valid on an entire struct type
    variable
  • assignment to another struct variable of
    same type,
  • pass as a parameter to a function
  • (either by value or by reference),
  • return as the value of a function.

13
Pass-by-value
sends a copy of the contents of the actual
parameter
SO, the actual parameter cannot be changed by
the function.
13
14
Pass-by-reference
can change value of actual parameter
14
15
Using struct type Reference Parameter to change
a member
  • void AdjustForInflation(CarType car, float
    perCent)
  • // Increases price by the amount specified in
    perCent
  • car.price car.price perCent car.price
  • SAMPLE CALL
  • AdjustForInflation(myCar, 0.03)

16
Using struct type Value Parameter to examine a
member
  • Boolean LateModel(CarType car, int date)
  • // Returns true if the cars model year is later
    than or
  • // equal to date returns false otherwise.
  • return ( car.year gt date )
  • SAMPLE CALL
  • if ( LateModel(myCar, 1995) )
  • cout ltlt myCar.price ltlt endl
Write a Comment
User Comments (0)
About PowerShow.com