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

Comp Prog Lecture 2

Uploaded by

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

Comp Prog Lecture 2

Uploaded by

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

 By wikipedia definition:

▪ an algorithm is a sequence of finite


instructions, often used for calculation
and data processing.
▪ It is formally a type of effective method
in which a list of well-defined
instructions for completing a task will,
when given an initial state, proceed
through a well-defined series of
successive states, eventually
terminating in an end-state.
Input List

Al orith01
A step-by-step method for
solving a problem or doing a task

·Output List
 First documented algorithm by Euclid
(300 B.C.) to compute greatest
common divisor (gcd).
 Example: gcd(3,21)=3
 Condition:
1. Let A and B be integers with A > B 0.
2. If B = 0, then the gcd is A and the algorithm ends.
3. Otherwise, find q and r such that
A = qB + r where 0 r<B
Note that we have 0 r < B < A and gcd(A,B) =
gcd(B,r). Replace A by B, B by r. Go to step 2.
 Example No. 2:
 Find the greatest common divisor of
A=40, B=15; using Euclidean
algorithm;
A = 2B + A = 15 ; B =
10 A = 1B 10 A = 10 ; B
+ 5 A = 2B =5A=5;B=
+0 0
gcd is 5
 There are three properties of
algorithm that must have to
consider in solving a certain
problem in programming:
 Finiteness
 Absence of Ambiguity
 Sequence Definition
 Input and Output Definition
 Effectiveness
 Scope of Definition
 Finiteness
 The execution of a programmed
algorithm must be complete after
a finite number of operations have
been performed. Otherwise, we cannot
claim that the execution produces a
solution.
 Absence of Ambiguity
 The representation of every step of an
algorithm should have a unique
interpretation which also understand
by the human.
 It is convenient to deal with algorithms
presented in notational with sparse
detail:
▪ Example:
▪ Pseudo code
▪ Flowcharts
 Sequence of Definition
 The sequence in which the steps of the
algorithm are to carried out should be
clearly specified.
 In algorithmic specifications, the
instructions are performed from
top to button, unless the instruction
themselves otherwise specified.
 Input and Output Definition
 Inputs – are the data items that is
presented in the algorithm.
 Outputs – are the data items
presented to the outside world as
the result of the execution of a
program based on the algorithm.
 An algorithm ought to produce at
least one output
(otherwise, what use is it?...)
 Effectiveness
 it consists of basic instructions that are
realizable. This means that the
instructions can be performed by using
the given inputs in a finite amount
of time.
 The instructions of an algorithm may
order the computer only to perform
tasks that is capable of carrying out.
 Scope Definition
 An algorithm applies to the following:
▪ Specific problem or class of problem
▪ The range of inputs has to be predefined
▪ The range determines the generality of the
algorithm.
 Algorithms
can be expressed in
many kinds of notation, including:
 Natural language
 Pseudo Code
 Flowcharts
 Programming Language
 “Pseudo” means imitation or false
and “code” refers to the instructions
written in a programming language.
 Pseudocode is another programming
analysis tool that is used for
planning a program.
 Pseudocode is also called
Program Design Language (PDL).
 By wikipedia definition:
 Pseudocode is a compact and
informal high-level description of a
computer programming
algorithm that uses the
structural conventions of some
programming language, but is
intended for human reading
rather than machine reading.
 Pseudocode is made up of the
following logic structures that have
been proved to be sufficient for
writing any computer program:
 Sequence Logic
 Selection Logic
 Iteration Logic
 Itis used to perform
instructions in a sequence,
that is one after another.
 Thus, for sequence logic,
pseudocode instructions are
written in an order in which they
are to be performed.
 The logic flow of pseudocode is
from top to bottom.
 It is used for making decisions and
for selecting the proper path out of
two or more alternative paths in
program logic.
 It is also known as decision logic.
 Selection logic is depicted as
either an IF...THEN or an
IF...THEN...ELSE structure.
 It is used to produce loops when
one or more instructions may be
executed several times depending
on some of the conditions.
 It uses structures called the
DO_WHILE, FOR and the
REPEAT_UNTIL.
1. Write only one statement per line.
 Each statement in your
pseudocode should express just
one action for the computer.
 If the task list is properly drawn,
then in most cases each task will
correspond to one line of
pseudocode.
 Exampl
es
2. Capitalized initial keyword.
 In the example above, READ and
WRITE
are in caps.
 There are just a few keywords we
will use:
▪ READ, WRITE, IF, ELSE,
ENDIF, WHILE, ENDWHILE,
REPEAT, UNTIL
3.Indent to show
 Wehierarchy.
will use a particular indentation
pattern in each of the design
structures:
▪ SEQUENCE: keep statements that are
“stacked” in sequence all starting in the
same column.
▪ SELECTION: indent the statements that fall
inside the selection structure, but not the
keywords that form the selection
▪ LOOPING: indent the statements that fall
inside the
 Exampl
es:
• ▫ 4.All
End themulti-line
initial keyword must always in line
with the last or end of the structure.
structures.
•5. Keep statement language independent.
• ▫ Resist the urge to write in whatever
language you are most comfortable with.
There may be special features available in the
language you plan to eventually write the
program in; if you are SURE it will be written
in that language, then you can use the
features. If not, then avoid using the special
features.
 In summary:
 Write only one statement per
line.
 Capitalized initial keyword.
 Indent to show hierarchy.
 End multi-line structures.
 Keep statement language
independent.
• These are follows:
▫ Number each instruction.
 This is to enforce the notion, “well-ordered
collection of
... operations.”
▫ Each instruction should be
unambiguous.
 It means the computing agent, in this case
the reader, should be capable of carrying
out the instructions. And also, each
instruction should be effectively computable
(do-able).
▫ Completeness.
 Following
are some of the
advantages of using
pseudocode:
 Converting a pseudocode to a
programming language is much more
easier than converting a flowchart.
 As compared to flowchart, it is easier to
modify a pseudocode of a program
logic when program modifications are
necessary.
 Italso suffers from some of the
limitations. These limitations are
as follows:
 In the cases of pseudocode, a graphic
representation of program logic is
not available.
 There are no standard rules to follow
for using a pseudocode. Different
programmers use their own style of
writing pseudocode and hence,
communication problem occurs due to
 To
symbolize the arithmetic
operators we use these symbols:
 Note: There is a precedence or
hierarchy implied in this symbols.
 When we have to make a choice
between actions, we almost
always base that choice on a test.
 There is a universally accepted set
of symbols used to represent these
phrases:
It is more difficult to
follow the logic of or
write pseudocode as
compared to
flowcharting.
Prepare ½ crosswise yellow paper
for seatwork after the discussion.
Introduction To Flowcharting
Flowchart:

Represents an
algorithm in
graphical symbols
Flowchart Symbols

Terminal: Used to indicates the


start and end of a flowchart.
Single flow line. Only one “Start”
and “Stop” terminal for each
program. The end terminal for
function/subroutine must use
“Return” instead of “Stop”.
Process: Used whenever data is
being manipulated. One flow line
enters and one flow line exits.
Input/Output: Used whenever
data is entered (input) or
displayed (output). One flow line
enters and one flow line exits.
Flowchart Symbols
Decision: Used to represent operations in
which there are two possible selections.
One flow line enters and two flow lines
(labeled as “Yes” and “No”) exit.
Function / Subroutine: Used to identify an
operation in a separate flowchart
segment (module). One flow line enters
and one flow line exits.
On-page Connector: Used to connect
remote flowchart portion on the same
page. One flow line enters and one flow
line exits.
Off-page Connector: Used to connect
remote flowchart portion on different
pages. One flow line enters and one flow
line exits.
Comment: Used to add descriptions or
clarification.
Flow line: Used to indicate the direction of
Comments or description
Start

Read N, N = The number of students


M M = The number of subjects

Yes

No

Stop
Connectors on the same page

Start

1 2

1- connection on the same


flowchart portion

2- connection on the different


flowchart portion
Stop

2
Connectors on a different page
Page 1 Page 2

Start

2
1

Stop
Yes 1

No

2
The detail of how the function works
is put in another flowchart.

This is known as Function-Definition


Function
Page 1 Start terminal for a Page 2
Function is different.
Start
Do not use “Start”
AVRG ( result,n1, n2,n3)

Read
n1, n2 , n3

sum = n1+ n2+n3

Body of a function is
AVRG (result, n1, n2,n3) the same with
normal flowchart

At this point, result = sum/3


we only focus on what
to do. How to do it,
it comes later. Print
result
This part is known as
Function-Call Return

Stop
End terminal
must be a “Return”

This flowchart calculates the average of three n


Example:
What is the output of the following flowchart when the input is N = 6
10
Page 1 5
average Page 2

Start
N=6
AVRG ( result,n1, n2,n3)

Read
N Sum = 10 + 5 +

sum = n1+ n2+n3

AVRG (average, 10, 5, N) average =


21/3

result = sum/3

Print
average Output:
Average: 7
Return

Stop
Sequence
In a computer program or an algorithm,
sequence involves simple steps which are
to be executed one after the other.
The steps are executed in the same order in which they are written.
In a flowchart,
sequence is expressed as:
In pseudocode,
sequence is expressed as:

process 1
process 2


process n
Sequence
An Example Using Sequence

Problem: Write a set of instructions that describe how to make a pot of tea.

Pseudocode Flowchart

BEGIN
fill a kettle with water
boil the water in the kettle
put the tea leaves in the pot
pour boiling water in the pot
END
Example:

Start

Read
Length, Input:
Width Length <- 5
Width <- 3

Calculate Area Process:


Area=Length * Width Area = 5 * 3 = 15

Calculate Perimeter Process:


Perimeter= Perimeter =
2 * (Width+Length) 2* (5+3) = 16
Output

Area: 15
Print
Area, Perimeter: 16
Perimeter

Stop
Selection is used in a computer program or algorithm
to determine which particular step or set of steps is to
be executed

Binary Selection Binary Selection

In pseudocode, binary selection is In flowcharts, binary selection is expressed in the following


expressed in the following ways: ways:

1. IF condition THEN
process 1
ENDIF

2. IF condition THEN
process 1
ELSE
process 2
ENDIF
Selection
Binary (structure)
Binary Selection Binary Selection

In pseudocode, binary selection is In flowcharts, binary selection is expressed in the


expressed in the following ways: following ways:

1. IF condition THEN
process 1
ENDIF

2. IF condition THEN
process 1
ELSE
process 2
ENDIF
Selection
Binary (flowchart structure)
Note: In a flowchart it is most important to indicate
1. which path is to be followed when the condition is true, and
2. which path to follow when the condition is false.
Without these indications the flowchart is open to more than one interpretation.

Note: There are two acceptable ways to represent a decision in all of the structures.
Either method is acceptable. For consistency, the method 1 is used throughout this document.

1. The condition is expressed as a 2. The condition is expressed as a question


statement and the two possible and the two possible outcomes are indicated by
outcomes are indicated by • Yes
• True • No
• False
Selection
Binary (examples)
Selection is used in a computer program or algorithm
to determine which particular step or set of steps is to be executed.

Examples Using Binary Selection


Problem 1: Write a set of instructions to describe when to answer the phone.

Binary Selection
Flowchart
Binary Selection
Pseudocode

IF the telephone is ringing THEN


answer the telephone
ENDIF
Selection
Binary (examples)
Examples Using Binary Selection
Problem 2: Write a set of instructions to follow when approaching a set of traffic control
lights.
Binary Selection
Flowchart
Binary Selection
Pseudocode

IF the signal is green THEN


proceed through the
intersection
ELSE
stop the vehicle
ENDIF
Selection
Multi-way (structure)

Multi-way Selection Multi-way Selection

In pseudocode, multiple selection is In flowcharts, multi-way selection is expressed


expressed as: as:
CASEWHERE expression evaluates to
choice a : process a
choice b : process b
. .
. .
. .
OTHERWISE : default process
ENDCASE

Note: As the flowchart version of the


multi-way selection indicates, only
one process on each pass is executed
as a result of the implementation of
the
multi-way selection.
Selection
Multi-way (examples)
Example Using Multi-way Selection
Problem: Write a set of instructions that describes how to:
respond to all possible signals at a set of traffic control lights.
Multi-way Selection
Multi-way Selection Flowchart
Pseudocode

CASEWHERE signal is
red : stop the vehicle
amber : stop the vehicle
green : proceed through
the intersection
OTHERWISE : proceed with
caution
ENDCASE
Pseudo Code
• Algorithms are commonly written using
Pseudo code.
• The term “Code” usually refers to as
programming language.
• Pseudo code is an English like language that is
similar to programming language that is used
to write Algorithms.
Looping
1. Ask the user for the Centigrade temperature
2. Store the value in box C
3. Calculate the corresponding Fahrenheit
temperature
4. Store it in box F
5. Print the values in boxes C and F,
Appropriately labelled
6. Go to step 1.
• When the Algorithm reaches step 6, it
does not stop but rather transfers control
to step 1 to repeat the Algorithm again.
• A Loop is a set of instructions which can
be repeated. In this case. Step 1 to step 5
form a loop.
• The problem is there’s no condition
under which the loop can be stopped.
• How long will the loop go for ?
• How do we stop the Algorithm ?
The While loop
1. Ask the user for the WHILE C is not 0 DO
Centigrade temperature
2. Store the value in box C
3. If C = 0, then Stop. Set F to 32+(9C/5)
4. Calculate the Print C and F,
corresponding Fahrenheit
temperature Prompt the user for
5. Store it in box F the
6. Print the values in boxes C Centigrade
and F, Appropriately
temperature C
labelled
7. Go to step 1.
END WHILE
The While loop
When a WHILE loop has the
following steps
• The condition is tested.
• If it is true the statements in
the loop are tested and the
process is repeated from step
1.
• If the condition is false then
the WHILE loop
terminates/Ends with the END
WHILE statement. And the
program ends with the STOP
statement.
Repetition
Repetition allows for a portion of an algorithm or computer program
to be done any number of times
dependent on some condition being met.
An occurrence of repetition is usually known as a loop.

An essential feature of repetition is that


each loop has a termination condition
to stop the repetition,
or the obvious outcome is that
the loop never completes execution (an infinite loop).

The termination condition can be checked or tested


1. at the beginning and is known as a pre-test loop or
2. at the end of the loop and is known as a post-test loop.
Repetition
Pre-test (structure)
Repetition: Pre-Test
A pre-tested loop is so named because the condition has to be met at
the very beginning of the loop or the body of the loop is not executed.
This construct is often called a guarded loop.
The body of the loop is executed repeatedly while the termination condition is true.

Repetition

Repetition In flowcharting
pre-test repetition
In pseudocode, pre-test is expressed as:
repetition is expressed as:

WHILE condition is true


process(es)
ENDWHILE
Repetition Post-test (structure)
Repetition: Post-Test
• A post-tested loop executes the body of the loop before testing the termination condition.
• This construct is often referred to as an unguarded loop.
• The body of the loop is repeatedly executed until the termination condition is true.
An important difference between a pre-test and post-test loop is that the statements of a post-test
loop are executed at least once even if the condition is originally true, whereas the body of the pre-test
loop may never be executed if the termination condition is originally true.
A close look at the representations of the two loop types makes this point apparent.

Repetition

Repetition In a flowchart
post-test repetition
In pseudocode, post-test is expressed as:
repetition is expressed as:

REPEAT
process
UNTIL condition is true
Repetition Pre-test (example)
An Example Using Pre-Test Repetition
Problem: Determine a safety procedure for travelling in a carriage on a moving train.

Pre-test Repetition
Flowchart

Pre-test Repetition
Pseudocode

WHILE the train is moving


keep wholly within the
carriage
ENDWHILE
Repetition Post-test (example)
An Example Using Post-Test Repetition
Problem: Determine a procedure to beat egg whites until fluffy.

Post-test Repetition
Flowchart

Post-test Repetition
Pseudocode

REPEAT
beat the egg whites
UNTIL fluffy
For Loop
• The For construct is a simple For C = 0 to 100
statement which executes a piece
of code a set number of times.
• It consists of Set F to
1. The word FOR
32+9C/5
2. The loop variable, (problem in
the example) Print (C,F)
3. The word TO
4. The final value
5. To word DO END FOR
6. One or more lines of STOP
instructions to be executed
( The body of the for loop)
7. The END FOR statement
For Loop
RESULT
C F
0 32.0
1 33.8
2 35.6
3 37.4
4 39.2
5 41.0
6 42.8
7 44.6
8 46.4
9 48.2
10 50.0
IF Then ELSE statement

The IF then ELSE consists of Prompt the user for two


• The word IF numbers A & B
• A condition IF A>B THEN
• The word THEN
PRINT (“A is bigger”)
• One or more statements
called the THEN PART
• The word ELSE ELSE
• One or more statements PRINT (“B is bigger”)
called the ELSE PART END IF
• The word END IF STOP
Flowcharting &
Algorithms
Key terms
• Abstraction - the process of hiding information that is not needed to
know at the time; to use the overall essential concept with details hidden.
• Algorithm - a process to solve a problem.
• Function - a combination of variables and operators.
• Heuristic - a technique, a way to try to solve, an idea to use to look for the
answer to a problem which may or may not be solved by the technique.
• Iteration - to do again, a repetition of an existing process.
• Method - a set of instructions telling a computer the operations to
perform for a problem solution.
• NP - in computer science, problems that have an indeterminate answer; a
choice of answers requiring more information to choose the best answer.
Key terms
• Operator - a character symbol like a plus sign in math, +, or a word or
specially defined symbol usage in a programming language, that tells the
computer to do something with variables.
• P - in computer science, problems that have a particular answer; a
determinate problem.
• Procedure - another word for method.
• Solvable Problems - problems that can be solved with algorithms to an
exact answer, a computer can find the exact answer.
• Unsolvable Problems - problems that are indeterminate in their solution
for a computer.
• Variable - a programming word made up of letters, numbers, and/or
allowable symbols which holds data for the program.
ALGORITHMS AND
FLOWCHARTS
• Computer programming can be divided into two
phases:
• Problem solving phase
– Make an ordered sequence of steps that solves a problem.
– This sequence of steps is called an algorithm.
• Implementation phase
– Implement using a programming language.
Steps in Problem Solving
• Pseudocode is an artificial and informal language
that helps programmers develop algorithms.
Pseudocode may be in informal English,
combinations of computer languages and spoken
language. Whatever works for you.
• First produce a general algorithm (one can use
pseudocode).
• Refine your steps until you get to an easy sequence.
Perhaps use numbers or bullets. The point is to
simplify the language to an understandable process
or event.
The Flowchart
A Flowchart is another algorithm but graphical.
– Shows logic solution
– Emphasizes individual steps and their
interconnections
– A flowchart must have a start and stop.
– All steps in a flowchart must connect. Can’t leave
a step “hanging” with no connection.
e.g. control flow from one action to the next
Algorithms in alice 3
DATA MANIPULATION

1. WHAT IS DATA MANIPULATION?


• Data Manipulation Meaning: Manipulation of data is the process of
manipulating or changing information to make it more organized and readable.
We use DML to accomplish this. What is meant by DML? Well, it stands for Data
Manipulation Language or a programming language capable of adding,
removing, and altering databases, i.e. changing the information to something
that we can read. We can clean and map the data thanks to DML to make it
digestible for expression.
SQL (Structured Query Language) is used to communicate with DBMS(Database
Management Systems). The SQL DML commands used for data manipulation are
– SELECT: This command is used to select a section of the database (a few
rows/columns) to work on.
– UPDATE: This command is required to make changes to the existing data
– INSERT: This command is used to insert data in a different location or move data.
– DELETE: This command is used to delete the redundant or duplicate data from the
table.
DATA MANIPULATION

• Data Manipulation is the modification of information to make it easier


to read or more structured. For example, in alphabetical order, a log of
data may be sorted, making it easier to find individual entries. On web
server logs, data manipulation is also used to allow the website owner
to monitor their most famous pages and their sources of traffic.
• Accounting users or related fields also manipulate information to
assess the expense of the product, pricing patterns, or future tax
obligations. To forecast developments in the stock market and how
stocks might perform shortly, stock market analysts also use data
manipulation.
• Computers can also use data manipulation to view the information in
a more realistic way to users based on code in a user-defined software
program, web page, or data formatting.
PURPOSE OF DATA MANIPULATION
• For business operations and optimization, data manipulation is a key feature.
You have to be able to deal with the data in the way you need it to use data
properly and turn it into valuable information such as analyzing financial data,
consumer behavior, and doing trend analysis. As such, data manipulation
provides an organization with many advantages, including:
– Consistent data: It can be structured, read, and better understood by providing data in
a consistent format. You may not have a unified view when taking data from various
sources, but with data manipulation and commands, you can make sure that the data
is structured and stored consistently.
– Project data: it is paramount for organizations to be able to use historical data to
project the future and to provide more in-depth analysis, especially when it comes to
finances. Manipulation of data makes it possible for this purpose.
– Overall, being able to convert, update, delete, and incorporate data into a database
means you can do more with the data. -Create more value from the data. It becomes
pointless by providing data that remains static. But you will have straightforward
insights to make better business decisions when you know how to use data to your
advantage.
– Delete or neglect redundant data: data that is unusable is always present and can
interfere with what matters.
STEPS INVOLVED IN DATA MANIPULATION

• When you want to get started with data manipulation,


here are the steps you should take into consideration:
– Only if you have data to do so is data manipulation feasible.
You need a database, therefore, which is generated from
data sources.
– This knowledge requires reorganization and restructuring.
Manipulation of data helps you to cleanse your information.
– Import a database and create it for you to work on.
– You can combine, erase, or merge information through data
manipulation.
– When you manipulate data, data analysis becomes simple.
IN EXCEL, HOW DO YOU MANIPULATE DATA?
• Manipulation of data in Python and manipulation of data in R are critical aspects of data
manipulation. Before moving through the more profound principles of Data Manipulation
in Python and R, let us now understand how to manipulate data.
• Most definitely, you are aware of how to use MS Excel. Here are some tips to help you
manipulate Excel info.
– Formulas and functions – Addition, subtraction, multiplication, and division are some of the basic
math functions in Excel. You need to know how to use these Excel-critical features.
– Autofill in Excel-When you want to use the same equation across several cells, this feature is
useful. One way of doing it is to retype the formula. Another way is to drag the cursor to the cell’s
lower right corner and then downwards. It will help you simultaneously apply the same formula
to several rows.
– Sort and Filter- Users can save a lot of time when analyzing data by sorting and filtering options
in Excel.
– Removing duplicates-There are often chances of replication of data in the process of collecting
and assimilating data. In Excel, the Delete Duplicate feature can help remove duplicate
spreadsheet entries.
– Column splitting, merging, and merging-Columns or rows in Excel may often be added or
removed. Data organization often requires integrating, splitting, or combining multiple
datasheets.
DIFFERENCE BETWEEN DATA MANIPULATION AND DATA
MODIFICATION
• Data manipulation and data modification appear to have the same
meaning. However, they are mutually exclusive when it comes to
the processing of data.
– When a computer’s stored or saved value changes to a different
value, this is referred to as data modification.
– Data manipulation is the process of extracting information and
applying logic to it to generate a completely different set of
data. In other words, data is modified when it is manipulated
and then stored in the same location.
– We’ll look at the distinction between the two terms with a
simple example.
– If you change the value of a column in MS Excel sheet A1 from
350 to 500, you are modifying the data.
– If you create a formula in A2 and use the data in A1, the output is data manipulation if you
save it in A2.
• Control Structures are just a way to specify flow of control in
programs. Any algorithm or program can be clearer and understood
if they use self-contained modules called as logic or control
structures. It basically analyses and chooses in which direction a
program flows based on certain parameters or conditions. There
are three basic types of logic, or flow of control, known as:

• Sequence logic, or sequential flow


• Selection logic, or conditional flow
• Iteration logic, or repetitive flow
Programming language
• It is a language that is used to control the
behavior of a machine particularly computer.
• It is used to facilitate communication about
task of organizing and manipulating
information
• It is used to express algorithms precisely
Why programming is important??
• Critical reading :Understanding + analysis
• Analytical reading: Step-by-Step procedures to
break complex problem into small steps
• Creative synthesis: Think about all the
possibilities
History Of C++
Pay attention to details
• Pay attention to all the aspects
• Pay attention to all the calculations involved in
program, their flow, and most importantly the
logic of program
• Understand the fact the computers are useless
• Don’t assume that reader is intelligent
• Comment your code
Model of a complex system
• Model: Simplified representation of salient
features of something, either tangible or
abstract
• System: Collection of components that work
closely together
• Syntax: Grammatical rules for forming
instructions
• Semantics: Meaning/ interpretation of
instructions.
Instruction written by programmer
• Coded in a specific programming language
• Programming language allow you to express
yourself more precisely than natural language
Source code:: All instructions that compute a
program is called source code
e.g. library catalog, ATM, video game.
Algorithm
• Set of instructions used to specify how to
solve a problem
Syntax
• Set of rules that govern the structure of
sentences, instructions
Types of languages
• Typed language: If operation defined for one
data type can’t be performed on another data
type
• Un-typed language: Allow any operation to be
performed on any data type e.g. assembly
language.
Introduction
• C++ is General purpose programming
language
• Mid level language: Combination of both high
level language and low level language
High level language
• It is a programming language that in comparison to
high level language is more compact, abstract, easier
to use and portable to most platforms
• They normally abstract away cpu operations like
memory access models and measurement of scope
• It can easily implement algorithms
• High level language is converted to assembly by
compiler
Low level language
• It does not provide any sort of abstraction from a
computer’s microprocessor
• First generation low level language: It was only
understood by microprocessor; it requires numerous
numeric codes for writing a single instruction
• Second generation low level language :e.g. Assembly
language. It is not a microprocessor’s native
language.But programmer still need to understand
internal architecture of microprocessor such as
registers and instructions e.g. cmp edx,3
Why functions?
• It is a way to make programs more
comprehensive
• Each function has a clearly defined purpose
and a clearly defined interface to other parts
of program
• Module: Grouping of a number of functions
together
Structured programming
• Division of a program into functions and
reconstruction in the form of modules is
structured programming
Data
• In procedural language data is given second
class status But in object oriented
programming data is given first class status
• Global data: The one that is acessible to all
the functions
• Local Data: the one that is accessible only to
its own confined block
Object oriented programming
• Combine data and functions into a single unit
that operate on that data; such a unit is called
an object
• Object functions: Provide only way to access
its data; if you want to read a data item you
only need to access its function;
Contd…
• C++ typically consists of a number of objects
which communicate with each other through
its functions
Properties of object oriented programming

• Abstraction
• Inheritance
• Encapsulation
• polymorphism
Inheritence
• Each subclass share a common set of
characteristics from its parent class. In
addition to common characteristics they have
their own characteristics as well
• OOP class can be divided into subclasses.
Original class is called parent class and those
that share common characteristics are called
subclass.
Class
• Serve as template of a new data type . It
specifies what data and functions will be
included in objects of that class. Defining class
don’t create ay object . Similar to integer
don’t create any integer variable.
Compilers
• Borland C++
• Turbo C++
Integrated development environment
• Put all the tools that you need to develop
program into a single unit
Borland C++
• It is used to create program in windows
environment
• It is a special kind of windows program that
acts like a DOS program ; it runs under
windows but acts like a DOS program

You might also like