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

CHAPTER 01

AN OVERVIEW OF PROGRAMMING LANGUAGES


AND PROBLEM SOLVING TECHNIQUES

1
PROGRAMMING LANGUAGES

Various programming languages enable people


to tell computers what to do
Foundation for developing applications

2
THE LANGUAGE TRANSLATION PROCESS
How are Programs Understood by the Computer?

Program written in Translator program Program written in


programming Assembler machine language
language Compiler (object code)
(source code)
Interpreter

Processed
By CPU

3
PROGRAMMING LANGUAGES
Machine Language
(first generation of programming languages)
The computers native language
Composed of binary digits (0s, 1s)
The only language that computers understand

Assembly Language
(second generation of programming languages)
One-to-one correspondence to machine language
Somewhat more user-friendly than machine language (mnemonic
rather than binary digits)
Assembler program that translates an assembly language
program into machine language

4
PROGRAMMING LANGUAGES
Procedural Languages (High Level Languages)
(third generation languages)
One instruction translates into many machine language
instructions
Programs describe the computers processing step-by-step
Closer to natural language; uses common words rather than
abbreviated mnemonics
Examples: C, Fortran, QuickBasic
Compiler - translates the entire program into machine language
Interpreter - translates and executes one source program
statement at a time

5
PROGRAMMING LANGUAGES
Nonprocedural Language
(fourth generation languages)
Allows the user to specify the desired result without having to
specify the detailed procedures needed for achieving the result
Example: data base query language - SQL
Can be used by non technical users

Natural Language Programming Languages


(fifth generation (intelligent) languages)
Translates natural languages into a structured, machine-readable
form
Are extremely complex and experimental

6
PROGRAMMING LANGUAGES

7
CURRENT PROGRAMMING LANGUAGES
Visual Programming Languages
Used within a graphical environment
Example: Visual Basic and Visual C++
Popular to non technical users

Hypertext Markup Language (HTML)


standard language used in World Wide Web
contains text, images, and other types of information such as data files,
audio, video, and executable computer programs

Componentware
Software components that may be assembled by developer as needed
Plug and Play software development

8
CURRENT PROGRAMMING LANGUAGES
Extensible Markup Language (XML)
Improved on web document functionality

Virtual Reality Modeling Language (VRML)


a file format for describing three-dimensional interactive worlds and
objects
can be used with the World Wide Web

Object-Oriented Programming Languages (OOP)


based on objects packaging data and the instructions about what to
do with that data together
Examples: Java, C++
Unified Modeling Language (UML)- modeling tool for object-oriented
systems

9
PROCESSING A HIGH LEVEL LANGUAGE
PROGRAM
Steps to execute a program written in C++:
1. Use an editor to create a program. (source program)
2. Compiler translate the program in to an equivalent
machine language. (object program)
3. The programs that you write in a high-level language are
developed using a software development kit (SDK), which
contains many programs that are useful in creating your
program. This prewritten code resides in a place called
the library.
4. Linking programs: The linker assembles all of functions
(source and systems) into final executable program.
5. The next step is to load the executable program into
the main memory for execution and a program called
loader accomplishes this.
6. The final step is to execute the program.

10
STEP IN PROGRAM DEVELOPMENT
Programming can be defined as the development of a solution to an identified
problem, and the setting up of a related series of instructions that will produce the
desired results.

Define the Problem


To help with initial analysis, the problem should be divided into three separate
components:
the inputs
the outputs
the processing steps to produce the required outputs

Outline the Solution


This initial outline is usually a rough draft of the solution and may include:
The major processing steps involved
The major subtasks (if any)
The user interface (if any)
The major control structures (e.g. repetition loops)
The major variables and record structures
The mainline logic

11
STEP IN PROGRAM DEVELOPMENT
Develop the Outline into an Algorithm
The solution outline developed in Step 2 is expanded into an algorithm: a set of precise steps that
describe exactly the tasks to be performed and the order in which they are to be carried out.

Test the Algorithm for Correctness


Most importance in the development of a program
To identify major logic errors early, so that they may be easily corrected.

Code the Algorithm into a Specific Programming Language


Only after all design considerations have been met

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 and logic errors.

Document and Maintain the program


It is an ongoing task from the initial definition of the problem to the final test result.
Documentation involves both external and internal documentation that may have been coded in the
program.
Maintenance requires using and modifying the program if the problem domain changes.

12
PROGRAMMING WITH THE PROBLEM
ANALYSIS CODING EXECUTION
CYCLE
Problem solving process

First step
Define the problem.
Outline the solution.
Design an algorithm.
Test the algorithm for correctness.

Second step
Implement the algorithm in programming
language, such as C++.
Run the program on the computer

Last step
Document and maintain the program.
WHAT IS AN ALGORITHM?
A step-by-step problem solving procedure, especially an establish,
recursive computational procedure for solving a problem in a finite
number of steps.
An algorithm has to
be clear
have a finite length
stop in finite time

There are many models supporting the development of the code:

Pseudocode
Structure Diagram and finally in C++
Flowcharts

14
WRITE A PROGRAM CALCULATING THE SUM OF
TWO NUMBERS : ADDITION
Input Processing Output

5, 10 15

1) Declare variables 3) Process


input_1 2) Assign values
input_1 = 5 sum = input_1 + input_2
input_2
sum input_2 = 10

The computer provides basic arithmetic


operations.
Assigning values to the variables

Names for our variables


15
PSEUDO CODE

Uses phrases to outline the task

Easy to read and write

Allowthe programmer to concentrate on the logic of


the problem

Structured in English language

16
PSEUDO CODE

Pseudocode is "halfway" between English and a


programming language.

It is a description of a process in detail, though not


necessarily in full sentences.

The key is to provide enough information so that


anyone could follow the instructions

Recipes are one type of pseudocode, instructions for


assembling things are another.
17
WRITING PSEUDO CODE

Write only one statement per line

Capitalize initial keyword

Indent to show hierarchy

End multiline structures

Keep statements language independent

18
WRITING PSEUDO CODE

In the example below note the words: READ and


WRITE. These are just a few of the keywords to use,
others include:

READ, WRITE, IF, ELSE, ENDIF, WHILE, ENDWHILE

Pseudocode
READ name, hoursWorked,
payRate
gross = hoursWorked * payRate
WRITE name, hoursWorked,
gross

19
PSEUDOCODE WRITE A PROGRAM
CALCULATING THE SUM OF TWO NUMBERS
Pseudocode are English-like statements that
follow a loosely defined syntax and are used to
convey the design of an algorithm.

Version 1: Version 2:
PROGRAM Add Two Numbers
PROGRAM Add Two Numbers
READ First
READ two numbers
READ Second
ADD the numbers
Sum = First + Second
WRITE the sum
WRITE Sum
END PROGRAM
END PROGRAM

20
STRUCTURE CHART

A structure chart (module chart, hierarchy


chart) is a graphic depiction of the
decomposition of a problem
It is a tool to help in software design.

It is particularly helpful on large problems.

A structure chart illustrates the partitioning of


a problem into sub problems and shows the
hierarchical relationships among the parts
STRUCTURE DIAGRAM WRITE A PROGRAM CALCULATING THE
SUM OF TWO NUMBERS
Version 1: PROGRAM
Add Two Numbers Take note:
We develop software
iteratively (meaning
READ ADD WRITE version by version),
Two Numbers Two Numbers The Sum
but the code itself
is broken in top-down
manner!!
Version 2: PROGRAM
Add Two Numbers

READ ADD WRITE


Two Numbers Two Numbers The Sum

READ READ Sum =


Input_1 Input_2 Input_1 +
Input_2
22
FLOWCHARTS WRITE A PROGRAM
CALCULATING THE SUM OF TWO NUMBERS
Input/Output (used for all I/O operations)
START
Processing (used for all arithmetic and data
transfer operations).

READ First Terminal (used to indicate the beginning


READ Second and end of a program or module).

Decision (used to test for a condition).

Sum = First + Second


Connector (used to indicate the point at
which a transfer of control operation
occurs).

WRITE Sum Predefined (used to indicate the name


process of a module to be executed).

Connecting all the symbols and showing the


STOP flow

23
MODULAR DESIGN WRITE A PROGRAM CALCULATING THE SUM OF
TWO NUMBERS

Pseudocode are more closely


to the programming language Modular Design
and for the advanced programmer.
We dont break according
Structure Diagrams are helpful to the sequence
to break the algorithm into more in which the parts are
manageable pieces. following, but rather
in its frequency of use and
Flowcharts show the workflow similarity
of the algorithm and stress on to other parts.
structured programming.

Every model has its advantages


and disadvantages. But all try to
help you to structure your code in
a top-down style and this is the
way you should implement your
algorithm.
24
STRUCTURED V/S UNSTRUCTURED PROGRAMMING

Unstructured
Structured Programming
Programming
A program is broken down Style of programming in
into small independent tasks which small and simple
that are small enough to be programs consist of only
understood easily without one main program.
having to understand the
whole program at once.
C++ CODING WRITE A PROGRAM
CALCULATING THE SUM OF TWO NUMBERS
/* Addition of 2 numbers */

#include <iostream> Where do you find now in


using namespace std; the code the steps we
have developed?
int main()
{ 1. Declaration of the
int first, second, sum; structure

cin>>first; 2. Reading the input


cin>>second;
3. Processing the data
sum = first + second;
cout<<sum<<endl; 4. Writing the output

return 0;
}

26
FLOW CHART AND ALGORITHM- ACTIVITY

Design a Flow chart and write the algorithm for


the given problems.

1. Find average of two numbers


2. Calculate area of a rectangle
3. Find square/cube of a number
4. Find whether a numbers is negative or not
5. Find whether two numbers are equal or not

27

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