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

INTRODUCTION TO

C++

CHAPTER 1
INTRODUCTION TO
COMPUTER PROGRAM
Learning Outcome
At the end of this chapter, you should be able to:
•Understand the concepts and importance of programs
and programming.
•Differentiate between program, compiler, interpreter
and assembler.
•Apply the steps in the program development life cycle.
INTRODUCTION

• Computers can be found anywhere from the


size of a desktop to smaller than the palm of
one’s hand such as desktop computers,
notebooks, netbooks, tablet PCs and mobile
devices.
• Many kinds of applications or apps can be
downloaded into the tablet or smartphone.
INTRODUCTION

• There are many ways to develop these applications.


• Some websites provide templates to create apps
quickly
• Users with programming knowledge can create their
apps from scratch.
• Examples of systems/apps developed using
programming language:
– Automated Teller Machine (ATM) systems,
– Student Information Systems
– Online Ticketing Systems
History of Computers
• first general purpose computing device.
19th Century

• early analogue computers have been invented.


20th Century

• first freely programmable computers were developed.


1936

• electronic programmable computers using vacuum tubes and transistors have been created.
1940s

• commercial computers, computer games and programming languages were developed.


1950-1960s

• mainframes and supercomputers were available.


1975

• IBM introduced its personal computers


1981

• The first personal computer with a graphical user interface was introduced
1983
Language
Basic of PDLC
Operation
Computer
Basic operation of a Computer

• A computer is a device that can process data.


• Data consists of raw facts or unprocessed
information.

Basic operation of a computer

• Input – accepts data from user


• Process – manipulate data
• Output – produce result
• Storage – store result
Basic Operation of
a Computer

• Computers are electronic devices capable of


performing computations and making logical
decisions at speeds faster than human beings.

Hardware Software

Computer Component
Language of a Computer
• Computers can only understand machine language.
• Machine language is also called binary numbers or
binary code, which is a sequence of 0s and 1s.
• The digits 0 and 1 are called binary digits or bits.
• A sequence of 8 bits is called a byte.
Language of a Computer
Types and Levels of
Programming Languages

 Consist of Binary code  language is mnemonic  Machine independent


of 0 and 1 series  use assembler as  the instructions are quite English-
 Machine dependent translator to translate like
to machine language  use compiler/interpreter as
 Machine dependent translator to translate to machine
language
 Example: JAVA, C++, COBOL
Language of a Computer
Types and Levels of
Programming Languages

• Example:
To calculate the BMI of a user given the formula:
weight (kg)
BMI =
height (m) x height(m)
Language of a Computer
High-level Language

• High-level programming languages were designed to make


programming far easier, less error-prone and to remove the
programmer from having to know the details of the internal
structure of a particular computer.
• These high-level languages were much closer to human
language. One of the first of these languages was Fortran II which
was introduced in about 1958. In Fortran II our program above
would be written as:  Readable
C=A+B  quicker to write
 less error-
• As with assembly languages the computer does not
prone.
understand these high-level languages directly and hence
they have to be processed by passing them through a
program called a compiler which translates them into internal
machine language before they can be executed.
Language of a Computer
High-level Language

• Many high level languages have appeared since Fortran II (and


many have also disappeared!), among the most widely used
have been:

COBOL Business applications


FORTRAN Engineering & Scientific Applications
PASCAL General use and as a teaching tool
C & C++ General Purpose - currently most popular
PROLOG Artificial Intelligence
JAVA General Purpose - gaining popularity rapidly
Language of a Computer
High-level Language

Advantages of writing program using high-level language:


• Easy to read
• Easy to debug
• Less error prone
• Not Lengthy
• Independent
Language of a Computer
Translator

PROGRAM
Line by line instructions (coding statements) for a computer to
perform specific task.

Compiler Interpreter Assembler


Translate Translate Translate
instructions in instructions in instructions in
high-level high-level assembly
language all at language one at language into
one time into a time into machine code
machine code machine code
Language of a Computer
Program Vs Programming

• A program is a set of instructions that tell the computer how to


solve a problem or perform a task.
• Programming is the process of designing and writing computer
programs. Why

• A program is like a recipe. It contains a list of ingredients


(variables) and a list of directions (statements) that tell the
computer what to do with the variables.
• A program can be as short as one line of code, or as long as
several million lines of code.
• Computer programs guide the computer through orderly sets
of actions specified by the computer programmers.
• The programmer must decide what the programs need to do,
develop the logic of how to do it and write instructions in a
programming language that the computer can translate into
machine language and execute.
Language of a Computer
Why Computer Programming
is important?

1 Able to perform difficult tasks without making human-type errors such


as lack of focus, energy, attention or memory.
2 Capable of performing extended tasks at greater serial speeds than
conscious human thoughts.
3 Human brain cannot be duplicated or ‘re-booted’ like computers, and
has already achieved ‘optimization’ through design by evolution,
making it difficult to upgrade.
4 Human brain does not physically integrate well, externally or internally
with current hardware and software.
5 Non-existence of boredom in computers when performing repetitive
tasks allows jobs to be done faster and more efficiently.
Language of a Computer
A GOOD program Must have…

Accura
cy
Usabili Reliabili
ty ty

Readab Efficiency
ility
Maintain
ability
Language of a Computer
Writing a GOOD program

Names for variables, types and functions


• Variables and constants are storage locations in the computer’s memory that
match with associated names known as identifiers.
• The following are some standards that can be used when naming variables,
constants, types and functions:
1. Function names will start with a lowercase letter.
Example: double calculateBMI (double, double);
2. Variable names start with a lowercase letter and the length must not be
more than 40 characters.
Example: double weight, height;
3. Constant names can be all in capital letters.
Example: const int MAX_SIZE =10;
Why
Language of a Computer
GOOD programming practice

Include
comment
where
necessary

Use of loop
statement
Use Divide by when
Mnemonic process; necessary
variable name 1) input,
2) output,
3) process
Program Development life cycle
• The process of developing a program is called
program development.
• The process associated with creating successful
application programs is called the Program
Development Life Cycle (PDLC).
Program Development
Life Cycle
Phase1: Analysis

• First step in the Program Development Life Cycle (PDLC).


• This process is done by reviewing the program specifications.
• Other criteria must also be identified, especially the data that will
be used as input, the process involved and the output that will be
produced.

Why
Program Development
Life Cycle
Phase2: Design

• A programmer needs to develop a series of steps with logical


order, which when applied would produce the output of the
problem.
• A solution is created using a structured programming technique
known as algorithm, which consists of pseudocode and flowchart.
– A procedure or formula for solving a problem.
– A step-by-step problem solving process where the result is
attained in a limited amount of time.
Program Development
Life Cycle
Phase2: Design

• Before pseudocode and flowchart are created, the flow of a


program should be understood first.
• Flow of a programs is not limited to a linear sequence of
statements. During its process, a program may repeat segments
of code, or take decisions and bifurcate.
• For that purpose, C++ provides flow control statements that serve
to specify what has to be done by the program, when, and under
which circumstances.
• Control Structure is a pattern to control the flow of a program
module.
Program Development
Life Cycle
Phase2: Design

CONTROL
STRUCTURE

Iteration/
Sequential Selection
Repetition

• Sequential: Basic flow of a program. Statements are executed one


after another (orderly) in which they have been written.
• Selection: The next statement is executed if the condition is TRUE.
• Iteration: Repetition of a statement or group of statements. construct
How to

condition?
Program Development
Life Cycle
Phase2: Design- Pseudocode

Pseudocode:
• A semiformal, English-like language with a limited vocabulary
used to design and describe algorithms.
• Every statement in pseudocode involves keywords which define
the process and operands.
• Each pseudocode statement should be written in a separate line.
• All statements showing "dependency" are to be indented. These
include while, do, for, if, switch.
Program Development
Life Cycle
Phase2: Design- Pseudocode
Program Development
Life Cycle
Phase2: Design- Pseudocode

BEGIN

Iteration
Sequence structure
structure

Selection
structure

END
Program Development
Life Cycle
Phase2: Design- Flowchart

Flowchart:
• A diagrammatic representation of an algorithm. It explains the
flow of the program.
• Best describes structure of the program: sequence; selection and
iteration.
• Uses geometric symbols where different symbols are used to
represent different actions such as start/stop, decision,
input/output, processing and looping.
Program Development
Life Cycle
Phase2: Design- Flowchart

Symbol Purpose Description


Used to indicate the flow of logic by connecting
Flow line
symbols.

Terminal(Stop/Start) Used to represent start and end of flowchart.

Input/Output Used for input and output operation.

Used for arithmetic operations and data-


Processing
manipulations.

Used to represent the operation in which there


Decision
are two alternatives, true and false.

On-page Connector Used to join different flowline

Used to connect flowchart portion on different


Off-page Connector
page.
Used to represent a group of statements
Predefined Process/Function
performing one processing task.
Program Development
Life Cycle
Phase2: Design- Flowchart

• The most important geometric symbol is diamond shape, that is


used to construct decision and split the result either TRUE or
FALSE. in

False
Condition

True
Program Development
Life Cycle
Phase2: Design- Flowchart

Flow of the
program is in
sequence
Program Development
Life Cycle
Phase2: Design- Flowchart

Flow of the program depends on the decision of the selection

Control
decision of the
program

Flow if
TRUE
Flow if
FALSE
Program Development
Life Cycle
Phase2: Design- Flowchart

Flow of the program


Control depends on the decision
decision of the of the iteration
program

FALSE

TRUE

Loop when
TRUE

Proceed when
FALSE
Program Development
Life Cycle
Phase3: Implementation

• The pseudocode and flow chart which have been done in the design
step (phase 2) will be converted into a program by using certain high-
level of programming languages such as BASIC, JAVA, C or C++.
• This step solves the problem by enabling the user to start writing the
programs.
• Coding is the actual process of creating a program in a programming
language.
• The coded program is referred to as source code.
– Must follow certain rules which are called syntax.
– Must then be saved as a program which has the extension ‘.cpp’.
• To be executed, the program is converted by the computer into object
code using a special program called translator such as a compiler or
interpreter.
Program Development
Life Cycle
Phase4: Testing/ Debugging

• The step for checking and verifying the correctness of


the program.
• The process of making sure a program is free of errors or
‘bugs’ is called debugging.
• Preliminary debugging begins after the program has
been entered into the computer system.
Program Development
Life Cycle
Phase5: Maintenance

• Essentially, every program, if it is to last a long time,


requires ongoing maintenance.
• A process of updating software for any changes,
corrections, additions, moving to a different computing
platform and others so that it continues to be useful.
• A costly process.
• Can be very useful especially on extending the life of a
program.
• Last step in the Program Development Life Cycle (PDLC).

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