bg287

csc110

Posted in csc110 by bnmng on 2010 03/30

Homework due Thursday
Brookshear (eoc exercises): Chapter 6 : 7, 8, and 29
Bronson Chapter 6 Section 6.1 1, 2a, 6a
Sectin 6.2

Test 3 will be Next Tuesday, April 6.

Today: Bronson 6.2 Returning a simple value; 6.3 Call by reference, pass by reference.

Procedural: A jump from the normal program flow.
Advantages: Useful thinking tool. Modularizes parts of code into separate sections.

Arguments in the caller are “actual arguments”
Arguments in the header are called “formal arguments.”.

Passing arguments. Sometimes you want to pass a

You can call function which returns a value.

Our instructor doesn’t like 6.1. he Emphasizes functional cohesiveness.

When using a function we need three things: Prototype; Call; Definition. By convention, you don’t need names for the arguments in the prototype, but modern teaching includes names in the prototypes.

Also, the prototype is only needed if we define the function after

You need a return statement for any function that returns a value. If you forget your return statement, the program will compile but it will run improperly.

Parameters are passed in order. The order of parameters in the prototype, call, and definition must match.

Example:
prototype:
void larger (int, int, int &);

Overloading. You can use the same name for two function that have different parameters. Example:
void something (int int);
int something (float int int&);
are two different functions.

By convention, two functions with the same name should do the same thing. The reason you would have two functions like this is because you might have to use different code for float inputs as you would for int inputs. For instance:

void divide (int numer int deno) {
int quo;
int mo;
quo=numer / deno;
mo=numer % deno;

cout << numer << "divided by " << deno << " equals " << quo << " remainder " << mo << endl;

}

void divide (float numer float deno) {
float quo;

quo=numer / deno;

cout << numer << "divided by " << deno << " equals " << quo << endl;

}

Using dummy variables inside functions.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: