Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Structures and ADTs

Similar presentations


Presentation on theme: "Data Structures and ADTs"— Presentation transcript:

1 Data Structures and ADTs
Chapter 3

2 C++ Data Types Fundamental (or simple or scalar): Structured:
Data objects are single objects int, double, char, bool, complex, the related types (unsigned, short, etc.) enumerations Structured: Collections of data arrays, structs, unions, classes, valarrays, bitsets, the containers and adapters in STL

3 Structs vs. Classes Similarities
Essentially the same syntax Both are used to model objects with multiple attributes (characteristics) represented as data members also called fields … or … instance or attribute variables). Thus, both are used to process non-homogeneous data sets.

4 Structs vs. Classes Differences
No classes in C Members public by default Can be specified private Both structs and classes in C++ Structs can have members declared private Class members are private by default Can be specified public

5 Advantages in C++ (structs and Classes)
C++ structs and classes model objects which have: Attributes represented as data members Operations represented as functions (or methods) Leads to object oriented programming Objects are self contained "I can do it myself" mentality They do not pass a parameter to an external function

6 Designing a Class Data members normally placed in private: section of a class Function members usually in public: section Typically public: section followed by private: although not required by compiler

7 Rationale Data members are typically private
Cannot be accessed outside class Application programs must interact with an object through its interface Public member functions control interaction between programs and class. Application programs need not know about implementation!

8 Separate Implementation Details from Application Code
If NOT … change in implementation forces change in the application code Increased upgrade time Increased programmer cost Decreased programmer productivity Reduced profits due to Delayed releases/upgrades Loss of customer confidence in software reliability

9 Traditional Implementation
Specification of class in .h file Implementation in .cpp file Forces data abstraction separates interface from interface details Increased use of templates changes this specification and implementation must be in same file thus the dropping of the .h from standard class libraries they are really class-template libraries


Download ppt "Data Structures and ADTs"

Similar presentations


Ads by Google