lecture17 Structures

lecture17 Structures - 1 Janice Regan, CMPT 128, Feb.. 2007...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Janice Regan, CMPT 128, Feb.. 2007 CMPT 128: Introduction to Computing Science for Engineering Students Structures Janice Regan, CMPT 128, February 2007 2 Recall: Composite Data Types Data Type includes A collection of objects (can be numbers, characters ) A group of operations that can be performed on those objects (the result of the operation should also be a member of the collection) A way to represent object of the type in memory Basic data types ( int, double, ) identify the type of a single variable which references a single location in memory. Composite data types identify a group of values located in successive memory locations. The group of values is referred to by a single identifier. If all the component values have the same basic type use an array If component values have a variety of basic types use a structure Janice Regan, CMPT 128, February 2007 3 Using Structures Define Structure Declare variables of type of the structure Use variables declared above Structures can be used as parameters and return values of functions Janice Regan, CMPT 128, February 2007 4 Defining Structures Define Structure (A new composite type) Must tell the compiler what the structure is before it can be used, In particular you must specify the following for your structure: An identifier (name) A list of component variables or elements The basic types of each of the elements Janice Regan, CMPT 128, February 2007 5 Defining Structures: Example Define Structure labMeasurement labMeasurement contains all data regarding the running of a load test on a sample group of components labMeasurement includes An integer indicating the date the measurement was taken An integer indicating the number of components to be tested in the experiment An integer containing the duration of the experiment is seconds A floating point number containing the measured temperature in degrees Celsius An integer indicating the number of components that failed the load test in the recorded conditions Janice Regan, CMPT 128, February 2007 6 Defining Structures: Example struct labMeasurement { int measurementNum; int date; int numOfComponents; int duration; double temperature; int numFailures; } ; ; at the end of the structure definition is required Janice Regan, CMPT 128, February 2007 7 Review: what is scope? Local or function scope: Variable exists and can be used only within the function in which it is defined int myFunct( double myParam1, in myParam2) { // start of body of function myFunct int myLocalVariable; // myLocal Variable has local or function scope // myLocal Variable exists and can be used only // within the body of function myFunct // end of body of function myFunct } Janice Regan, CMPT 128, February 2007 8 Review: what is scope?...
View Full Document

This note was uploaded on 05/18/2010 for the course CMPT 128 taught by Professor Regan during the Spring '08 term at Simon Fraser.

Page1 / 30

lecture17 Structures - 1 Janice Regan, CMPT 128, Feb.. 2007...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online