ECE Application Programming

Slides:



Advertisements
Similar presentations
ECE Application Programming Instructor: Dr. Michael Geiger Spring 2013 Lecture 6: printf() formatting.
Advertisements

Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Assignment #2, 12- month Calendar CS-2301, B-Term Programming Assignment #2 12-Month Calendar CS-2301, System Programming for Non-Majors (Slides.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
1 IPC144 Session 11 The C Programming Language. 2 Objectives To format a #define statement correctly To use a #define statement in a C program To construct.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
ECE Application Programming Instructors: Dr. Michael Geiger & Nasibeh Nasiri Fall 2015 Lecture 2: Basic C program structure Data in C: Data types,
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
+ Note On the Use of Different Data Types Use the data type that conserves memory and still accomplishes the desired purpose. For example, depending on.
Numbers in ‘C’ Two general categories: Integers Floats
ECE Application Programming
ECE Application Programming
C Formatted Input/Output
ECE Application Programming
ECE Application Programming
Formatted Input and Output
ECE Application Programming
ECE Application Programming
ECE Application Programming
ECE Application Programming
ECE Application Programming
TMF1414 Introduction to Programming
ECE Application Programming
ECE Application Programming
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Differences between Java and C
EECE.2160 ECE Application Programming
Conversion Check your class notes and given examples at class.
EECE.2160 ECE Application Programming
WEEK-2.
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Instructor: Dr. Michael Geiger Spring 2019 Lecture 13: Exam 1 Preview
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Instructor: Dr. Michael Geiger Spring 2017 Lecture 12: Exam 1 Preview
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Presentation transcript:

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

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

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

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

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

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

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);  12 (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);  0000000012 To use a variable to specify field width, use * as the width printf(“%*d”, n, n);  12 (Field width = 12  10 spaces, then the number 12) 6/2/2018 ECE Application Programming: Exam 1 Preview

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

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

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

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

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

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

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

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