0% found this document useful (0 votes)
22 views

C ++ Wsu

Uploaded by

hachalu50
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

C ++ Wsu

Uploaded by

hachalu50
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

CHAPTER -1

INTRODUCTION
TO
PROGRAMMING

1
PROBLEM SOLVING
A problem as a question or situation that presents uncer-
tainty or difficulty.
For example: Selling a product in the shop is the task
here.
 The problem is to sell Or how a sales person sells a product in the
shop.
For a sale to happen in a shop you should go through the
following:
 Determine what the unit price of the product is.
 Count the quantity, (how many of the product) and
 Calculate the total amount to be paid by the customer.
 Calculate the change that you have to give back to the customer.

Chapter1: Introduction to Programming 2


PROBLEM SOLVING USING COMPUTER
Computers can be programmed to do many com-
plicated tasks at very high speeds.
We can use computers as a tool in problem solving
if a problem has:
It has extensive input and output.
Its method of solution is too complicated to implement
manually.
If done manually, it takes an excessively long time to
solve.
To use the same method of solution to solve the same
problem with different inputs.

Chapter1: Introduction to Programming 3


Programming refers to the process of making (enabling) a
machine to perform a particular task by giving it instruc-
tions (programs) and inputs.
 It is the process of solving a problem using computers.

A program is a detailed set of instructions written in a


programming language that directs the computer to solve a
problem.
For the instructions to be carried out, a computer must ex-
ecute a program
 that is, the computer reads the program, and then follows the steps

encoded in the program in a precise order until completion


Chapter1: Introduction to Programming 4
SOFTWARE DEVELOPMENT PHASE
Software development method is a method of develop-
ing computer programs to solve problems using a com-
puter.
The software development method consists of the follow-
ing steps:

Chapter1: Introduction to Programming 5


SOFTWARE DEVELOPMENT PHASE cont’d..
Requirements Specification
 Consists of understanding exactly
 what the problem is,
 what is needed to solve it,
 what the solution should provide, and

 if there are constraints and conditions.

Chapter1: Introduction to Programming 6


SOFTWARE DEVELOPMENT PHASE cont’d..
Analysis
 In the analysis phase we should identify the follow-
ing:
 Inputs to the problem, their form, and the input media to
be used
 Outputs expected from the solution, their form, and the
output media to be used
 Any special constraints or conditions
 Formulas or equations to be used

Chapter1: Introduction to Programming 7


SOFTWARE DEVELOPMENT PHASE cont’d..
Design
 The next step is to design a method of solution
for the problem.
 A method of solution is also called algorithm
 Algorithm is a series of steps to be performed in
a specific logical order.
 Algorithm can be designed by using either:
 Pseudo codes or
 Flow charts

Chapter1: Introduction to Programming 8


SOFTWARE DEVELOPMENT PHASE cont’d..
Implementation
 Translate each step of the algorithm into a language
statement.
 Ends up with a computer program.
 A computer program is a sequence of a finite number
of statements expressed in a programming language in a
specific logical order that, when executed, produce the
solution for a problem.
 This phase consists of
 Choosing the appropriate programming language and
 Writing a program following the syntax of the language exactly.

Chapter1: Introduction to Programming 9


SOFTWARE DEVELOPMENT PHASE cont’d..
Testing and Verification
 Check the correctness of the program and verify that the
program will do what is expected to do.
 Program Verification
 is the process of ensuring that a program meets user require-
ments. One of the techniques that can be used for program veri-
fication is Program Testing.
 Program Testing
 is the process of executing a program to demonstrate its correct-
ness.
 A program must be tested using a sufficiently large sam-
ple of test data sets such that every logical path in the
program is traversed at least once.

Chapter1: Introduction to Programming 10


SOFTWARE DEVELOPMENT PHASE cont’d..
Testing the program consists of :
Desk-checking- is simply reading through, or checking
the program to make sure that it is free of errors and
that the logic works
Debugging the program- means to detect, locate and
remove all errors in a computer program
Run real-world data
 Testing the program with real data and real users
 It is also advisable to test it with faulty or incomplete or over-
whelming data

Chapter1: Introduction to Programming 11


SOFTWARE DEVELOPMENT PHASE cont’d..
Program Documentation
 Prepare documents that explain
 how the program works and
 how to use it.
 Program documentation consists of these elements:
 A concise requirements specification.
 Descriptions of problem inputs, expected outputs, constraints,
and applicable formula
 A pseudocode or flowchart for its algorithm.
 A source program listing.
 A hard copy of a sample test runs of the program.
 A user’s guide explaining to non programmer users how the pro-
gram should be used.

Chapter1: Introduction to Programming 12


PROGRAM ALGORITHM
Algorithm:
is a sequence of a finite number of steps arranged in a

specific logical order which is used to develop the solu-


tion for a problem
Pseudocodes and flowcharts can be used to develop

algorithms.

Chapter1: Introduction to Programming 13


Psedocoding and Flowcharting
Pseudocoding:
 Pseudocode is a semiformal, English-like language with a limited vocabulary
that can be used to design and describe algorithms.
 A pseudocode language is a more appropriate algorithm description language
than any programming language.
 A pseudocode can be used for:
 Designing algorithms

 Communicating algorithms to users

 Debugging logic errors in program

 Documenting programs for future maintenance and expansion purposes

Chapter1: Introduction to Programming 14


Psedocoding and Flowcharting cont’d…
Flowcharting:
 is a graph consisting of geometrical shapes that are connected by
flow lines.
The geometrical shapes in a flowchart represent the types
of statements in an algorithm.
 The details of statements are written inside the shapes.

Chapter1: Introduction to Programming 15


Chapter1: Introduction to Programming 16
Examples
Example:1 The following set of instructions forms a de-
tailed algorithm in pseudo code for calculating the pay-
ment of person.
Input the three values into the variables Name, Hours,
Rate.
Calculate Pay = Hours  Rate.
Display Name and Pay.

Activity1: Given the above, design the algorithm for the


above problem using pseudopodia and flowcharts

Chapter1: Introduction to Programming 17


Solution for example 1
Pseudocode:
Start
Input Name, Hours worked, Rate of payment.
Compute Payment = Hours worked  Rate of payment
Output Name and Payment
Stop

Chapter1: Introduction to Programming 18


Chapter1: Introduction to Programming 19
Class Activity 2:
Example 2: Design the Algorithm for computing
the minimum and the maximum values

Chapter1: Introduction to Programming 20


PROGRAMMING LAN-
GUAGES
PROGRAMMING LANGUAGES
 Early programming languages were designed for specific
kinds of tasks.
 Modern languages are more general-purpose.
 In any case, each language has its own characteristics,
vocabulary, and syntax.
 Many programming languages have some form of writ-
ten specification of their syntax (form) and semantics
(meaning).

Chapter1: Introduction to Programming 23


Types [Levels] of
Programming Languages
There is only one programming language that any
computer can actually understand and execute:
its own native binary machine language.
All other languages are said to be high level or low
level according to how closely they can be said to re-
semble machine code.

Chapter1: Introduction to Programming 24


1. Low-level languages
 They allow instructions to be written at the hardware
level.
 Thus, a program written in a low-level language can be
 extremely efficient,
 making optimum use of both computer memory and pro-
cessing time.
 However, to write a low-level program needs
 a substantial amount of time,
 as well as a clear understanding of the inner workings of
the processor itself.

Chapter1: Introduction to Programming 25


Characteristics of LOW Level Languages:
They are machine oriented:
an assembly language program written for one ma-
chine will not work on any other type of machine
unless they happen to use the same processor chip.
The program becomes long and time-consuming

to create.
Each assembly language statement generally trans-
lates into one machine code instruction,

Chapter1: Introduction to Programming 26


2. High-level languages
 They permit faster development of large pro-

grams.
 The final program as executed by the computer is

not as efficient,
 but the savings in programmer time generally far
outweigh the inefficiencies of the finished product.

Chapter1: Introduction to Programming 27


Characteristics of HIGH Level Languages:
They are not machine oriented:
 they are portable, meaning that a program written for one ma-
chine will run on any other machine for which the appropriate
compiler or interpreter is available.
They are problem oriented:
 most high level languages have structures and facilities appro-
priate to a particular use or type of problem.
 For example, FORTRAN was developed for use in solving
mathematical problems. Some languages, such as PASCAL
were developed as general-purpose languages.
Statements in high-level languages usually resemble
English sentences or mathematical expressions
 they tend to be easier to learn and understand than assembly
language.
Each statement in a high level language will be
translated into several machine code instructions.

Chapter1: Introduction to Programming 28


GENERATIONS OF PROGRAM-
MING LANGUAGES
GENERATIONS OF PROGRAM-
MING LANGUAGES
1ST GENERATION –
 MACHINE LANGUAGE

2ND GENERATION –
 ASSEMBLY LANGUAGE (Symbolic Code)

3RD GENERATION –
 HIGH LEVEL LANGUAGES (Independent of the machine)

4TH GENERATION –
 FOURTH GENERATION LANGUAGES (4GLS) ( most advanced)

Chapter1: Introduction to Programming 30


LANGUAGE
TRANSLATORS

Chapter1: Introduction to Programming 31


LANGUAGE TRANSLATORS
All computer programs run on machine code that is exe-
cuted directly on computer architecture.
Essentially, machine code is a long series of bits (i.e. ones
and zeroes).

Chapter1: Introduction to Programming 32


LANGUAGE TRANSLATORS cont’d…
3 types of system software used for translating the
code that a programmer writes into a form that
the computer can execute (i.e. machine code).
These are:
Assemblers
Compilers
Interpreters

Chapter1: Introduction to Programming 33


1. Assembler
Assembly language code is simply an abbreviated form
of machine code.
To transform a program, the instructions must be con-
verted from their mneumonic abbreviations into
their equivalent string of ones and zeroes.
This transformation process is known as assembling
and is accomplished by an assembler.
The assembler substitutes the required machine
code for each symbolic names.
The final result is a machine-language program that
can run on its own at any time without the need of the
assembler.

Chapter1: Introduction to Programming 34


2. Compilers
A compiler converts an entire program written in a
high-level language (called source code) and translates
it into an executable form (called object code).
 Advantages of a Compiler
 Fast in execution
 The object program can be used without the need to of re- compilation.
 Disadvantages of a Compiler
 Debugging a program is much harder.
 When an error is found, the whole program has to be re-compiled

Chapter1: Introduction to Programming 35


3.Interpreter
An interpreter takes source code and converts
each line in succession.
 Advantages of an Interpreter
 Good at locating errors in programs
 Debugging is easier
 If an error is removed, there is no need to retranslate
 Disadvantages of an Interpreter
 Execution of an interpreted program is much slower
 No object code is produced.
 For the program to run, the Interpreter must be present.

Chapter1: Introduction to Programming 36

You might also like