Вы находитесь на странице: 1из 21

2 Problem-solving in a Computer

ES 26 Introduction to Computer Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

1
Solamo ver 1.1

Objectives

Describe what programmers DO and DON'T DO Explain how programmers define a problem, plan the solution, and then code, test, and document the program List and describe the levels of programming languages: machine, assembly, high level, very high level, and natural Introduce the Java Language
ES 26 Introduction to Computer Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

2
Solamo ver 1.1

Programming Terminologies

Program

is a set of detailed, step-by-step instructions that directs the computer to do what you want it to do is a set of rules that provides a way of telling the computer what operations to perform

Programming language

ES 26 Introduction to Computer Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

3
Solamo ver 1.1

The Programming Process

Five main steps


Defining the problem Planning the solution Coding the program Testing the program Documenting the program

ES 26 Introduction to Computer Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

4
Solamo ver 1.1

Defining the Problem

Develop a written agreement that specifies:


The objects (and classes) that are part of the project or problem domain The properties (and attributes) of the identified objects The responsibility (or operations) of the identified objects The relationships (or collaborations) of the identified objects The scenarios of how the objects interact with one another
Return ES 26 Introduction to Computer Programming Source: A Recipe for Object-oriented Design (http://max.cs.kzoo.edu/AP/OOD/OODPresentation) Lesson 03- Getting to Know the Environment 5 Lesson 02- Problem-solving in a Computer Solamo ver 1.1

Planning the Solution

Algorithm

Is a detailed, step-by-step solution to the problem

Several tools help plan the algorithm Desk-check the solution

Carry out each step of the algorithm with pencil and paper

ES 26 Introduction to Computer Return Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

6
Solamo ver 1.1

Planning Tools
Class Diagram

is a pictorial representation of the objects and/or classes

Source: JEDI- Software Engineering Student's Course Materials

ES 26 Introduction to Computer Next Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

7
Solamo ver 1.1

Planning Tools
Flowchart

is a pictorial representation internal behavior of the objects and classes

ES 26 Introduction to Computer Next Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

8
Solamo ver 1.1

Planning Tools

Pseudocode Is an English-like specification of the internal behavior of the object


Begin Address envelope Fold letter Place letter in envelope if NOT(have stamp) then Borrow Stamp Place Stamp in envelope End
ES 26 Introduction to Computer Return Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer 9
Solamo ver 1.1

Coding the Program


Translating the class from the planning stage into a formal programming language All languages have syntax rules

Similar to grammatical rules The computer will reject a program with even a minor syntax error

Programs can be keyed into the computer by using a text editor

ES 26 Introduction to Computer Return Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

10
Solamo ver 1.1

Testing the Program

Two phases of testing the program

Translation

Converting the program you wrote into the binary instructions the CPU understands Identifying and correcting logic errors in the program

Testing and Debugging

ES 26 Introduction to Computer Return Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

11
Solamo ver 1.1

Translation

ES 26 Introduction to Computer Return Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

12
Solamo ver 1.1

Documenting the Program


Materials are generated at each part of the process Common examples of documentation

Flowchart and/or pseudocode Comments within the source code (using javadocs) Testing procedures Layouts of input and output records A narrative description of the program

ES 26 Introduction to Computer Return Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

13
Solamo ver 1.1

Levels of Languages

Lower-level languages

more like the 0s and 1s the computer itself uses more like the languages people use Divided into five generations

Higher-level languages

ES 26 Introduction to Computer Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

14
Solamo ver 1.1

Five Generations of Languages


Machine language Assembly languages High-level languages Very high-level languages Natural languages

ES 26 Introduction to Computer Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

15
Solamo ver 1.1

Machine Language

Programs and memory locations are written in strings of 0s and 1s Problems with machine languages

Programs are difficult to write and debug Each computer has its own machine language

Only option available to early programmers

ES 26 Introduction to Computer Return Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

16
Solamo ver 1.1

Assembly Languages

Substitute mnemonic codes for 0s and 1s


For example, A for add, C for compare, etc. Use names rather than binary addresses for memory locations

Require an assembler to translate the program into machine language Still used for programming chips and writing utility programs

ES 26 Introduction to Computer Return Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

17
Solamo ver 1.1

High-Level Languages

Transformed programming

Programmers could focus on solving problems rather than manipulating hardware Programs could be written and debugged much more quickly

Requires a compiler to convert the statements into machine language

Each computer has its own version of a compiler for each language

ES 26 Introduction to Computer Return Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

18
Solamo ver 1.1

Very High-Level Languages


Also called fourth-generation languages (4GLs) Considered nonprocedural languages


The programmer specifies the desired results, and the language develops the solution Programmers can be about 10 times more productive using a fourth-generation language than a third-generation language

ES 26 Introduction to Computer Return Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

19
Solamo ver 1.1

Natural Languages

Resemble written or spoken English

Programs can be written in a natural syntax, rather than in the syntax rules of a programming language

The language translates the instructions into code the computer can execute
ES 26 Introduction to Computer Return Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer

20
Solamo ver 1.1

Java Programming Language Created by James Gosling


of Sun Microsystems /* Prints a message on the screen */ Motivation of the language import javax.swing.JOptionPane.*; was the need to have a platform-independent public class Hello{ public static void language that could be main( String[] args ){ embedded in various consumer electronic JOptionPane.showMessageDialog (null, Hello, World!); products like toasters and } refrigerators. } Initially called Oak; it was changed because there was a programmming ES language called Oak. 26 Introduction to Computer
Programming Lesson 03- Getting to Know the Environment Lesson 02- Problem-solving in a Computer 21
Solamo ver 1.1

Вам также может понравиться