Introduction To Programming For Mathematics...programming language or an assembly language. An...

Post on 02-Apr-2021

19 views 0 download

Transcript of Introduction To Programming For Mathematics...programming language or an assembly language. An...

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Introduction To Programming ForMathematics

Lecture 1: Basics Of Computer Programming

Onassis1

1Department of MathematicsKNUST - Ghana

September 9, 2015

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Outline

1 Terminologies

2 Machine Language

3 Basic Concepts of ProgrammingStructured ProgrammingAlgorithm

FlowchartsModular/Top-Down Programming Design

4 Programming Problem Design Process

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Basic Terminologies

TerminologiesComputer Program: A set of instructions that direct thecomputer to perform a certain task.Computer/Programming Language: Instructions are writtenin a language understood by the computer.

Examples: C, C++, Fortran, Java, MATLAB, Python, R etc.

Programming: The art of writing a computer programProgrammer: A person who writes computer programs

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Basic Terminologies

TerminologiesComputer Program: A set of instructions that direct thecomputer to perform a certain task.Computer/Programming Language: Instructions are writtenin a language understood by the computer.

Examples: C, C++, Fortran, Java, MATLAB, Python, R etc.

Programming: The art of writing a computer programProgrammer: A person who writes computer programs

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Basic Terminologies

TerminologiesComputer Program: A set of instructions that direct thecomputer to perform a certain task.Computer/Programming Language: Instructions are writtenin a language understood by the computer.

Examples: C, C++, Fortran, Java, MATLAB, Python, R etc.

Programming: The art of writing a computer programProgrammer: A person who writes computer programs

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Basic Terminologies

TerminologiesComputer Program: A set of instructions that direct thecomputer to perform a certain task.Computer/Programming Language: Instructions are writtenin a language understood by the computer.

Examples: C, C++, Fortran, Java, MATLAB, Python, R etc.

Programming: The art of writing a computer programProgrammer: A person who writes computer programs

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Machine LanguageThe lowest-level programming language (except forcomputers that utilize programmable microcode) Machinelanguages are the only languages understood bycomputers.While easily understood by computers, machine languagesare almost impossible for humans to use because theyconsist entirely of numbers.Programmers, therefore, use either a high-levelprogramming language or an assembly language.An assembly language contains the same instructions as amachine language, but the instructions and variables havenames instead of being just numbers.Programs written in high-level languages are translatedinto assembly language or machine language by acompiler.Assembly language programs are translated into machinelanguage by a program called an assembler.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Machine LanguageThe lowest-level programming language (except forcomputers that utilize programmable microcode) Machinelanguages are the only languages understood bycomputers.While easily understood by computers, machine languagesare almost impossible for humans to use because theyconsist entirely of numbers.Programmers, therefore, use either a high-levelprogramming language or an assembly language.An assembly language contains the same instructions as amachine language, but the instructions and variables havenames instead of being just numbers.Programs written in high-level languages are translatedinto assembly language or machine language by acompiler.Assembly language programs are translated into machinelanguage by a program called an assembler.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Machine LanguageThe lowest-level programming language (except forcomputers that utilize programmable microcode) Machinelanguages are the only languages understood bycomputers.While easily understood by computers, machine languagesare almost impossible for humans to use because theyconsist entirely of numbers.Programmers, therefore, use either a high-levelprogramming language or an assembly language.An assembly language contains the same instructions as amachine language, but the instructions and variables havenames instead of being just numbers.Programs written in high-level languages are translatedinto assembly language or machine language by acompiler.Assembly language programs are translated into machinelanguage by a program called an assembler.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Machine LanguageThe lowest-level programming language (except forcomputers that utilize programmable microcode) Machinelanguages are the only languages understood bycomputers.While easily understood by computers, machine languagesare almost impossible for humans to use because theyconsist entirely of numbers.Programmers, therefore, use either a high-levelprogramming language or an assembly language.An assembly language contains the same instructions as amachine language, but the instructions and variables havenames instead of being just numbers.Programs written in high-level languages are translatedinto assembly language or machine language by acompiler.Assembly language programs are translated into machinelanguage by a program called an assembler.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Machine LanguageThe lowest-level programming language (except forcomputers that utilize programmable microcode) Machinelanguages are the only languages understood bycomputers.While easily understood by computers, machine languagesare almost impossible for humans to use because theyconsist entirely of numbers.Programmers, therefore, use either a high-levelprogramming language or an assembly language.An assembly language contains the same instructions as amachine language, but the instructions and variables havenames instead of being just numbers.Programs written in high-level languages are translatedinto assembly language or machine language by acompiler.Assembly language programs are translated into machinelanguage by a program called an assembler.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Machine LanguageThe lowest-level programming language (except forcomputers that utilize programmable microcode) Machinelanguages are the only languages understood bycomputers.While easily understood by computers, machine languagesare almost impossible for humans to use because theyconsist entirely of numbers.Programmers, therefore, use either a high-levelprogramming language or an assembly language.An assembly language contains the same instructions as amachine language, but the instructions and variables havenames instead of being just numbers.Programs written in high-level languages are translatedinto assembly language or machine language by acompiler.Assembly language programs are translated into machinelanguage by a program called an assembler.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Structured Programming

Structured Programming

Structured ProgrammingA set of rules that prescribe good style habits for theprogrammer.Key Idea : Any numerical algorithm can be composedusing the three fundamental control structures:

sequence,selection, andrepetition.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Structured Programming

Structured Programming

Structured ProgrammingA set of rules that prescribe good style habits for theprogrammer.Key Idea : Any numerical algorithm can be composedusing the three fundamental control structures:

sequence,selection, andrepetition.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Structured Programming

Structured Programming

Structured ProgrammingA set of rules that prescribe good style habits for theprogrammer.Key Idea : Any numerical algorithm can be composedusing the three fundamental control structures:

sequence,selection, andrepetition.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Algorithm

AlgorithmAn algorithm is a step-by-step procedure for finding thesolution to a problem.Commonly expressed as

Flowchart or PseudocodeFlowchart: A visual or graphical representation of analgorithm.

Employs a series of blocks and arrows, each of whichrepresents a particular operation or step in the algorithm.The arrows represent the sequence in which the operationsare implemented.

Pseudocode: Uses code-like statements in place of thegraphical symbols of the flowchart

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Algorithm

AlgorithmAn algorithm is a step-by-step procedure for finding thesolution to a problem.Commonly expressed as

Flowchart or PseudocodeFlowchart: A visual or graphical representation of analgorithm.

Employs a series of blocks and arrows, each of whichrepresents a particular operation or step in the algorithm.The arrows represent the sequence in which the operationsare implemented.

Pseudocode: Uses code-like statements in place of thegraphical symbols of the flowchart

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Algorithm

AlgorithmAn algorithm is a step-by-step procedure for finding thesolution to a problem.Commonly expressed as

Flowchart or PseudocodeFlowchart: A visual or graphical representation of analgorithm.

Employs a series of blocks and arrows, each of whichrepresents a particular operation or step in the algorithm.The arrows represent the sequence in which the operationsare implemented.

Pseudocode: Uses code-like statements in place of thegraphical symbols of the flowchart

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Algorithm

AlgorithmAn algorithm is a step-by-step procedure for finding thesolution to a problem.Commonly expressed as

Flowchart or PseudocodeFlowchart: A visual or graphical representation of analgorithm.

Employs a series of blocks and arrows, each of whichrepresents a particular operation or step in the algorithm.The arrows represent the sequence in which the operationsare implemented.

Pseudocode: Uses code-like statements in place of thegraphical symbols of the flowchart

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Algorithm

AlgorithmAn algorithm is a step-by-step procedure for finding thesolution to a problem.Commonly expressed as

Flowchart or PseudocodeFlowchart: A visual or graphical representation of analgorithm.

Employs a series of blocks and arrows, each of whichrepresents a particular operation or step in the algorithm.The arrows represent the sequence in which the operationsare implemented.

Pseudocode: Uses code-like statements in place of thegraphical symbols of the flowchart

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Algorithm

AlgorithmAn algorithm is a step-by-step procedure for finding thesolution to a problem.Commonly expressed as

Flowchart or PseudocodeFlowchart: A visual or graphical representation of analgorithm.

Employs a series of blocks and arrows, each of whichrepresents a particular operation or step in the algorithm.The arrows represent the sequence in which the operationsare implemented.

Pseudocode: Uses code-like statements in place of thegraphical symbols of the flowchart

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Flowchart Symbols

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Sequential Flow

Sequential FlowThe computer code implemented one instruction at a time.Generically expressed as a flowchart or as pseudocode asfollows:

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Sequential Flow

Sequential FlowThe computer code implemented one instruction at a time.Generically expressed as a flowchart or as pseudocode asfollows:

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Selection/Branching/Switching/Decision

BranchingProvides a means to split the program’s flow into branchesbased on the outcome of a logical condition.Two most fundamental ways for doing this.

Single-alternative selection(IF/THEN) andDouble-alternative selection (IF/THEN/ELSE).

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Selection/Branching/Switching/Decision

BranchingProvides a means to split the program’s flow into branchesbased on the outcome of a logical condition.Two most fundamental ways for doing this.

Single-alternative selection(IF/THEN) andDouble-alternative selection (IF/THEN/ELSE).

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Selection/Branching/Switching/Decision

BranchingProvides a means to split the program’s flow into branchesbased on the outcome of a logical condition.Two most fundamental ways for doing this.

Single-alternative selection(IF/THEN) andDouble-alternative selection (IF/THEN/ELSE).

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Flowchart and Pseudocode for Single-Alternative SelectionConstructs

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Flowchart and Pseudocode for Double-Alternative SelectionConstructs

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Flowchart and Pseudocode for Multiple-Alternative SelectionConstructs

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Flowchart and Pseudocode for Select Case Constructs

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Repetition/LoopingProvides a means to implement instructions repeatedly.The resulting constructs, called loops, come in two"flavors" distinguished by how they are terminated.The Two Major Forms are Decision loop andCount-Controlled loop.

A Decision/Break Loop : Structure repeats until a logicalcondition is true.

Termination based on the result of a logical condition.

A Count-Controlled or DOFOR loop: Performs a specifiednumber of repetitions, or iterations.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Repetition/LoopingProvides a means to implement instructions repeatedly.The resulting constructs, called loops, come in two"flavors" distinguished by how they are terminated.The Two Major Forms are Decision loop andCount-Controlled loop.

A Decision/Break Loop : Structure repeats until a logicalcondition is true.

Termination based on the result of a logical condition.

A Count-Controlled or DOFOR loop: Performs a specifiednumber of repetitions, or iterations.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Repetition/LoopingProvides a means to implement instructions repeatedly.The resulting constructs, called loops, come in two"flavors" distinguished by how they are terminated.The Two Major Forms are Decision loop andCount-Controlled loop.

A Decision/Break Loop : Structure repeats until a logicalcondition is true.

Termination based on the result of a logical condition.

A Count-Controlled or DOFOR loop: Performs a specifiednumber of repetitions, or iterations.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Repetition/LoopingProvides a means to implement instructions repeatedly.The resulting constructs, called loops, come in two"flavors" distinguished by how they are terminated.The Two Major Forms are Decision loop andCount-Controlled loop.

A Decision/Break Loop : Structure repeats until a logicalcondition is true.

Termination based on the result of a logical condition.

A Count-Controlled or DOFOR loop: Performs a specifiednumber of repetitions, or iterations.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Repetition/LoopingProvides a means to implement instructions repeatedly.The resulting constructs, called loops, come in two"flavors" distinguished by how they are terminated.The Two Major Forms are Decision loop andCount-Controlled loop.

A Decision/Break Loop : Structure repeats until a logicalcondition is true.

Termination based on the result of a logical condition.

A Count-Controlled or DOFOR loop: Performs a specifiednumber of repetitions, or iterations.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Flowchart and Pseudocode for Repetition: DOEXIT or break loop

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Algorithm

Flowchart and Pseudocode for Repetition: Count-Controlled or forloop

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Modular/Top-Down Programming Design

Modular/Top-Down Programming Design

Programming Problem Design ProcessDecomposition of computer programs into smallsubprograms, or modules, that can be developed andtested separately.Advantages

Makes the underlying logic easier to devise and tounderstand for both the developer and the user.Development is facilitated because each module can beperfected in isolation.Increases the ease with which a program can be debuggedand tested because errors can be more easily isolated.Program maintenance and modification are facilitated.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Modular/Top-Down Programming Design

Modular/Top-Down Programming Design

Programming Problem Design ProcessDecomposition of computer programs into smallsubprograms, or modules, that can be developed andtested separately.Advantages

Makes the underlying logic easier to devise and tounderstand for both the developer and the user.Development is facilitated because each module can beperfected in isolation.Increases the ease with which a program can be debuggedand tested because errors can be more easily isolated.Program maintenance and modification are facilitated.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Modular/Top-Down Programming Design

Modular/Top-Down Programming Design

Programming Problem Design ProcessDecomposition of computer programs into smallsubprograms, or modules, that can be developed andtested separately.Advantages

Makes the underlying logic easier to devise and tounderstand for both the developer and the user.Development is facilitated because each module can beperfected in isolation.Increases the ease with which a program can be debuggedand tested because errors can be more easily isolated.Program maintenance and modification are facilitated.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Modular/Top-Down Programming Design

Modular/Top-Down Programming Design

Programming Problem Design ProcessDecomposition of computer programs into smallsubprograms, or modules, that can be developed andtested separately.Advantages

Makes the underlying logic easier to devise and tounderstand for both the developer and the user.Development is facilitated because each module can beperfected in isolation.Increases the ease with which a program can be debuggedand tested because errors can be more easily isolated.Program maintenance and modification are facilitated.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Modular/Top-Down Programming Design

Modular/Top-Down Programming Design

Programming Problem Design ProcessDecomposition of computer programs into smallsubprograms, or modules, that can be developed andtested separately.Advantages

Makes the underlying logic easier to devise and tounderstand for both the developer and the user.Development is facilitated because each module can beperfected in isolation.Increases the ease with which a program can be debuggedand tested because errors can be more easily isolated.Program maintenance and modification are facilitated.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Modular/Top-Down Programming Design

Flowchart of Modular/Top-Down Programming Design

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Programming Problem Design Process

Programming Problem Design Process1 Clearly state the problem that you are trying to solve.2 Define the inputs required by the program and the outputs

to be produced by the program.3 Design the algorithm that you intend to implement in the

program.4 Turn the algorithm into desired computer programming

language(e.g. MATLAB) statements.5 Test the resulting program.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Programming Problem Design Process

Programming Problem Design Process1 Clearly state the problem that you are trying to solve.2 Define the inputs required by the program and the outputs

to be produced by the program.3 Design the algorithm that you intend to implement in the

program.4 Turn the algorithm into desired computer programming

language(e.g. MATLAB) statements.5 Test the resulting program.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Programming Problem Design Process

Programming Problem Design Process1 Clearly state the problem that you are trying to solve.2 Define the inputs required by the program and the outputs

to be produced by the program.3 Design the algorithm that you intend to implement in the

program.4 Turn the algorithm into desired computer programming

language(e.g. MATLAB) statements.5 Test the resulting program.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Programming Problem Design Process

Programming Problem Design Process1 Clearly state the problem that you are trying to solve.2 Define the inputs required by the program and the outputs

to be produced by the program.3 Design the algorithm that you intend to implement in the

program.4 Turn the algorithm into desired computer programming

language(e.g. MATLAB) statements.5 Test the resulting program.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

Programming Problem Design Process

Programming Problem Design Process1 Clearly state the problem that you are trying to solve.2 Define the inputs required by the program and the outputs

to be produced by the program.3 Design the algorithm that you intend to implement in the

program.4 Turn the algorithm into desired computer programming

language(e.g. MATLAB) statements.5 Test the resulting program.

Terminologies Machine Language Basic Concepts of Programming Programming Problem Design Process

The End!!!Further questions/contributions are welcomeThanksOnassis