cs246-s11-001-june2

cs246-s11-001-june2 - CS 246 (Spring 2011) Section 1...

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

View Full Document Right Arrow Icon
CS 246 (Spring 2011) – Section 1 Thursday 2 June Modularization, Routines, and I/O
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 2 June 2 Today's Agenda 2.8 Modularization 2.9 Routine 2.10 Input/Output
Background image of page 2
CS 246 (Spring 2011) - Section 001 - Thursday 2 June 3 2.8 Modularization The division of a system into interconnecting smaller parts Logical boundaries between modules Provided through interfaces A way to abstract data structures and algorithms Example Common code can be factored to a single location 3x 3 – 8x 2 + 4x = x(3x 2 – 8x + 4)
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 2 June 4 2.9 Routine Routine : The simplest module for factoring an abstraction into code Input and output parameters define the interface of a routine Parallel with mathematical notation f: Z Z f(x) = x 2 int f ( int n ); int f ( int n ) { return n*n; }
Background image of page 4
CS 246 (Spring 2011) - Section 001 - Thursday 2 June 5 Routine (ctd.) A routine in C++ [inline] void p( OR [inline] T( list of parameters) { routine body } Inline : Routine expanded at call site (benefits?) Two types of routines Procedure : Return type of void Function : Returns a value that can be used in an expression How to terminate a procedure or function? Returned values vs. side effects?
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 2 June 6 A brief look at memory Division of memory into three regions Static block : Routines, variables outside of routines Heap : Dynamic allocation of memory Stack : Stack frames for routine calls Stack frames Stores parameters, local variables, return address Division into stack blocks Example
Background image of page 6
CS 246 (Spring 2011) - Section 001 - Thursday 2 June 7 2.9.1 Argument/Parameter Passing Arguments are passed from a routine call to the parameters in a routine in one of two ways
Background image of page 7

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

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

This note was uploaded on 12/08/2011 for the course CS 246 taught by Professor Wormer during the Spring '08 term at Waterloo.

Page1 / 22

cs246-s11-001-june2 - CS 246 (Spring 2011) Section 1...

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

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