22
Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Embed Size (px)

Citation preview

Page 1: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Introduction to programming

Carl SmithNational Certificate

Year 2 – Unit 4

Page 2: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Unit objectives Apply simple analysis and design

techniques to the software development process.

Develop basic high-level code using an appropriate procedural programming language.

Use suitable testing methods to ascertain the correctness of a working piece of code.

Produce appropriate documentation for a given program application.

Page 3: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Programming languages

Pascal is one language among others such as:-C, C++, VB, JAVA, COBOL, ADA, BASIC, Fortran…Each has strengths and weaknesses for various tasks, for example COBOL is ideal for data processing

Page 4: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Why Pascal? Experts consider Pascal is ideal for

students studying computer science courses because:- It forces structure, very “elegant” “Easy” to learn Very powerful

Page 5: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Blaise Pascal, 1623-1662

The Pascal language was named after the 17th century mathematician, Blaise Pascal who invented a calculating machine called “the Pascaline” which could add and subtract and worked with eight rotating gears. Tax clerks of the era viewed it as a threat to their jobs and it was never adopted!

Page 6: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Program development

Good program development is performed in 4 main steps…

(which match the unit objectives - strangely…!)

Analy se

Test

W riteDoc ument

Page 7: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Program development…In fact there are 6 steps:-1. Analyse the problem2. Develop algorithm3. Write code4. Run the program5. Test the results6. Document the program

} Step 2

Page 8: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Analysis Phase Analysis is not a trivial task Before you can code you need to know

exactly what you are to do You need a clear and precise statement of

what is to be done You need to understand what data is

available and what is to be assumed You need to know what output is desired

and the form it should take

Page 9: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Development (Develop/Write/Run) Phase Develop an Algorithm, which is:-

“A finite sequence of effective statements that when applied to a problem, will solve it”

Write code for the program when the algorithm solves the problem

(Compile) and Run the program:-At this point you may discover typing or

logic errors!...

Page 10: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Testing phase Test that the results are correct and in the

form you like Prove that your program produces the

correct solution in all cases:-e.g. with arithmetic operations this may mean

checking with a calculator or even pencil and paper!

After this phase you may need to go back to the development or even analysis phases so the whole process becomes a “cycle”

Page 11: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Documentation phase It is very important to fully document a

working program He writer knows how the program works

(hopefully!) but if others are to modify it they must know the logic used

Documentation can also be included in the development phase as remarks within the pseudo and actual code

Page 12: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Developing Algorithms Algorithms for solving problems can be

developed by:- Stating the problem Dividing the problem into major sub-tasks Dividing each sub-task into smaller tasks Repeating the process until each task is easily

solved This is known as “Top Down” design

Page 13: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Software “Life-Cycle” Analysis Design Coding Testing/Verification Maintenance Obsolescence

Page 14: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

What is programming? Giving the computer a logical set of

instructions to perform a specific task

That is, taking the design algorithm and converting it to code that the computer “understands”

Page 15: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Compiled v Interpreted Languages either run “Interpreted” that is

each line of code is interpreted into pseudo machine code (binary) at run time

Or Compiled, which is the whole program is compiled, prior to running it, into pseudo machine code

Interpreted languages tend to be slower in execution but are easier to develop and debug because the interpreter is available to pin point errors at run time

Pascal is a compiled language but the compiler is part of the “Turbo Pascal” development environment

Page 16: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Turbo Pascal 7 MSDOS based environment Therefore 8.3 filenames Support for the mouse but mainly

used via the keyboard Runs in a window or full screen

under Windows 95/98 or 2000

Page 17: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Turbo Pascal v7 – Main

Page 18: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Turbo Pascal v7 - Editor

Page 19: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Output name program

Page 20: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Program Components Remarks – “Self documenting code” Program Structure Declarations – Variables/Constants & Data

Types Input, Output & Formatting Arrays Decisions – “IF” Iteration - Looping Arithmetic and regular expressions Commands, Procedures and Functions :–

In Built and User Defined

} “Nesting”

Page 21: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Pascal - Program StructureProgram <name>;Uses Crt; - output to screenConst<list of constants>Var<list of variables><list of subprograms>BEGIN

END.

}}

Program Name

Declarationsection

Executablesection

Page 22: Introduction to programming Carl Smith National Certificate Year 2 – Unit 4

Summary We covered:-

National Certificate Unit 4 objectivesThe software development cycleThe software life cycleIntro to Turbo Pascal 7Program Elements and structure

Any Questions?