Module 1 Introduction to Programming Using C Welcome

  • Slides: 41
Download presentation
Module 1 Introduction to Programming Using C

Module 1 Introduction to Programming Using C

Welcome • Facility – UMBC Training Centers • Instructor – Shawn Lupoli • Course

Welcome • Facility – UMBC Training Centers • Instructor – Shawn Lupoli • Course Overview – An introduction to programming using C www. umbctraining. com @UMBC Training Centers 2013 2

So, you want to make computers do things? www. umbctraining. com @Copyright UMBC Training

So, you want to make computers do things? www. umbctraining. com @Copyright UMBC Training Centers 2012 3

www. umbctraining. com @Copyright UMBC Training Centers 2012 4

www. umbctraining. com @Copyright UMBC Training Centers 2012 4

Computer A machine that stores and manipulates information under the control of a changeable

Computer A machine that stores and manipulates information under the control of a changeable program www. umbctraining. com @Copyright UMBC Training Centers 2012 5

Computer program A detailed, step-by-step set of instructions telling a computer exactly what to

Computer program A detailed, step-by-step set of instructions telling a computer exactly what to do www. umbctraining. com @Copyright UMBC Training Centers 2012 6

“Computer science is no more about computers than astronomy is about telescopes. ” --

“Computer science is no more about computers than astronomy is about telescopes. ” -- Edsger Dijkstra www. umbctraining. com @Copyright UMBC Training Centers 2012 7

What process can we describe? What can be computed? www. umbctraining. com @Copyright UMBC

What process can we describe? What can be computed? www. umbctraining. com @Copyright UMBC Training Centers 2012 8

Design Analysis Solution Experimentation www. umbctraining. com @Copyright UMBC Training Centers 2012 9

Design Analysis Solution Experimentation www. umbctraining. com @Copyright UMBC Training Centers 2012 9

Algorithm A step-by-step process for achieving a desired result, a “recipe” www. umbctraining. com

Algorithm A step-by-step process for achieving a desired result, a “recipe” www. umbctraining. com @Copyright UMBC Training Centers 2012 10

Output Devices CPU Input Devices Main Memory www. umbctraining. com @Copyright UMBC Training Centers

Output Devices CPU Input Devices Main Memory www. umbctraining. com @Copyright UMBC Training Centers 2012 Secondary Memory 11

www. umbctraining. com @Copyright UMBC Training Centers 2012 12

www. umbctraining. com @Copyright UMBC Training Centers 2012 12

Translating, Interpreting, and Compiling /* File: My. App. c */ #include <stdio. h> int

Translating, Interpreting, and Compiling /* File: My. App. c */ #include <stdio. h> int main( ) { printf(“Hello Worldn”); return 0; } C C++ Java Python Perl Interpreter (Interactive Shell) Compiler C C++ Java Intermediate Language Runtime (JVM) Executable (My. App. exe)

Function Defining a function Open Brace void print. Greeting( ) { printf(“This program will

Function Defining a function Open Brace void print. Greeting( ) { printf(“This program will examine “); printf(“ the integers that you input “); printf(“ and display the largest onen”); } Close Brace www. umbctraining. com @Copyright UMBC Training Centers 2012 14

Invoking a Function Invoking void print. Greeting( ) { printf(“This program will examine “);

Invoking a Function Invoking void print. Greeting( ) { printf(“This program will examine “); printf(“ the integers that you input “); printf(“ and display the largest onen”); } /* elsewhere in your code */ print. Greeting( ); www. umbctraining. com @Copyright UMBC Training Centers 2012 15

Functions with Parameters Formal parameters Arguments www. umbctraining. com void print. Sum(int a, int

Functions with Parameters Formal parameters Arguments www. umbctraining. com void print. Sum(int a, int b) { printf(“The sum is %dn”, a + b); } /* elsewhere in your code */ print. Sum(5, 8); @Copyright UMBC Training Centers 2012 16

Development Environment www. umbctraining. com @UMBC Training Centers 2013 17

Development Environment www. umbctraining. com @UMBC Training Centers 2013 17

History of C • C was created in the early 70’s Dennis Ritchie www.

History of C • C was created in the early 70’s Dennis Ritchie www. umbctraining. com @UMBC Training Centers 2013 18

History C developed as a high level programming language for UNIX operating system in

History C developed as a high level programming language for UNIX operating system in early 1970’s Ken Thompson at Bell Telephone Laboratories wanted to create high level programming level for new operating system (UNIX) www. umbctraining. com @UMBC Training Centers 2013 Ken Thompson 19

More History • 1971 -1973 - Ritchie created C • 1973 - UNIX rewritten

More History • 1971 -1973 - Ritchie created C • 1973 - UNIX rewritten in C • 1978 - Brian Kernighan and Ritchie wrote The C Programming Language • C’s history according to Ritchie http: //cm. belllabs. com/who/dmr/chist. html www. umbctraining. com @UMBC Training Centers 2013 Brian Kernighan 20

Pioneers of Modern Computing Era • Thompson and Ritchie are considered pioneers of the

Pioneers of Modern Computing Era • Thompson and Ritchie are considered pioneers of the new computing era… • Interesting article on the deaths of Dennis Ritchie and Steve Jobs who died in 2011 http: //www. wired. com/wiredenterprise/2011/1 0/thedennisritchieeffect/ www. umbctraining. com @UMBC Training Centers 2013 21

Stood test of time • • 1988 – “white book” (K & R) 1989

Stood test of time • • 1988 – “white book” (K & R) 1989 – C 89 standard (ANSI C) 1999 – C 99 standard 2011 – C 11 standard (formally C 1 X) • This course uses C 99 www. umbctraining. com @UMBC Training Centers 2013 22

Characteristics of C • Low-level in modern high level programming languages – Structured –

Characteristics of C • Low-level in modern high level programming languages – Structured – Procedural (not object oriented) – Compiled – Fast – Platform independent “to an extent” – Direct access to memory www. umbctraining. com @UMBC Training Centers 2013 23

Uses of C • Systems Programming – Operating systems – Compilers – Device drivers

Uses of C • Systems Programming – Operating systems – Compilers – Device drivers – Databases – Applications that are time-critical • Subset of C++ – Graphics – Video gaming www. umbctraining. com @UMBC Training Centers 2013 24

Resources In 1988, K & R wrote the second edition PDF by Nick Parlante

Resources In 1988, K & R wrote the second edition PDF by Nick Parlante on Essential C http: //cslibrary. stanford. edu/101/Essential. C. pdf MIT Open Courseware http: //ocw. mit. edu/courses/electrical-engineeringand-computer-science/6 -087 -practicalprogramming-in-c-january-iap-2010/lecture-notes/ www. umbctraining. com @UMBC Training Centers 2013 25

Break time? ? www. umbctraining. com @UMBC Training Centers 2013

Break time? ? www. umbctraining. com @UMBC Training Centers 2013

Hello World /** Filename: hello. c ** Author: Bob Smith ** Creation Date: 7/1/1012

Hello World /** Filename: hello. c ** Author: Bob Smith ** Creation Date: 7/1/1012 ** Last Edit: ** R. Smith Version 1. 1 7/3/12 Capitalized World ** an example of a simple C program */ #include <stdio. h> int main( ) { // say hello to the world printf( "Hello Worldn" ); return 0; } www. umbctraining. com @UMBC Training Centers 2013 27

Running Hello World in Code. Blocks • Just sit back and watch, then we

Running Hello World in Code. Blocks • Just sit back and watch, then we will do together • http: //userpages. umbc. edu/~slupoli/notes/C/ videos/Hello. World/Hello%20 World%20 with% 20 Code%20 Blocks. html www. umbctraining. com @UMBC Training Centers 2013 28

Another Simple Program #include <stdio. h> int main( ) { int sum; sum =

Another Simple Program #include <stdio. h> int main( ) { int sum; sum = 50 + 25; printf(“The sum of 50 and 25 is %in”, sum); return 0; } www. umbctraining. com @UMBC Training Centers 2013 29

Creating an executable Text Editor Compiler Errors C Library Files Linker Errors main. c

Creating an executable Text Editor Compiler Errors C Library Files Linker Errors main. c main. o main. exe text file binary file Preprocessor Compiler Assembler www. umbctraining. com Linker @UMBC Training Centers 2013 Runtime Errors Program Output Program Execution 30

Configuring Compiler • You must configure Code: : Blocks to use the appropriate gcc

Configuring Compiler • You must configure Code: : Blocks to use the appropriate gcc compiler and linker – Both should be mingw 32 -gcc. exe – Settings > Compiler > Toolchain executables • “C compiler” set by default • Change “Linker for dynamic libs” if necessary • Pic next page www. umbctraining. com @UMBC Training Centers 2013 31

Configuring Compiler www. umbctraining. com @UMBC Training Centers 2013 32

Configuring Compiler www. umbctraining. com @UMBC Training Centers 2013 32

Configuring Compiler • You must also configure the gcc compiler to accept c 99

Configuring Compiler • You must also configure the gcc compiler to accept c 99 coding features – Settings > Compiler > Other options • Enter “–std=c 99” (no spaces, without the quotes) • Pic next page www. umbctraining. com @UMBC Training Centers 2013 33

Configuring Compiler www. umbctraining. com @UMBC Training Centers 2013 34

Configuring Compiler www. umbctraining. com @UMBC Training Centers 2013 34

Configuring Code: : Blocks • Settings > Compiler >> Compiler Flags – Produce debugging

Configuring Code: : Blocks • Settings > Compiler >> Compiler Flags – Produce debugging symbols [-g] – Enable all compiler warnings [-Wall] – Pic next page www. umbctraining. com @UMBC Training Centers 2013 35

Configuring Code: : Blocks www. umbctraining. com @UMBC Training Centers 2013 36

Configuring Code: : Blocks www. umbctraining. com @UMBC Training Centers 2013 36

Configuring Code: : Blocks • Settings > Editor > General Settings – Your preferences

Configuring Code: : Blocks • Settings > Editor > General Settings – Your preferences • Settings > Editor > Code Completion – May want to disable • Settings > Editor > Source Formatter > Style – Pick a style you like for braces www. umbctraining. com @UMBC Training Centers 2013 37

Compiling and Linking • BUILD drop-down menu – F 9 (Build and Run) •

Compiling and Linking • BUILD drop-down menu – F 9 (Build and Run) • Compiles and links all code in project • Runs the project – Ctrl+F 10 (Run) • Executes the current project – Ctrl+Shift+F 9 (compile current file) • Compiles current file, displaying errors in log window – Ctrl+F 11 (Rebuild) • Compiles all files that have changed www. umbctraining. com @UMBC Training Centers 2013 38

Downloading Code. Blocks • Need to install at home! – Get your work done

Downloading Code. Blocks • Need to install at home! – Get your work done • Downloading – www. codeblocks. org www. umbctraining. com @UMBC Training Centers 2013 39

Exercises • Will give 30 minutes, but can finish the rest later in lab

Exercises • Will give 30 minutes, but can finish the rest later in lab – Remember, lab is from 12 noon - 4 pm – Instructor proctored until 1 pm – Email your instructor if anything comes up • Textbook Chapter 3 – page 19 – Ex #1, 2, 4, 5, 6 www. umbctraining. com @UMBC Training Centers 2013 40