Presentation on theme: "Creating Computer Programs lesson 27. This lesson includes the following sections: What is a Computer Program? How Programs Solve Problems Two Approaches:"— Presentation transcript:
This lesson includes the following sections: What is a Computer Program? How Programs Solve Problems Two Approaches: Structured & Object-Oriented Programming
Files Hardware/Software Interaction What is a Computer Program?
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.
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 (1s and 0s). 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. What is a Computer Program? - Hardware/Software Interaction
Program Control Flow Algorithms Heuristics Common Flow Patterns Variables and Functions How Programs Solve Problems
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. How Programs Solve Problems – Program Control Flow
This flowchart shows that the sequence can vary depending on conditions.
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. How Programs Solve Problems - Algorithms
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 - Heuristics
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 - Common Flow Patterns
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. How Programs Solve Problems - Variables and Functions
Structured programming 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: Two Approaches: Structured & Object-Oriented Programming
This type of programming has fallen into disfavor.
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. Structured programming uses three types of control structures to make program control flow more predictable: Two Approaches: Structured & Object-Oriented Programming - Structured 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. Two Approaches: Structured & Object-Oriented Programming - Object-Oriented Programming
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. lesson 27 Review