Copyright © Curt Hill Structured Data What this course is about
Last class The first semester is mostly about: Common syntax Executable statements Flow of control Functions This is stuff that is in every programming langauge This course is mostly about structured data Copyright © Curt Hill
Un-Structured Data The simple types are not structured: –bool –char –double –float –int One name and one value Usually reserved words in C/C++/Java
Copyright © Curt Hill Memory models A running program has several segments of memory The code segment –Machine language instructions –Some types of constants The stack segment –Local and global variables –Temporary values Return addresses and values Temporary expression values Heap –Dynamically allocated variables –Allocated and freed explicitly by the programmer
Copyright © Curt Hill Structured Data One item with multiple values Data thingies clustered together Ability to access as a whole Ability to access the individual values Always shows relationship of the values to one another
Copyright © Curt Hill The structured data types Arrays Structs Unions Classes Files Pointers Dynamic data structures
Copyright © Curt Hill Arrays Every language has one Homogeneous data structure Many values with just one type Identical form and function –Interchangeable values –Sortable Different in C/C++ than others Example: –Test scores
Copyright © Curt Hill Structs Same as: –Pascal record –COBOL group Heterogeneous data structure Many values and many types Collection of attributes Example of a person: –Age (int) –Wage (float) –Name (character string) –Gender (bool) Bill Smith true
Copyright © Curt Hill Unions Different ways to treat the same memory A cast converts from one type to an equivalent value in another type Unions do not cast, they use the same memory in one of several ways Example of marital status from a personnel record –If married save the spouse name –If divorced save the divorce date –If single save whether a dependent –The first byte of each is exactly the same memory byte
Copyright © Curt Hill Classes Only one not in C Basis of object oriented programming in C++ and Java Struct as an independent item Extension of a struct with –Visibility –Member functions, often called methods (these did exist but were not often used in structs) –Inheritance –Polymorphism
Copyright © Curt Hill Importance of classes The difference between the OO languages and previous –Main difference between C and C++ Objects become our main abstraction tool –Previously functions were They allow us to divide our programs into bite size pieces They facilitate reuse They simplify design
Classes We will take four shots at the class Simple definitions More complicated with operator overloads Inheritance and polymorphism Generics – template classes –This will lead to the Standard Template Library in the next semester Copyright © Curt Hill
Files Arrays on disk and not in memory Only permanent data structure Not a machine dependent item but an Operating System dependent item Example –File of scores
Copyright © Curt Hill Pointers An address to a memory location In C/C++/Pascal must point at only one type Changing the pointer is different than changing the item pointed at In C/C++ can be automatically cast to an int The mechanism used for dynamic allocation Intertwined with arrays
Copyright © Curt Hill Dynamic data structures A technique using both pointers and some other structured type –Usually a class –May be an array or struct