computer programming contents introduction to operating systems introduction to programming...

33
Computer Programming

Upload: adrian-shelton

Post on 21-Jan-2016

237 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Computer Programming

Page 2: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

CONTENTS

• Introduction to Operating Systems• Introduction to programming languages• Introduction to perl programming language• Programming skills in perl• Perl applications in bioinformatics

Page 3: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Software Categories

• System SW– Programs written for computer systems

• Compilers, operating systems, …

• Application SW– Programs written for computer users

• Word-processors, spreadsheets, & other application packages

Page 4: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Operating system

• The set of software that controls the overall operation of a computer system, typically by performing such tasks as memory allocation, job scheduling, and input/output control

• Software designed to control the hardware of a specific data-processing system in order to allow users and application programs to make use of it.

Page 5: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

OS Tasks

The operating system's tasks, in the most general sense, fall into six categories:i. Processor managementii. Memory managementiii. Device managementiv. Storage managementv. Application interfacevi. User interface

Page 6: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Language

• The purpose of language is simply that it must convey meaning. (Confucius)

• That which can be said, can be said clearly. (Wittgenstein,1963)

• A program is a specification of a computation. A programming language is a notation for writing programs.(Sethi,89)

Page 7: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

7

What is a programming language?

• A language that is intended for the expression of computer programs and that is capable of expressing any computer program.

Page 8: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

What is Programming

• Program – a very specific set of instructions (or command lines) that making a computer do what you want it to do

• Programming – the process of creating a program– the development of a solution to an identified program,

and setting up of a related series of instructions which, when directed through computer hardware, will produce the desired results

Page 9: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Differences or Similarities

• Natural Language– Grammar– Vocabulary– Sentences

• Programming Language– Syntax– Objects, data types– Commands

Page 10: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Steps in program development

1. Define the problem2. Outline the solution(pseudocode)3. Develop the outline into an algorithm4. Test the algorithm for correctness5. Code the algorithm into a specific

programming language6. Run the program on the computer7. Document and maintain the program

Page 11: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Define the Problem

• Divide the problem into three components (called IPO):

– Inputs – what do you have?– Outputs – what do you want to have?– Processing

• how do you go from inputs to outputs?

• A defining diagram is recommended

Page 12: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Outline the Solution

• The major processing steps involved

• The major subtasks (if any)

• The major control structures (e.g. repetition loops)

• The major variables and record structures

• The mainline logic

Page 13: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Develop the Outline into an Algorithm

• Algorithm is a set of precise steps that describe exactly the tasks to be performed, and the order in which they are to be carried out

• Pseudocode (a form of structured English) is used to represent the solution algorithm

Page 14: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Test the Algorithm for Correctness

• The main purpose of desk checking the algorithm is to identify major logic errors early, so that they may be easily corrected

• Test data needs to be walked through each step in the algorithm, to check that the instructions described in the algorithm will actually do what they are supposed to

Page 15: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Code the Algorithm into a Specific Programming Language

• Only after all design considerations have been met

should you actually start to code the program into

your chosen programming language (e.g. Visual

Basic, Java, C++)

Page 16: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Run the Program on the Computer

• This step uses a program compiler and programmer-designed test data to machine test the code for syntax errors

• Program complier translate high-level languages (e.g. VB) to low-level machine language before execution

Page 17: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Document and Maintain the Program

• Not the last step in the program development process

• An ongoing task from the initial definition of the problem to the final test result

• Involves both external documentation (such as hierarchy charts) and internal documentation that may have been coded in the program

Page 18: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

How do Programming Languages Differ?

Common Constructs:• basic data types (numbers, etc.); variables;

expressions; statements; keywords; control constructs; procedures; comments; errors ...

Uncommon Constructs:• type declarations; special types (strings, arrays,

matrices, ...); sequential execution; concurrency constructs; packages/modules; objects; general functions; generics; modifiable state; ...

Page 19: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Pseudocode vs Algorithm• Pseudocode is a compact and informal high-level description of a

computer programming algorithm that uses the structural conventions of some programming language, but is intended for human reading rather than machine reading.

• Algorithm Procedure that produces the answer to a question or the solution to a problem in a finite number of steps. In mathematics, computing, and related subjects, an algorithm is a sequence of finite instructions, often used for calculation and data processing. It is formally a type of effective method in which a list of well-defined instructions for completing a task will, when given an initial state, proceed through a well-defined series of successive states, eventually terminating in an end-state.

Page 20: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Problem 1

A program is required to read three numbers, add them together and print their total.

Page 21: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

• Defining diagram

Input Processing Output

Number1Number2Number3

Prompt for input numbers

total

Get input numbers

Apply addition

Display total

Page 22: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Solution Pseudocode

Begin ProgramGet number1Get number2Get number3Total = number1 + number2 + number3Display total

End Program

Page 23: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Problem 2

• A program is required to prompt the terminal operator for the maximum and minimum temperature readings on a particular day, accept those readings as integers, and calculate and display to the screen the average temperature, calculated by (maximum temperature + minimum temperature)/2.

Page 24: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

• Defining diagram

Input Processing Output

Max_tempMin_temp

Prompt for temperaturesGet temperaturesCalculate average temperatureDisplay average temperature

Avg_temp

Page 25: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Solution Pseudocode

Begin programGet max_temp, min_tempAvg_temp= (max_Temp + min_temp)/2Output avg_temp to the screen

End Program

Page 26: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Problem 3

• Calculate the circumference and area of a circle

Page 27: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

• Defining diagram

Input Processing Output

Radiuspi

Get radius, piCalculate circumference = 2 * P I* radiusCalculate area=PI * radius ^ 2

Display circumference, area

Circumference

area

Page 28: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Solution Pseudocode

Begin program

get radius, PI

circumference = 2 * P I* radius

area=PI * radius * radius

display circumference, area

End program

Page 29: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

29

Attributes of a good language

1. Clarity, simplicity, and unity– Have a minimum number of different concepts, with the

rules for their combination, simple and regular (conceptual integrity).

– readability2. Orthogonality

– Being able to combine various features of a language in all possible combinations.

3. Support for abstraction

Page 30: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

30

Attributes of a good language

4. Ease of program verification– Proof of correctness, desk checking, test– Simplicity of semantic and syntax

5. Programming environment6. Portability of programs7. Cost of use

– Program execution– Program translation– Program creation, testing, and use– Program maintenance

Page 31: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Jazayeri 31

Attributes of a good language (another view: to make a software reliable, maintainable, efficient)

• Reliability– Writability– Readability– Simplicity– Safety (no goto, no pointers)– Robustness (undesired events can be trapped, like

arithmetic overflow, invalid inputs)• Maintainability

– Factoring (modularity)– Locality

• Efficiency

Page 32: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Can you answer these questions?

• What is an OS?• PL?• Pseudocode vs Algorithm?• Steps involved in programming?• Attributes of good PL?• How do PL differ?• Write pseudocode for a given problem?

Page 33: Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming

Assignment

• Uses of internet as biologists• Single page