chapter 5( programming) answer

24
Chapter : Basic Programming Concepts Is a series of organized instructions that directs a computer to perform tasks. Without programs, computer are useless PROGRAM Is a creation of a set of commands or instruction which directs a computer in carrying out a task. A set of words, symbols and codes that enables humans to Communication with computers. Someone who writes computer programs. PROGRAMMING PROGRAMMING LANGUAGE PROGRAMMER

Upload: smkengkilili2011

Post on 11-May-2015

2.115 views

Category:

Technology


7 download

TRANSCRIPT

Page 1: Chapter 5( programming) answer

Chapter : Basic Programming Concepts

Is a series of organized instructions that directs a computer to perform tasks. Without programs, computer are useless

PROGRAM

Is a creation of a set of commands or instruction which directs a computer in carrying out a task.

A set of words, symbols and codes that enables humans to Communication with computers.

Someone who writes computer programs.

PROGRAMMING

PROGRAMMING LANGUAGE

PROGRAMMER

Page 2: Chapter 5( programming) answer

GENERATIONS OF PROGRAMMING LANGUAGE

Provides little or no abstraction from Computer’s microprocessor.

More abstract, easier to use, & more portable across platforms.

Low level PL High Level PL

1 GL

Machine Language

Eg: Binary code

2 GL

Assembly Language

5 GL

Visual programming

Language/ natural language

Eg: Prolog, Mercury

4 GL

Non-procedural Language

Eg: SQL,NOMAD,FOCUS

3 GL

Procedural Language

Eg: PASCAL,FORTRAN,

BASIC,COBOL,C++..

Page 3: Chapter 5( programming) answer

Open programming language (OPL)

Is an embedded programming language found in portable devices that run the Symbian Operating system.

Eg: mobile telephones and PDAs.

Page 4: Chapter 5( programming) answer

Programming Approaches

-Uses a top- down design model

- whole program is broken down Into smaller sections.

Object –oriented programming (OOP)

-Type of programming approach That Combines data with functions to create object.

Ada, Pascal, Fortran Smalltalk, Java, Visual Basic, C++

Structured Programming

Examples: Examples:

Page 5: Chapter 5( programming) answer

Translator

Computer program for Translating assembly

language Into machine

Language

Used to interpret & execute Program direct

from its source Without compiling

it first.

Source code will be Converted into

Machine Code which is a file consisting Of binary

machine code that is executed On a computer.

If any errors, it record them in the program listing file.

BASIC, LOGO,

SMALLTALK

MACRO-80,Microsoft MASM C++,

PASCAL,COBOL

Examples Examples Examples

Assembler interpreter Compiler

Page 6: Chapter 5( programming) answer

5 Basic Element in programming

Data type VariablesConstants OperatorsControl

structure

Page 7: Chapter 5( programming) answer

Constant & Variables

Const Margin = 10

Differences between constant and variables

Constant variables

Margin = 10

Variable

Definition

Characteristics

Usage

Examples

Elements

Is a virtual data container that Stores information.

Is a virtual data container that Stores information.

Value is not changeableduring the Course of the program

Value can be changed anytimeduring the Course of theprogram

When you want to declaresomething that won’t change midway in your program execution.

Use variable to store data that May or will change during the Running of the program.

Page 8: Chapter 5( programming) answer

Data Types

Definition: determines the type of data a variable can store.

IntegerInteger Number value Number value does not have does not have fractional part fractional part

0, 1, 25, 99 ….0, 1, 25, 99 …. Dim Dim

Data types Definition Examples Sample usage

Double Double Contain a Contain a fractional partfractional part

41.5, 31.441.5, 31.4

String String Sequence of Sequence of characters characters

Kok Leong, Kok Leong, AmiraAmira

StringString

Boolean Boolean Consists Consists either True or either True or False False

TRUE, FALSE TRUE, FALSE

Page 9: Chapter 5( programming) answer

Operators

Operators Definition Examples/ symbols

Mathematical operators

Are notations thattell the computer To perform mathematicoperations

+, -, *, / ,

Relational Operators

LogicalOperators

Performs comparison between Two elements

Performs logical operations ,Checking the condition of two Boolean values.

=, >,<, <=, >=

AND, OR, NOT

Page 10: Chapter 5( programming) answer

ExamplesExamples

A = B A = B A = B

A >= B A <= B

Equal to Greater than Less than

Greater than or equal to

Less than or equal to

Page 11: Chapter 5( programming) answer
Page 12: Chapter 5( programming) answer
Page 13: Chapter 5( programming) answer

Logical operator

AND OR NOT

VALUE VALUE TRUTH TRUTH

VALUE VALUE

X X YY

X AND YX AND Y

0 0 0 0

00

0 0 11

00

1 1 00

00

1 1 11

11

“NOT” OPERATORS VALUE VALUE TRUTH TRUTH

VALUE VALUE

X X YY

X OR YX OR Y

0 0 0 0

00

0 0 11

11

1 1 00

11

1 1 11

11

VALUE VALUE TRUTH TRUTH

VALUE VALUE

X X NOT XNOT X

0 0

11

1 1 00

“AND” OPERATORS “OR” OPERATORS

1 REPRESENT “TRUE”, 0 REPRESENT “FALSE”

Page 14: Chapter 5( programming) answer

PSEUDO CODES PSEUDO CODES

DEF: is text only sentences that DEF: is text only sentences that describe describe

the logic and program flow of a the logic and program flow of a computer program. computer program.

Pseudo code esembles plain English.Pseudo code esembles plain English. Do not have any specific Do not have any specific

progamming language snytax and progamming language snytax and grammar.grammar.

Page 15: Chapter 5( programming) answer
Page 16: Chapter 5( programming) answer
Page 17: Chapter 5( programming) answer

Flow chartFlow chart

Begin

End

READ Length, Width, Height

DISPLAY Volume of Cuboid

Volume of cuboid= Length* Width* Height

Page 18: Chapter 5( programming) answer

ELEMENTS IN FLOWCHARTELEMENTS IN FLOWCHARTElements Description

Terminator Shows the beginning or end of a program

Flowline and arrowhead Connect symbols and indicate the sequences of operation

Input or Output Shows either an input operation (an INPUT from the user) or an output operation (PRINT some message)

Process Process to be carried out (e.g calculation)

Decision Shows a decision (or choice) to be made. The program should continue along one of two routes (e.g if…else)

Page 19: Chapter 5( programming) answer

Control structures

Definition: is a structure of statement in programming that allows the programmer to control the flow of a program.

•Linear execution

Selection control

•To make decisionBased on the situation

Given.

Repetition Control

• looping

Sequence Control

Draw flow chart For sequence

control True and false

Repeat while some Condition remains true

Page 20: Chapter 5( programming) answer

Differentiate between selection control and sequence control

Types of control structure

Execution flow

Usage

Flow chart

Sequence control Selection control

m/s 33 chapter programming

Linear execution

Execute line by line

Execute different Statement for Different conditions

To implement decision Making.

Page 21: Chapter 5( programming) answer

DEVELOP A PROGRAMDEVELOP A PROGRAM

Examples of how user apply program Examples of how user apply program development phases to solve development phases to solve problem:problem:

Page 22: Chapter 5( programming) answer

PROGRAM DEVELOPMENT

5 MAIN PHASES Of PROGRAM DEVELOPMENT

PROBLEM ANALYSIS PHASE

• interview the client, find out what the client’s need are.

PROGRAM DESIGN PHASE• design a flow chart.

Coding phase

• perform coding

• Checking error, and do debbuging

Testing and debugging phase

Documentation phase

• user manual, a clear layout, program listing

Page 23: Chapter 5( programming) answer

Syntax Error

•Wrong spelling

Logic Error

• the output do not matchfor any set

of data

Run-Time Error

• Error occurs while The program is

running Or executing.

Errors

Page 24: Chapter 5( programming) answer

The latest type of programming languages

Fifth generation languages

• Advance programming language

Natural language

• English to write a program

Open GL (Graphic Library)

• 3D/2D computer Graphic application