1 / 9

Data Structures and ADTs

This chapter explores the fundamental data types in C++, including ints, doubles, chars, bools, and enumerations. It also discusses the differences and similarities between structs and classes, as well as the advantages of using structs and classes in object-oriented programming.

esteele
Download Presentation

Data Structures and ADTs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Structures and ADTs Chapter 3

  2. C++ Data Types • Fundamental(or simple or scalar): • 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. 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 Structs vs. ClassesDifferences

  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 fileImplementation 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

More Related