Lecture 15: Course Review BJ Furman ME 30 16MAY2011.
-
Upload
patrick-wiggins -
Category
Documents
-
view
220 -
download
0
description
Transcript of Lecture 15: Course Review BJ Furman ME 30 16MAY2011.
Lecture 15: Course Review
BJ FurmanME 3016MAY2011
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
Learning Objectives List the important concepts we covered Develop a plan to prepare for the final
exam
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
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
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 ( &, |, ~, ^ )
Repetition Structures Be able to apply the three kinds of
repetition structures: while do/while for
Syntax and logic
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
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
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
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()
Excel for Engineering Applications
Chart types Scatter vs. line
Opening data files Annotating charts for publication Trend line and regression Using Solver Macros
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
Review
References
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; }
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;
WHILE Structure Syntaxwhile(expression) /* if expression is TRUE (!= zero) */ { statement1; /* then execute statements between { } */
statement2; }
DO-WHILE Structure Syntaxdo { statement1; // do the stuff between the { }
statement2; } while(condition); // while condition is true
FOR Structure Syntaxfor(i=0; i<5; i++) { statement1; // do the stuff between the { }
statement2; }