1 / 20

Lecture 15: Course Review

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

vianca
Download Presentation

Lecture 15: Course Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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

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

  4. 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

  5. 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

  6. 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 ( &, |, ~, ^ )

  7. Repetition Structures • Be able to apply the three kinds of repetition structures: • while • do/while • for • Syntax and logic

  8. 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

  9. 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

  10. 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

  11. 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()

  12. Excel for Engineering Applications • Chart types • Scatter vs. line • Opening data files • Annotating charts for publication • Trend line and regression • Using Solver • Macros

  13. 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

  14. Review

  15. References

  16. IF Structure Syntax if(expression) /* if expression is TRUE (not equal to zero) */ { statement1; /* then execute statements between { } */ statement2; } else { statement3; /* otherwise execute these statements */ statement4; }

  17. Switch-case structure switch(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;

  18. WHILE Structure Syntax while(expression) /* if expression is TRUE (!= zero) */ { statement1; /* then execute statements between { } */ statement2; }

  19. DO-WHILE Structure Syntax do { statement1; // do the stuff between the { } statement2; } while(condition); // while condition is true

  20. FOR Structure Syntax for(i=0; i<5; i++) { statement1; // do the stuff between the { } statement2; }

More Related