Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE Application Programming

Similar presentations


Presentation on theme: "ECE Application Programming"— Presentation transcript:

1 16.216 ECE Application Programming
Instructor: Dr. Michael Geiger Fall 2013 Lecture 12 Exam 1 Preview

2 ECE Application Programming: Exam 1 Preview
Lecture outline Announcements/reminders Program 3 regrades due 10/4 Program 4 due 10/7 Exam 1: Wednesday, 10/2 Will be allowed one 8.5” x 11” double-sided note sheet Final exam scheduled: Wed. 12/18, 8-11 AM Today’s lecture: Exam 1 Preview General exam notes Review of material 6/2/2018 ECE Application Programming: Exam 1 Preview

3 ECE Application Programming: Exam 1 Preview
Exam 1 notes Allowed one 8.5” x 11” double-sided sheet of notes No other notes No electronic devices (calculator, phone, etc.) Exam will last 50 minutes We’ll start at 12:00—please be on time!! Covers all lectures through Friday You will not be tested on design process, IDEs Material starts with basic C program structure 3 questions 1 multiple choice 1 code reading 1 code writing (complete 2 of 3 parts; all 3 for extra credit) 6/2/2018 ECE Application Programming: Exam 1 Preview

4 Review: Basic C program structure
Preprocessor directives #include: typically used to specify library files #define: generally used to define macros We’ll use to define constants Main program Starts with: int main() or void main() Enclosed in block: specified by { } Ends with return 0; Indicates successful completion Not used if main() is void Basic output Call printf(<string>); <string> can be replaced by characters enclosed in double quotes May include escape sequence, e.g. \n (new line) 6/2/2018 ECE Application Programming: Exam 1 Preview

5 Review: Data types, variables, constants
Four basic data types int, float, double, char Constants Discussed viable ranges for all types #define to give symbolic name to constant Variables Have name, type, value, memory location Variable declarations: examples int x; float a, b; double m = 2.35; 6/2/2018 ECE Application Programming: Exam 1 Preview

6 Review: printf() and scanf() basics
To print variables (or constants), insert %<type> in your printf() format string %c: single character %d or %i: signed decimal integer %u: unsigned decimal integer %x or %X: unsigned hexadecimal integer %f: float %lf: double %s: string Each %<type> must correspond to a variable or constant that follows printf("a=%f, b=%f",a,b); To read input, use same format specifiers in scanf() format string, followed by addresses of variables scanf("%d %f",&hours,&rate); 6/2/2018 ECE Application Programming: Exam 1 Preview

7 ECE Application Programming: Exam 1 Preview
Review: field width Format specifier for printf() takes form: %[flags][width][.precision] Field width: minimum # chars to be printed Never truncates—if more chars than width, prints all Default behavior—right justify value, print spaces printf(“%10d”, n);  (8 spaces, then number 12) Flags allow you to add sign (+), left justify (-), and add leading zeroes (0) printf(“%+-10d”, n);  +12_______ (Number 12 with sign, then 7 spaces) printf(“%010d”, n);  To use a variable to specify field width, use * as the width printf(“%*d”, n, n);  (Field width = 12  10 spaces, then the number 12) 6/2/2018 ECE Application Programming: Exam 1 Preview

8 ECE Application Programming: Exam 1 Preview
Review: precision Format specifier for printf() takes form: %[flags][width][.precision] Specifying precision: # chars after decimal point for FP (%f, %lf) Rounds last digit printf(“%.1lf”, x);  3.8 printf(“%.0lf”, x);  4 Minimum # chars for integer (%d, %i, %u, %x) Does not truncate; will pad with leading 0s printf(“%.3d”, n);  012 Max # chars for string (%s) printf(“%.5s”, “one two”);  one t No effect for char (%c) As with field width, can use * to specify that field width is a variable 6/2/2018 ECE Application Programming: Exam 1 Preview

9 ECE Application Programming: Exam 1 Preview
Review: C operators Operator Associativity Innermost ( ) Left to right Unary - Right to left * / % 6/2/2018 ECE Application Programming: Exam 1 Preview

10 Review: Operators and statements
Operators can be used either with constants or variables More complex statements are allowed e.g. x = ; Parentheses help you prioritize parts of statement Makes difference with order of operations x = * 3 is different than x = (1 + 2) * 3 6/2/2018 ECE Application Programming: Exam 1 Preview

11 ECE Application Programming: Exam 1 Preview
Review: if statements Conditional execution using if statements: Form: if (<expression>) <statement> [ else brackets show <statement> ] else is optional Expression frequently uses relational operators to test equality/inequality < > <= >= == != e.g., if (x <= 5) Can combine conditions using logical operators AND : && OR: || e.g., if ((x <= 5) && (x > 0)) Can test if condition is false using logical NOT: ! e.g., if (!(x < 5)) 6/2/2018 ECE Application Programming: Exam 1 Preview

12 Review: switch statements
When checking multiple exact values for expression, more sense to use switch statement switch (<expr>) { case <val1> : ... break; case <val2> : default: } break allows you to exit switch statement after completing code Otherwise, program will continue to run through cases until finding break default covers any values without specific case 6/2/2018 ECE Application Programming: Exam 1 Preview

13 Review: while/do-while loops
Used for repetition of code while (<expression>) <statement>  loop body do { <statements> } while ( <expression> ); 6/2/2018 ECE Application Programming: Exam 1 Preview

14 ECE Application Programming: Exam 1 Preview
Review: for loops for (<init var>; <test>; <change var>) <statements> Operators to directly change variable x++, x--  post-increment/decrement ++x, --x  pre-increment/decrement +=, -=, *=, /=  augmented assignment 6/2/2018 ECE Application Programming: Exam 1 Preview

15 ECE Application Programming: Exam 1 Preview
Final notes Next time Exam 1 Reminders: Program 3 regrades due 10/4 Program 4 due 10/7 Exam 1: Wednesday, 10/2 Will be allowed one 8.5” x 11” double-sided note sheet 6/2/2018 ECE Application Programming: Exam 1 Preview


Download ppt "ECE Application Programming"

Similar presentations


Ads by Google