Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

20
Lecture 15: Course Review BJ Furman ME 30 16MAY2011

description

Learning Objectives List the important concepts we covered Develop a plan to prepare for the final exam

Transcript of Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Page 1: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Lecture 15: Course Review

BJ FurmanME 3016MAY2011

Page 2: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

The Plan for Today Review of what we covered this semester

Overview of computers and programming Algorithm development Selection structures Operators Repetition structures Modular programming Pointers and Arrays Strings File I/O Embedded programming Spreadsheets for engineering computation Matlab/Octave for engineering computation

Page 3: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Learning Objectives List the important concepts we covered Develop a plan to prepare for the final

exam

Page 4: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Overview of computers and programming

Where and how computers are used by MAEs List some of the major areas List some of the software

Memory and addresses Hex numbers as a shorthand for 4-bit chunks

Data types naming and declaration memory allocation

Formatted I/O with printf and scanf Focus of ME 30

Page 5: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Algorithm Development List and describe the steps in designing a

program Articulate what is meant by an algorithm Be able to generate pseudocode for an

algorithm

Page 6: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Selection Structures Be able to apply the three kinds of selection

structures: if if/else switch

Syntax and logic Relational operators (< <= > >= != ==)

test for equality Logical operators ( &&, | |, ! )

Used in compound expressions for selection decision Bit-wise ( &, |, ~, ^ )

Page 7: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Repetition Structures Be able to apply the three kinds of

repetition structures: while do/while for

Syntax and logic

Page 8: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Modular Programming (functions) Why are functions important? Working with functions

function prototype defining a function

return data type passing arguments

Scope of variables Program (global scope) File (just in the immediate source file) Function-prototype (just in the prototype) Function (applies only to labels) Block (“between the { } scope”)

Pointers and returning multiple values

Page 9: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Pointers and Arrays What is a pointer?

A variable that holds an address for a memory location int *ptr1 = &myvar1; // defines a pointer to an int and assigns

the memory location of the variable myvar1 Using the indirection operator to get the value pointed to

int myvar1 = 32; int *ptr1 = &myvar1; *ptr1 = *ptr1 + 1; // myvar1 == ??

What is an array? Declare and initialize an array Access elements in an array

remember that in C, indexing starts at 0! Arrays and pointers

Page 10: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Strings What is a string?

NUL ( \0 ) terminated array of characters String constant, string variable

"Hello, world"; char a[ ] = "Hello, world";

How many elements in this array? sizeof (a) / sizeof (char);

Access elements in an string variable remember that in C, indexing starts at 0!

Strings and pointers Name of string variable is treated like a pointer to its first

element

Page 11: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Microcontrollers Handling printed circuit boards Arduino microcontroller Inputs and Outputs

How to specify whether a pin is an input or output Programming the Arduino Reading to and writing from digital pins Reading to and writing from analog pins Writing a program for the Arduino

setup() loop()

Page 12: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Excel for Engineering Applications

Chart types Scatter vs. line

Opening data files Annotating charts for publication Trend line and regression Using Solver Macros

Page 13: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Matlab/Octave for Engineering Applications

Array and vector creation Array indexing starts with 1

Manipulating elements in arrays Matrix operations Script files and functions File I/O Plotting

Page 14: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Review

Page 15: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

References

Page 16: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

IF Structure Syntaxif(expression) /* if expression is TRUE (not equal to zero) */ { statement1; /* then execute statements between { } */

statement2; }else { statement3; /* otherwise execute these statements */

statement4; }

Page 17: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

Switch-case structureswitch(expression)// Expression must result in an integer value { case match1: // if exp is match1, then execute statements between { } { statement1; } break; case match2: // if exp is match1, then execute statements between { } { statement2; } break;default: // if no match, then execute statements between { } { statement3; } break;

Page 18: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

WHILE Structure Syntaxwhile(expression) /* if expression is TRUE (!= zero) */ { statement1; /* then execute statements between { } */

statement2; }

Page 19: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

DO-WHILE Structure Syntaxdo { statement1; // do the stuff between the { }

statement2; } while(condition); // while condition is true

Page 20: Lecture 15: Course Review BJ Furman ME 30 16MAY2011.

FOR Structure Syntaxfor(i=0; i<5; i++) { statement1; // do the stuff between the { }

statement2; }