lesson 27 Creating Computer Programs This lesson includes

  • Slides: 21
Download presentation
lesson 27 Creating Computer Programs

lesson 27 Creating Computer Programs

This lesson includes the following sections: • What is a Computer Program? • How

This lesson includes the following sections: • What is a Computer Program? • How Programs Solve Problems • Two Approaches: Structured & Object-Oriented Programming

What is a Computer Program? • Files • Hardware/Software Interaction

What is a Computer Program? • Files • Hardware/Software Interaction

What is a Computer Program? - Files Typically, a program is stored as a

What is a Computer Program? - Files Typically, a program is stored as a collection of files. Some common file types used in programs are: • Executable (. EXE) files actually send commands to the processor. • Dynamic Link Library (. DLL) files are partial. EXE files. • Initialization (. INI) files contain configuration information for a program. • Help (. HLP) files contain information for the user.

What is a Computer Program? Hardware/Software Interaction • The program tells the CPU to

What is a Computer Program? Hardware/Software Interaction • The program tells the CPU to process interrupts, or sets of steps the CPU must follow to perform a task. • To control hardware, a program must be written in binary numbers (1 s and 0 s). This code is called machine code or machine language. • Programmers use programming languages to write code in nearly human language. The resulting description is called source code. • Compilers and interpreters translate a program into object code, the binary version of source code.

How Programs Solve Problems • Program Control Flow • Algorithms • Heuristics • Common

How Programs Solve Problems • Program Control Flow • Algorithms • Heuristics • Common Flow Patterns • Variables and Functions

How Programs Solve Problems – Program Control Flow • The order in which program

How Programs Solve Problems – Program Control Flow • The order in which program statements are executed is called program control flow. • To determine program control flow, programmers may use a flowchart to map the program's sequence. • Programmers may also create a simple text version of a program's code – called pseudocode – to determine how the program will flow.

This flowchart shows that the sequence can vary depending on conditions.

This flowchart shows that the sequence can vary depending on conditions.

How Programs Solve Problems - Algorithms • An algorithm is a set of steps

How Programs Solve Problems - Algorithms • An algorithm is a set of steps that always lead to a solution. The steps are always the same, whether the problem is being solved manually or with a PC. • A computer program may contain thousands of algorithms, each one devoted to a single task. • An algorithm, for example, will find the highest point in a mountain range by comparing all the points until the highest one is found.

no

no

How Programs Solve Problems - Heuristics • If a problem is too complex to

How Programs Solve Problems - Heuristics • If a problem is too complex to be solved by an algorithm, a programmer may try to solve it by using heuristics. • Heuristics are like algorithms, and will always find a solution to a problem. But unlike algorithms, heuristics are not guaranteed to find the best possible solution. • A heuristic, for example, may find the highest point in a mountain range by comparing random points, but this process may never find the highest one.

How Programs Solve Problems Common Flow Patterns • To determine when and where to

How Programs Solve Problems Common Flow Patterns • To determine when and where to pass program control, a developer may use conditional statements or loops. • A conditional statement determines whether a condition is true. If so, control flows to the next part of the program. • A loop repeats again and again until a condition is met. Control then passes to another part of the program.

How Programs Solve Problems Variables and Functions • A variable is a named placeholder

How Programs Solve Problems Variables and Functions • A variable is a named placeholder for data that is being processed. Programs contain variables to hold inputs from users, for example. • A function is a set of steps that are followed to perform a specific task. By assembling a collection of functions together, a developer can build a complete program.

Two Approaches: Structured & Object-Oriented Programming Early programmers allowed control to pass from one

Two Approaches: Structured & Object-Oriented Programming Early programmers allowed control to pass from one part of a program to another by using goto statements. Control would "go to" a different part of the program when conditions allowed. Goto statements cause programs to become very complex. To eliminate their use, programmers developed two approaches to development: • Structured programming • Object-oriented programming

This type of programming has fallen into disfavor.

This type of programming has fallen into disfavor.

Two Approaches: Structured & Object-Oriented Programming - Structured Programming Structured programming uses three types

Two Approaches: Structured & Object-Oriented Programming - Structured Programming Structured programming uses three types of control structures to make program control flow more predictable: • Sequence structure defines the default control flow. • Selection structures are built around conditional statements. • Repetition (looping) structures use loops, which execute according to the results of conditional statements.

Two Approaches: Structured & Object-Oriented Programming - Object-Oriented Programming • In object-oriented programming (OOP),

Two Approaches: Structured & Object-Oriented Programming - Object-Oriented Programming • In object-oriented programming (OOP), programs are built from blocks of code, called objects. Each object has functions and characteristics (attributes), and can contain (encapsulate) other objects. • Objects that share common attributes can be grouped into classes. Classes can be divided into subclasses. • In OOP, objects communicate with one another by exchanging messages.

lesson 27 Review • Define the term computer program. • Describe the use of

lesson 27 Review • Define the term computer program. • Describe the use of flowcharts and pseudocode in programming. • Identify two ways in which a program can work toward a solution. • Differentiate the two main approaches to computer programming. • List and describe three elements of object-oriented programming.