Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2002-2008 Curt Hill Structured Data What this course is about.

Similar presentations


Presentation on theme: "Copyright © 2002-2008 Curt Hill Structured Data What this course is about."— Presentation transcript:

1 Copyright © 2002-2008 Curt Hill Structured Data What this course is about

2 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 © 2002-2008 Curt Hill

3 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

4 Copyright © 2002-2008 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

5 Copyright © 2002-2008 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

6 Copyright © 2002-2008 Curt Hill The structured data types Arrays Structs Unions Classes Files Pointers Dynamic data structures

7 Copyright © 2002-2008 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 87 69 72 95 76 86

8 Copyright © 2002-2008 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 35 9.65 true

9 Copyright © 2002-2008 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

10 Copyright © 2002-2008 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

11 Copyright © 1998-2008 - 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

12 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 © 2002-2008 Curt Hill

13 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 87 728790837977918982

14 Copyright © 2002-2008 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

15 Copyright © 2002-2008 Curt Hill Dynamic data structures A technique using both pointers and some other structured type –Usually a class –May be an array or struct


Download ppt "Copyright © 2002-2008 Curt Hill Structured Data What this course is about."

Similar presentations


Ads by Google