Presentation is loading. Please wait.

Presentation is loading. Please wait.

EECE.2160 ECE Application Programming

Similar presentations


Presentation on theme: "EECE.2160 ECE Application Programming"— Presentation transcript:

1 EECE.2160 ECE Application Programming
Instructor: Dr. Michael Geiger Summer 2018 Lecture 1: Course overview Basic C program structure Data in C: data types, constants, and variables

2 ECE Application Programming: Lecture 1
Lecture outline Announcements/notes Program 1 due Thursday, 5/24 10 points: register for access to the course textbook 10 points: introduce yourself to your instructor 30 points: complete simple C program Today’s lecture Course overview Introduction to C programming Program development cycle Basic program structure Data in C Data types, constants, and variables zyDE demo 7/11/2019 ECE Application Programming: Lecture 1

3 Course meeting times, instructor info
Lectures: MWTh 8-10:20, Ball 323 Instructor: Dr. Michael Geiger Phone: (x43618 on campus) Office: 301A Ball Hall Office hours: MWTh 10:30-11:30 Also available by appointment 7/11/2019 ECE Application Programming: Lecture 1

4 ECE Application Programming: Lecture 1
Course materials Required Textbook: Programming in C with zyLabs, EECE.2160, Summer 2018 Electronic textbook I’m using for first time Free (this term only) for students 10% of grade assigned to exercises from text To access text: Sign in or create learn.zybooks.com Enter zyBook code: UMLEECE2160GeigerSummer2018 Subscribe (free this term; lasts until 7/15/18) 7/11/2019 ECE Application Programming: Lecture 1

5 Additional course materials
Course websites: Will contain lecture slides, handouts, assignments Discussion group through piazza.com: Allow common questions to be answered for everyone Do not post code to the discussion group All course announcements will be posted here Will use as class mailing list—please enroll ASAP 7/11/2019 ECE Application Programming: Lecture 1

6 ECE Application Programming: Lecture 1
Academic honesty All assignments are to be done individually unless explicitly specified otherwise by the instructor Any copied solutions, whether from another student or an outside source, are subject to penalty You may discuss general topics or help one another with specific errors, but do not share assignment solutions Must acknowledge assistance from classmate in submission 7/11/2019 ECE Application Programming: Lecture 1

7 ECE Application Programming: Lecture 1
Course “rules” A couple of unofficial rules: Please call me “Dr. Geiger” “Professor Geiger” is okay (although I’m technically not a professor, I’m a lecturer) “Michael,” “Mike,” or “Geiger” is not okay Please don’t talk when I’m talking Doing so distracts your classmates and me If you have a question, please raise your hand and ask—I want questions during lecture! 7/11/2019 ECE Application Programming: Lecture 1

8 Programming assignments
Will submit all code through textbook IDE Penalty after due date: -(2n-1) points per day i.e., -1 after 1 day, -2 after 2 days, -4 after 3 days … Assignments that are 8+ days late receive 0 See grading policies (last three pages of today’s handout) for more details on: Grading rubric Common deductions Regrade policy Example grading PLEASE NOTE: With new grading system, I reserve right to modify grading guidelines on assignment-by-assignment basis 7/11/2019 ECE Application Programming: Lecture 1

9 Programming assignments: regrades
You are allowed one penalty-free resubmission per assignment Each regrade after the first: 1 day late penalty Must resubmit by regrade deadline, or late penalties will apply Late penalty still applies if original submission late “Original submission”  first file submitted containing significant amount of relevant code In other words, don’t turn in a virtually empty file just to avoid late penalties—it won’t count 7/11/2019 ECE Application Programming: Lecture 1

10 ECE Application Programming: Lecture 1
Grading and exam dates Grading breakdown Programming assignments: 50% No programs will be dropped Textbook activities: 10% Participation activities: 5% Challenge activities: 5% Lowest of first 2 exams: 10% Highest of first 2 exams: 15% Exam 3: 15% Exam dates Exam 1: Monday, June 4 in class Exam 2: Monday, June 18 in class Exam 3: Monday, July 2 in class May consider alternate scheduling—stay tuned 7/11/2019 ECE Application Programming: Lecture 1

11 Tentative course outline
Basic C program structure and development Working with data: data types, variables, operators, expressions Basic console input/output Control flow Functions: basic modular programming, argument passing Pointers, arrays, and strings Creating new data types: structures Dynamic memory allocation File & general input/output Bitwise operators 7/11/2019 ECE Application Programming: Lecture 1

12 Programming exercises
Note on course schedule: several days marked as “PE#” Those classes will contain supervised, in-class programming exercises We’ll write/complete short programs to illustrate previously covered concepts If you have a laptop, feel free to bring it 7/11/2019 ECE Application Programming: Lecture 1

13 ECE Application Programming: Lecture 1
Course questions General notes/questions about the course: How many of you have prior programming experience? For those that do, can improve programming style, efficiency, potentially learn new items For those that don’t, course assumes no prior programming experience Fair warning for all of you: material builds on itself throughout course Difficulty increases as course goes on If (when) you get stuck, ask for help!!! 7/11/2019 ECE Application Programming: Lecture 1

14 Course questions (continued)
How many of you are taking this course only because it’s required? Follow-up: how many of you hope you’ll never have to program again once you’re done with the course? Both computer and electrical engineers commonly program in industry—some examples: Automation of tasks Circuit simulation Test procedures Programming skills highly sought by employers 7/11/2019 ECE Application Programming: Lecture 1

15 ECE Application Programming: Lecture 1
Program development ... which is a good approach for your assignments, too! Average student’s approach to programming Read specification (assignment) ... at least some of it, anyway ... Attempt to write complete program Find output error and fix related code Repeat previous step until either Code completely works ... ... or code is such a mess that problem(s) can’t be fixed 7/11/2019 ECE Application Programming: Lecture 1

16 Program development (cont.)
A more structured approach to program development Read specification Identify requirements What results should program produce? How can I test correctness of those results? Plan design that implements requirements Using flowchart, pseudocode, etc. Plan for tests as well Translate design into actual code Test program and fix errors 7/11/2019 ECE Application Programming: Lecture 1

17 ECE Application Programming: Lecture 1
Our first C program #include <stdio.h> int main() { printf("Hello World!\n"); return 0; } 7/11/2019 ECE Application Programming: Lecture 1

18 ECE Application Programming: Lecture 1
Our first C program # indicates pre-processor directive include is the directive stdio.h is the name of the file to "insert" into our program. The <> means it is part of the C development system #include <stdio.h> int main() { printf("Hello World!\n"); return 0; } 7/11/2019 ECE Application Programming: Lecture 1

19 ECE Application Programming: Lecture 1
Our first C program main is the name of the primary (or main) procedure. All ANSI C programs must have a main routine named main The () indicates that main is the name of a procedure. All procedure references must be followed with () #include <stdio.h> int main() { printf("Hello World!\n"); return 0; } 7/11/2019 ECE Application Programming: Lecture 1

20 ECE Application Programming: Lecture 1
Our first C program { } enclose a "block". A block is zero or more C statements. Note that code inside a block is typically indented for readability—knowing what code is inside the current block is quite useful. #include <stdio.h> int main() { printf("Hello World!\n"); return 0; } 7/11/2019 ECE Application Programming: Lecture 1

21 ECE Application Programming: Lecture 1
Our first C program printf() is a "built-in" function (which is actually defined in stdio.h). "Hello World!" is the string to print. More formally, this is called the control string or control specifier. #include <stdio.h> int main() { printf("Hello World!\n"); return 0; } Every statement must end with a ";". Preprocessing directives do not end with a ";" (but must end with a return). 7/11/2019 ECE Application Programming: Lecture 1

22 ECE Application Programming: Lecture 1
Our first C program The \n is an escape character used by the printf function; inserting this character in the control string causes a “newline” to be printed—it’s as if you hit the “Enter” key #include <stdio.h> int main() { printf("Hello World!\n"); return 0; } 7/11/2019 ECE Application Programming: Lecture 1

23 ECE Application Programming: Lecture 1
Our first C program The int tells the compiler our main() program will return an integer to the operating system; the return tells what integer value to return. This keyword could be void, indicating that the program returns nothing to the OS. #include <stdio.h> int main() { printf("Hello World!\n"); return 0; } 7/11/2019 ECE Application Programming: Lecture 1

24 Variations #1 of first program
#include <stdio.h> int main() { printf("Hello"); printf("there"); printf("World!"); return 0; } 7/11/2019 ECE Application Programming: Lecture 1

25 Variations #2 of first program
#include <stdio.h> int main() { printf("Hello\n"); printf("there\n"); printf("World!\n"); return 0; } 7/11/2019 ECE Application Programming: Lecture 1

26 Variations #3 of first program
#include <stdio.h> int main() { printf("Hello\nthere\nWorld!\n"); return 0; } 7/11/2019 ECE Application Programming: Lecture 1

27 Variations #4 of first program
#include <stdio.h> int main(){printf ("Hello\nthere\nWorld!\n");return 0;} Note while this is syntactically correct, it leaves much to be desired in terms of readability. 7/11/2019 ECE Application Programming: Lecture 1

28 ECE Application Programming: Lecture 1
Code readability Readability wouldn’t matter if: Entire code project written by one person All code was in same file Same person is the only one to use the code Code was used only for a short period of time More typically: Projects are split—multiple programmers and files Code usually reused Multiple users Used/adapted (hopefully) over long period of time You may reuse code ... but forget what you originally wrote! Bottom line: code needs to be readable 7/11/2019 ECE Application Programming: Lecture 1

29 ECE Application Programming: Lecture 1
Comments C allows you to add comments to your code Single line comments: start with // Multi-line comments: start with /* end with */ Typical uses Multi-line comment at start of program with Author’s name (& other info if appropriate) Date started/modified File name Description of overall file functionality For individual code sections Single/multi-line comment for major section of code performing single function Single line comment for single line of code if that line alone is important 7/11/2019 ECE Application Programming: Lecture 1

30 ECE Application Programming: Lecture 1
Comment example /* ECE Application Programming Instructor: M. Geiger 7/11/2019 hello.c: Intro program to demonstrate basic C program structure and output */ #include <stdio.h> // Main program: prints basic string and exits int main() { printf("Hello World!\n"); // Comment return 0; } 7/11/2019 ECE Application Programming: Lecture 1

31 ECE Application Programming: Lecture 1
Representing data in C Two major questions (for now) What kind of data are we trying to represent? Data types Can the program change the data? Constants vs. variables 7/11/2019 ECE Application Programming: Lecture 1

32 Four Types of Basic Data
Integer int Floating point (single precision) float Double Precision double Character char 7/11/2019 ECE Application Programming: Lecture 1

33 ECE Application Programming: Lecture 1
Integer Constants Any positive or negative number without a decimal point (or other illegal symbol). Legal values: Illegal values: 2,523 (comma) 6.5 (decimal point) $59 (dollar sign) 5. (decimal point) 7/11/2019 ECE Application Programming: Lecture 1

34 Range of Integers (Machine Dependent)
unsigned signed char 0   +127 (8 bits) short int 0   short (16 bits) int 0 to  long long int (32 bits) 7/11/2019 ECE Application Programming: Lecture 1

35 float/double Constants
Any signed or unsigned number with a decimal point Legal values: Legal (exponential notation): 1.624e e e23 1.0e e e e e+7 Illegal: $ , E5 7/11/2019 ECE Application Programming: Lecture 1

36 float/double Constants
Range of float (32 bits) ± E – 38 ± E + 38 Range of double (64 bits) ± E – 308 ± E + 308 7/11/2019 ECE Application Programming: Lecture 1

37 ECE Application Programming: Lecture 1
Character Constants Stored in ASCII or UNICODE Signified by single quotes (’ ’) Valid character constants ’A’ ’B’ ’d’ ’z’ ’1’ ’2’ ’!’ ’+’ ’>’ ’?’ ’ ’ ’#’ Invalid character constants ’GEIGER’ ’\’ ’CR’ ’LF’ ’’’ ’’’’ ’”’ ”Q” 7/11/2019 ECE Application Programming: Lecture 1

38 Character Escape Sequences
Meaning ’\b’ Backspace ’\’’ Single quote ’\n’ Newline ’\”’ Double quote ’\t’ Tab ’\nnn’ Char with octal value nnn ’\\’ Backslash ’\xnn’ Char with hex value nn 7/11/2019 ECE Application Programming: Lecture 1

39 ECE Application Programming: Lecture 1
Variables All variables have four characteristics: A type An address (in memory) A value A name 7/11/2019 ECE Application Programming: Lecture 1

40 ECE Application Programming: Lecture 1
Variables - name must start with a-z, A-Z ( _ allowed, but not recommended) other characters may be a-z, A-Z, 0-9, _ upper case/lower case are not equal (i.e. ECE, ece, Ece, EcE, eCe would be five different variables) max length system dependent (usually at least 32) By convention Start with lowercase letter Descriptive names improve code readability 7/11/2019 ECE Application Programming: Lecture 1

41 Variables - legal names
grossPay carpet_Price cArPeT_price a_very_long_variable_name i ______strange___one_____ _ (not recommended) 7/11/2019 ECE Application Programming: Lecture 1

42 Variables - legal names (but not recommended)
l (that's lower case L) O (that's capital O) l1 (that's lower case L, and digit one) O0Oll11 (oh,zero,oh,el,el,one,one) _var (many system variables begin w/ _ ) 7/11/2019 ECE Application Programming: Lecture 1

43 ECE Application Programming: Lecture 1
Variables - declaring var name memory loc main() { float hours, payrate; float grosspay; int j; hours ? 4278 payrate ? 427C 4280 grosspay ? j ? 4284 All variable declarations should be grouped together at the start of the function 7/11/2019 ECE Application Programming: Lecture 1

44 ECE Application Programming: Lecture 1
Variables - assigning varname = expression; Declared variable single variable on left side of = expression any legal expression Expression can be constant, variable, function call, arithmetic operation, etc. Variable type (int, float, etc) and expression result type should match If not, funny things can happen ... 7/11/2019 ECE Application Programming: Lecture 1

45 ECE Application Programming: Lecture 1
Variables (cont.) var name memory loc main() { float hours, payrate; float grosspay; int j; hours = 40.0; hours 40.0 4278 payrate ? 427C 4280 grosspay ? j ? 4284 7/11/2019 ECE Application Programming: Lecture 1

46 ECE Application Programming: Lecture 1
Variables (cont.) var name memory loc main() { float hours, payrate; float grosspay; int j; hours = 40.0; payrate = 20.00; hours 40.0 4278 payrate 20.0 427C 4280 grosspay ? j ? 4284 7/11/2019 ECE Application Programming: Lecture 1

47 ECE Application Programming: Lecture 1
Variables (cont.) var name memory loc main() { float hours, payrate; float grosspay; int j; hours = 40.0; payrate = 20.00; grosspay = hours * payrate; hours 40.0 4278 payrate 20.0 427C 4280 grosspay 800.00 j ? 4284 note: referencing a variable only "reads" it (non-destructive). Assigning to a variable overwrites whatever was there (destructive). 7/11/2019 ECE Application Programming: Lecture 1

48 ECE Application Programming: Lecture 1
Variables (cont.) var name memory loc main() { float hours, payrate; float grosspay; int j; hours = 40.0; payrate = 20.00; grosspay = hours * payrate; j = 5; hours 40.0 4278 payrate 20.0 427C 4280 grosspay 800.00 j 5 4284 note: referencing a variable only "reads" it (non-destructive). Assigning to a variable overwrites whatever was there (destructive). 7/11/2019 ECE Application Programming: Lecture 1

49 ECE 160 - Introduction to Computer Engineering I
02/09/2005 Variables (cont.) var name memory loc main() { float hours, payrate; float grosspay; int j; hours = 40.0; payrate = 20.00; grosspay = hours * payrate j = 5; j = j + 1; hours 40.0 4278 payrate 20.0 427C 4280 grosspay 800.00 j 5 6 4284 note: referencing a variable only "reads" it (non-destructive). Assigning to a variable overwrites whatever was there (destructive). 7/11/2019 ECE Application Programming: Lecture 1 (c) 2005, P. H. Viall

50 ECE Application Programming: Lecture 1
Example: Variables What values do w, x, y, and z have at the end of this program? int main() { int w = 5; float x; double y; char z = ‘a’; x = 8.579; y = -0.2; w = x; y = y + 3; z = w – 5; return 0; } 7/11/2019 ECE Application Programming: Lecture 1

51 ECE Application Programming: Lecture 1
Example solution int main() { int w = 5; float x; double y; char z = ‘a’; x = 8.579; y = -0.2; w = x; y = y + 3; z = w – 5; return 0; } w = 5 z = ‘a’ (ASCII value 97) x = 8.579 y = -0.2 w = 8 (value is truncated) y = (-0.2) + 3 = 2.8 z = 8 – 5 = 3 7/11/2019 ECE Application Programming: Lecture 1

52 ECE Application Programming: Lecture 1
Final notes Next time: Operators Output with printf() Input with scanf() Reminders: Sign up for the course discussion group on Piazza! Program 1 due Thursday, 5/24 10 points: register for access to the course textbook 10 points: introduce yourself to your instructor 30 points: complete simple C program 7/11/2019 ECE Application Programming: Lecture 1


Download ppt "EECE.2160 ECE Application Programming"

Similar presentations


Ads by Google