Lecture Slides on Modular Programming | CSCE 150A, Study notes of Computer Science

Material Type: Notes; Class: PRBLM SOLVNG:COMPUTR; Subject: Computer Science and Engineering ; University: University of Nebraska - Lincoln; Term: Spring 2009;

Typology: Study notes

Pre 2010

Uploaded on 08/31/2009

koofers-user-1u0-2
koofers-user-1u0-2 🇺🇸

3.8

(4)

10 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCE150A
Modularization
Methods to
Help
Examples
Computer Science & Engineering 150A
Problem Solving Using Computers Laboratory
Lecture 06 Modular Programming
Derrick Stolee
Spring 2009
1/9
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Lecture Slides on Modular Programming | CSCE 150A and more Study notes Computer Science in PDF only on Docsity!

CSCE150A

Modularization Methods to Help Examples

Computer Science & Engineering 150A

Problem Solving Using Computers – Laboratory

Lecture 06 – Modular Programming

Derrick Stolee

Spring 2009

1 / 9^ [email protected]

CSCE150A

Modularization Methods to Help Examples

Break it up!

Big programs get BIG. Most software is many millions of lines of code. Organization is important

CSCE150A

Modularization Methods to Help Examples

Single Output Values

Usually, functions have a single return value. This is the only way to tell the “caller” any information* Parameters are pass by value, that is: values are copied. Consider the following definition: int func(int a) { a = 5; return 0; } What happens with the following code in main(): int b=1; int c = func(b);

CSCE150A

Modularization Methods to Help Examples

Multiple Output Values

We can pass values back to the caller more than just return! A parameter given by “type * name” is called a pointer. This is called pass by reference. We can set pointer values using (*name) = We pass an address to the function in the call using &variable. (see drawing on board)

CSCE150A

Modularization Methods to Help Examples

Example: Changing multiple values

See code sample ch6sam2.c The buyCoffee method returns the charge. Updates the total amount of coffee purchased (numCups) Checks for a coupon, or adds a coupon depending on number of cups.

CSCE150A

Modularization Methods to Help Examples

Example: Changing multiple values

See code sample ch6sam3.c The swapper method swaps the values if out of order. A sequence of calls to swapper sorts five variable values.