fp201 unit1 1

26
UNIT 1 INTRODUCTION TO PROGRAMMING

Upload: rohassanie

Post on 22-Dec-2014

418 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Fp201 unit1 1

UNIT 1 INTRODUCTION TO PROGRAMMING

Page 2: Fp201 unit1 1

Objectives Programming Environment Compiling Process Errors in Programming Debugging Strategies

Page 3: Fp201 unit1 1

At the end of this presentation, you will be able to :• Explain the system development phase that

involves programming• Explain three types of errors

Page 4: Fp201 unit1 1

Critical task in software development phase where to start?

WHY do the people feel the need to get something right early in the project??

Software ease to change.

Page 5: Fp201 unit1 1

1. Planning 2. Analysis 3. Design 4. Implementation

1. Coding 2. Testing 3. Installation

5. Maintenance

Page 6: Fp201 unit1 1

Determine what the system needs to do for the organization (requirements gathering). Often this means asking questions such as...• What do we need this system for?• What will the system do for the

organization?• How are we going to make this system?• Who is doing what, when, and how? 

Page 7: Fp201 unit1 1

Analyze any existing system to see what it is doing for the organization and how well that system is doing it's job. The feasibility of the project is also considered, and the group has to ask questions such as...• Can this system be created with the resources

(and budget) we have available?• Will this system significantly improve the

organization?• Does the old system even need to be replaced?

Analyzes end-user information needs. Software, hardware

Page 8: Fp201 unit1 1

Involves the actual creation and design of a system.

It will include screen layouts, process diagrams, pseudocode, flow chart and other documentation.

Page 9: Fp201 unit1 1

1. Coding 2. Testing 3. Installation

Page 10: Fp201 unit1 1

To ensure the reliability Changes and enhancements process

Page 11: Fp201 unit1 1

The process of going from source code files to an executable referred as build process.

There are 4 steps involve in building your program:• Editing• Compiling• Linking• Running

Page 12: Fp201 unit1 1

TOOL STEP PRODUCT

Editor Edit Source code files (.cpp)

Compiler Compile Object program (.obj)

Linker Link Executable object (.exe)

Run Result/Output

Page 13: Fp201 unit1 1

Start

SourceProgram

EditYour

Source

Compile orAssemble

Your Source

Yes

No

Errors? ObjectProgram

LinkLibrariesand Other

ObjectPrograms

Execute

ExecutableObject

No

Yes

ResultsOK?

Done

www.calpoly.edu

Page 14: Fp201 unit1 1

Compilation • the compiler translate C++ instruction in the

source code file into machine language instructions. • this process will produce an 'object' file but doesn't

create anything the user can actually run. • eg:

if you compile (but don't link) three separate files, you will have three object files created as output, each with the name <filename>.obj.

each of these files contains a translation of your source code file into a machine language file -- but you can't run them yet!

you need to turn them into executables your operating system can use and that's when the linker comes in.

Page 15: Fp201 unit1 1

The creation of a single executable file from multiple object files.

 A linker is typically used to generate an executable or library by combining parts of object files.

Page 16: Fp201 unit1 1
Page 17: Fp201 unit1 1

Compile time error Run time error Logical error

Page 18: Fp201 unit1 1

Syntax errors• Errors that prevent your program from

running. • Also called design-time error.• Caused by mistakes that you make when

typing code such as incorrect grammar, vocabulary, or spelling.

• These are usually easy to find and correct.• Common compile errors:

missing semicolon extra parenthesis keyword typo error

Page 19: Fp201 unit1 1

Errors that occur while your program runs. Occur when your program attempts an operation that

is impossible to carry out. Errors not caught at entry but which involve an

incorrect statement or bad data. The code appear has no syntax errors, but it will not

execute. More difficult to correct than syntax errors You can fix most run-time errors by rewriting the faulty

code, and then recompiling and rerunning it. common run time errors including:

undefined functions (commonly, main itself). during compilation, if the compiler could not find the definition for a particular function,

it would just assume that the function was defined in another file. if this isn't the case, there's no way the compiler would know since it doesn't look at

the contents of more than one file at a time. linker, on the other hand, may look at multiple files and try to find references for the

functions that weren't mentioned. dividing by zero and out of memory.

Page 20: Fp201 unit1 1

Errors that prevent your program from doing what you intended it to do.

Your code may compile and run without error, but produce a result that you did not expect.

For example: • char name[2]• int month = 11

These are the hardest to find because it is not always clear where they originate.

Page 21: Fp201 unit1 1

During the stages of compilation, linking, and running, error messages may occur that require the programmer to make corrections to the program source (debugging).

Debugging is a black art. Some things to go over, though, so they’ll be concrete in our brains:• relation to testing• why debugging is hard• process• techniques• avoiding bugs

Page 22: Fp201 unit1 1

Testing and debugging go together like peas in a pod:Testing finds errors; debugging repairs

them.Together these form the

“testing/debugging cycle”: we test, then debug, then repeat.

Page 23: Fp201 unit1 1

There may be no obvious relationship between the external manifestation(s) of an error and its internal cause(s).

Symptom and cause may be in remote parts of the program.

Changes (new features, bug fixes) in program may mask (or modify) bugs.

Symptom may be due to human mistake or misunderstanding that is difficult to trace.

Bug may be triggered by rare or difficult to reproduce input sequence, program timing (threads) or other external causes.

Bug may depend on other software/system state, things others did to your systems weeks/months ago.

Page 24: Fp201 unit1 1

Execution tracing• running the program• print• trace utilities

Interface checking• check procedure parameter number/type (if not

enforced by compiler) and value• defensive programming: check inputs/results

from other modules Skipping code: comment out suspect

code, then check if error remains.

Page 25: Fp201 unit1 1

Coding style: use clear, consistent style and useful naming standards.

Document everything, from architecture and interface specification documents to comments on code lines.

Hold code reviews. Program defensively. Use/implement exception handling liberally;

think constantly about anomalous conditions.

Be suspicious of cut/paste. Consider using an integrated development

environment (IDE) with dynamic syntax checking.

Page 26: Fp201 unit1 1