getting ready to code lecture 1 match 4, 2013. course syllabus

33
S Getting ready to code Lecture 1 Match 4, 2013

Upload: preston-singleton

Post on 18-Jan-2018

226 views

Category:

Documents


0 download

DESCRIPTION

Why study programming?   Autonomous vehicle project     Brain analysis through eye blink detection    Mobile robot control 

TRANSCRIPT

Page 1: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

S

Getting ready to code

Lecture 1Match 4, 2013

Page 2: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Course syllabus

http://synteam.org/language/

Page 3: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Why study programming?

http://www.youtube.com/watch?v=tVtvCAYBhTg Autonomous vehicle project

http://www.youtube.com/watch?v=kMn4_AyMAjE http://www.youtube.com/watch?v=8d-zrsy_zfk http://www.youtube.com/watch?v=bp9KBrH8H04

Brain analysis through eye blink detection http://www.youtube.com/watch?v=_5UHCNevrPM http://www.youtube.com/watch?v=EVgXeTGhARc

Mobile robot control http://www.youtube.com/watch?v=iLUl81e6OSs

Page 4: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Exam

ple

Face a

nd ey

es

detec

tion

progra

m

Page 5: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Continuation

Page 6: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Demonstration Face recognition program

Page 7: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

What is Programming?

Programming is instructing a computer to do something for you with the help of a programming language

The two roles of a programming language: Technical: It instructs the computer to perform

tasks. Conceptual: It is a framework within which we

organize our ideas about things and processes. In programming, we deal with two kind of things:

Data - representing 'objects' we want to manipulate

Procedures -'descriptions' or 'rules' that define how to manipulate data.

7

Page 8: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Programming Language

Formal Language used to communicate to a computer.

A programming language contains instructions for the computer to perform a specific action or a specific task: 'Calculate the sum of the numbers from 1 to 10‘ 'Print “I like programming”‘ 'Output the current time'

8

Page 9: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Programming Language

Can be classified into as a special-purpose and general-purpose programming languages.

Special-purpose : is design for a particular type of application Structured Query Language (SQL)

General-purpose : can be used to obtain solutions for many types of problems1. Machine Languages2. Assembly Languages3. High-Level Languages

9

Page 10: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Machine Language

The only language that the processor actually 'understands‘

Consists of binary codes: 0 and 1 Example: 00010101

11010001 01001100

Each of the lines above corresponds to a specific task to be done by the processor.

10

Page 11: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Machine Language

Programming in machine code is difficult and slow since it is difficult to memorize all the instructions.

Mistakes can happen very easily. Processor and Architecture dependent

Simple add numbers program1. Copy the number in memory location 2000 to register 1.2. Copy the number in memory location 2004 to register 2.3. Add the contents of register 2 to the contents of register 1, leaving the

answer in register 1.4. Copy the contents of register 1 to memory location 2008.

Register is a small amount of storage available as part of a CPU.

Machine language Machine instructions are written in hexadecimal system

Page 12: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Assembly Language Enables machine code to be represented in words and

numbers. Example of a program in assembler language:

Easier to understand and memorize (called Mnemonics), compared to machine code but still quite difficult to use.

Processor and Architecture dependent12

LOAD A, 9999LOAD B, 8282ADD BMOV C, ALOAD C, #0002DIV A, CSTORE A, 7002

Page 13: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

High-level Computer Languages

Use more English words. They try to resemble English sentences. Therefore, it is easier to program in these languages.

The programming structure is problem oriented - does not need to know how the computer actually executes the instructions.

Processor independent - the same code can be run on different processors.

Examples: Basic, Fortran, Pascal, Cobol, C, C++, Java A high level language needs to be analyzed by the

compiler and then compiled into machine code so that it can be executed by the processor.

13

Page 14: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

High-level Computer Languages

High-level computer languages simplify our programming life in several ways. First, you don't have to express your instructions in a numeric code.

To add two numbers, for example, you might write the following: total = mine + yours;

total = mine + yours;

The compiler is a program that translates the high-level language program into the detailed set of machine language instructions the computer requires.

Page 15: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Why C?• Design Features

– Efficiency (C programs tend to be compact and to run quickly.)

– Portability (C programs written on one system can be run on other systems with little or no modification.)

– Power and Flexibility (OS and programing languages are written in C.)

– Programmer Oriented (It gives you access to hardware, and it enables you to manipulate individual bits in memory)

– Shortcomings (you can make programming errors that are very difficult to trace)

Page 17: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Where C is applied?

Page 18: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

History of C LanguageWhy it is named 'C' ? Because based on 'B'; developed at Bell Laboratories Developed by Dennis Ritchie at Bell Laboratories in the 1960s In cooperation with Ken Thomson it was used for Unix systems The C Language was only vaguely defined, not standardized, so

that almost everyone had his own perception of it, to such an extend that an urgent need for a standard code was creeping up

In 1983, the American National Standards Institute (ANSI) set up X3J11, a Technical Committee to draft a proposal for the ANSI standard, which was approved in 1989 and referred to as the ANSI/ISO 9899 : 1990 or simply the ANSI C, which is now the global standard for C.

18

Page 19: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

19

History of C Language

Page 20: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

C – An Imperative Language

#include <stdio.h>int main(void) { printf(”Hello world.\n"); return 0; }

20

C is a highly imperative language We must tell it exactly how to do what; the means and functions to use; which libraries to use; when to add a new line; when an instruction is finished; in short: everything and anything…

A simple program

Page 21: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Programming Mechanics When you write a program in the C language, you store what you

write in a text file called a source code file. Most C systems (MS Windows, Linux, Mac, ) require that the name

of the file end in .c (for example, wordcount.c and budget.c).

The hello.c Program#include <stdio.h>

int main(void) { printf(”Hello world.\n"); return 0; }

standard Library, input-output, header-file

Begin of program

Function for printing text

End of statement

Insert a new line

End of Segment21

Page 22: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Overview of a C program

22

Page 23: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Object Code Files, Executable Files, and Libraries

1. The compiler converts your source code to an intermediate code (object code file), and the linker combines this with other code to produce the executable file.

2. The object file contains machine language code, it is not ready to run;

3. The first element missing from the object code file is something called startup code;

4. The second missing element is the code for library routines

5. The role of the linker is to bring together these three elements—your object code, the standard startup code for your system, and the library code—and put them together into a single file, the executable file.

23

Page 24: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Process of compiling and running a C program

24

Page 25: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Using C: Seven Steps

1. Define the program objectives;

2. Design the program;3. Write the code;4. Compile;5. Run the program;6. Test and debug the program;7. Maintain and modify the

program.

25

Page 26: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Define the program objectives

Start with a clear idea of what you want the program to do;

Think in terms of the information your program needs;

And the information the program should report back to you;

Think in general terms, not in terms of some specific computer language.

26

Page 27: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Design the program

What should the user interface be like?

How should the program be organized?

Who will the target user be?

How much time do you have to complete the program?

Think in general terms, not about specific code.

27

Page 28: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Write the Code

Now that you have a clear design for your program, you can begin to implement it by writing the code. #include <stdio.h>

int main(void) { int dogs;

printf("How many dogs do you have?\n"); scanf("%d", &dogs);

printf("So you have %d dog(s)!\n", dogs);

return 0; }

28

Page 29: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Compile The compiler is a program

whose job is to convert source code into executable code;

Executable code is code in the native language, or machine language, of your computer;

C compilers also incorporate code from C libraries into the final program; the libraries contain a fund of standard routines, such as printf() and scanf(), for your use. (More accurately, a program called a linker)

29

Page 30: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Run the Program The executable file is a program you can run.

30

Page 31: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Test and Debug the Program

The fact that your program runs is a good sign, but it's possible that it could run incorrectly;

Some of your programs have mistakes—bugs;

Debugging is the process of finding and fixing program errors;

The compiler catches many kinds of errors, and there are things you can do to help yourself track down the ones that the compiler doesn't catch.31

Page 32: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Maintain and modify the program

You could add a clever new feature.

You might adapt the program so that it runs on a different computer system.

All these tasks are greatly simplified if you document the program clearly and if you follow sound design practices.

32

Page 33: Getting ready to code Lecture 1 Match 4, 2013. Course syllabus

Questions?