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

ITEC1030_Ch02_Introduction to Programming (1)

This document serves as an introduction to programming, covering fundamental concepts such as computer programs, programming languages, and the problem-solving process involved in programming. It outlines the characteristics of low-level and high-level programming languages, the importance of algorithm design, and the steps required for effective problem-solving in programming. Additionally, it emphasizes the role of programmers and the significance of programming in automating tasks and improving efficiency.

Uploaded by

michaelnegash187
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

ITEC1030_Ch02_Introduction to Programming (1)

This document serves as an introduction to programming, covering fundamental concepts such as computer programs, programming languages, and the problem-solving process involved in programming. It outlines the characteristics of low-level and high-level programming languages, the importance of algorithm design, and the steps required for effective problem-solving in programming. Additionally, it emphasizes the role of programmers and the significance of programming in automating tasks and improving efficiency.

Uploaded by

michaelnegash187
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 84

Welcome

Department of information
Technology
Basic Computer
Programming
_________________________________________
@ 2024 FTVT Institute All Rights Reserved

OF/FTI/ALL /18 Issue No: 1


PPT 1
CHAPTER 2:

Introduction to
Programming

2 Introduction to ICT
Objective
After studying this chapter you will be able to:
• Define the fundamental concepts of programming,
including computer programs, programming, and
programming languages.
• Identify the characteristics and types of programming
languages (low-level and high-level).
• Explain the process of problem-solving in programming,
including steps such as analyzing problems, designing
algorithms, coding, testing, and debugging.
• Apply algorithm design techniques using tools like
pseudocode, flowcharts, and structured charts to solve
basic computational problems.
• Understand program development process, from editing
and compiling to linking and loading.

3
Department of Information AUGUST
Outline
2.1 Introduction to
Programming
2.2 Problem solving and
algorithm design techniques
2.3 Program design and
development process

OF-FTI-ALL -18 4 4
Department of Information AUGUST
1
Introduction to
Programming

5 Introduction to ICT
Discussion

What is Computer
Program ?

6
Department of Information AUGUST
Chapter 2 2.1 Introduction to Programming Computer Programs

The terms computer programs,


software programs, or just programs
are the instructions that tells the
computer what to do.
Sets of instructions that control a
computer’s processing of data
Computer requires programs to
function, and a computer programs
does nothing unless its instructions are
executed by a CPU. Department of Information AUGUST
7
Discussion

What is Programming
?

8
Department of Information AUGUST
Chapter 2 2.1 Introduction to Programming Computer Programming

Computer Programming
is the process of writing, testing,
debugging / troubleshooting, and
maintaining the source code of
computer programs.
Writing computer programs means
writing instructions, that will make the
computer follow and run a program
based on those instructions.

9
Department of Information AUGUST
Chapter 2 1.1 Introduction to Programming Computer Programming

Computer programming is creating a series


of programs to resolve a problem in a
computer.
The process constitutes many tasks:
Analyzing the problem
Create an algorithm to solve it
Convert the design to an actual computer
Program
Test and Examine the output

OF-FTI-ALL -18 1 10
Department of Information AUGUST 0
Chapter 2 2.1 Introduction to Programming Computer Programming
Many Aspects of
Programming
• Programming is problem solving
• always trying to make computer do something useful — i.e.,
finding an optimal travel route
• Programming is controlling
• computer does exactly what you tell it to
• Programming is teaching
• computer can only “learn” to do new things if you tell it how
• Programming is creative
• must find a good solution out of many possibilities
• Programming is modeling
• describe salient (relevant) properties and behaviors of a system of
components (objects)
• Programming is abstraction
OF-FTI-ALL -18 1 11
Department of Information AUGUST 1
Chapter 2 2.1 Introduction to Programming Programmer

Programmer

 Computer programs (also know as source


code) is often written by professionals known as
Computer Programmers
 "Programmer" or "Coder“: the person who writes
the code
 Programmers use various programming
languages to code the different parts of the
system.

OF-FTI-ALL -18 1 12
Department of Information AUGUST 2
Discussion

What is Programming
Language ?

1
Department of Information AUGUST 3
Programming
Chapter 2 1.1 Introduction to Programming
language

Programming language
• It is a set different category of written symbols
that instruct computer hardware to perform
specified operations required by the designer.
• an artificial language that can be used to control
the behavior of a computer
• A main purpose of programming languages is to
provide instructions to a computer.
• Programming languages have many similarities with
natural languages e.g., they conform to rules for
syntax and semantics, there are many dialects, etc.
1
Department of Information AUGUST 4
Programming
Chapter 2 2.1 Introduction to Programming
language

• But programming languages differ from


most other forms of human expression in
that they require a greater degree of precision
and completeness.
• When using a natural language to
communicate with other people, human
authors and speakers can be ambiguous and
make small errors, and still expect their
intent to be understood.
• However, computers do exactly what they are
told to do, and cannot understand the code
the programmer "intended" to write.
1
Department of Information AUGUST 5
Programming
Chapter 2 2.1 Introduction to Programming
language

• Every programming languages have


syntax and semantics
• defined by
• Syntactic - describes the possible
combinations of symbols that form a
syntactically correct program
• Semantic - The meaning given to a
combination of symbols
• In every programming Language there
are sets of rules that govern the symbols
used in a programming language.
1
Department of Information AUGUST 6
Programming
Chapter 2 2.1 Introduction to Programming
language

Some Well-Known
Programming Languages
C++
BASIC Ruby
FORTRAN
Java
Visual Basic
COBOL C#
JavaScript
C Python
1
Department of Information AUGUST 7
Types of
Chapter 2 2.1 Introduction to Programming programming
Types of programming language language

• Available programming
languages come in a variety of
forms and types. Thousands of
different programming languages
have been developed, used, and
discarded.
• Programming languages can be
divided in to two major
categories: 1
Department of Information AUGUST 8
Low-level languages
• Machine language
• Computers only understand one language and that is
binary language or the language of 1s and 0s.
• Binary language is also known as machine language,
one of low-level languages.
• In the initial years of computer programming, all the
instructions were given in binary form.
• Although the computer easily understood these
programs, it proved too difficult for a normal
human being to remember all the instructions in
the form of 0s and 1s.
• Therefore, computers remained mystery to a
common person until other languages such as
assembly language was developed, which were easier
to learn and understand
1
Department of Information AUGUST 9
---A. Low-level languages
• Assembly language
• correspondences symbolic instructions and executable
machine codes and was created to use letters (called
mnemonics) to each machine language instructions to make it
easier to remember or write. For example:
• ADD A, B – adds two numbers in memory location A and B
• Assembly language is nothing more than a symbolic
representation of machine code, which allows symbolic
designation of memory locations.
• However, no matter how close assembly language is to machine
code, computers still cannot understand it. The assembly
language must be translated to machine code by a separate
program called assembler.
• The machine instruction created by the assembler from the
original program (source code) is called object code.
• Thus assembly languages are unique to a specific computer
(machine). Department of Information AUGUST
2
0
---A. Low-level languages
• Assembly language
• The machine instruction created by the
assembler from the original program (source
code) is called object code.
• Thus assembly languages are unique to a
specific computer (machine).
• Assemblers are written for each unique
machine language.
• Although programming in assembly language
is not as difficult and error prone as stringing
together ones and zeros, it is slow and
cumbersome. 2
Department of Information AUGUST 1
B. High-level languages
• The lack of portability between different
computers led to the development of high-level
languages—so called because they permitted a
programmer to ignore many low-level details of
the computer's hardware.
• Further, it was recognized that the closer the
syntax, rules, and mnemonics of the programming
language could be to "natural language" the less
likely it became that the programmer would
inadvertently introduce errors (called "bugs")
into the program.
• High-level languages are more English-like and, 2
Department of Information AUGUST 2
----- B. High-level languages
• High-level languages also require translation to
machine language before execution.
• This translation is accomplished by either a compiler
or an interpreter.
• Compilers translate the entire source code program
before execution.
• Interpreters translate source code programs one
line at a time.
• Interpreters are more interactive than compilers.
• FORTRAN (FORmula TRANs,ator), BASIC (Bingers All
Purpose Symbolic Instruction Code), PASCAL, C, C++,
Java are some exa-ples of high-level languages.
2
Department of Information AUGUST 3
Low level vs High level
• low-level
• provide little or no abstraction, e.g., machine code and
assembly language
• Difficult to use
• Allows to program efficiently and with a low memory footprint
• used for communication with computer hardware
directly.
• Often written in binary machine code (0’s/1’s) directly.
• machine specific or dependent.

• high-level
• closer to human languages
• isolate the execution semantics of a computer architecture
from the specification of the program
• Simplifies program development Department of Information AUGUST
2
4
Why do we need
Chapter 2 2.1 Introduction to Programming
programming?
Why do we need programming?
• The main goal of programming is to make tasks easier
• If we program a task for one time, we can reuse it in many
similar situations, saving time.
• Computer programming will impact the future by creating
even more automated processes requiring less human
interaction.
• Banking from any location is possible only by
programming.
• For example, an online banking website or application
which opens a user portal from which the applicants can
make transactions using a smartphone or computer
• we can save time, energy, and physical work of going to the
bank for every small need.

OF-FTI-ALL -18 2 25
Department of Information AUGUST 5
2
Problem Solving

26 Introduction to ICT
2.2.1 Introduction Problem
Chapter 2 2.2 Problem Solving Introduction
Problem Solving
Solving
• Today, computers are all around us.
• We use them for doing various tasks in a faster
and more accurate manner.
• For example, using a computer or smartphone, to
book airplane tickets online.
• Computers are used for solving various day-to-
day problems
• Problem solving is an essential skill that a
student should know.

OF-FTI-ALL -18 2 27
Department of Information AUGUST 7
Introduction
Chapter 2 2.2 Problem Solving
Problem Solving
• Problem solving is the process of transforming the
description of a problem into the solution by using
our knowledge of the problem domain and by
relying on our ability to select and use appropriate
problem-solving strategies, techniques, and tools.
• Problem solving, or breaking down the solution to a
problem into sequential steps is by far the most difficult
part of computer programming.
• A problem is an undesirable situation that prevents the
organization from fully achieving its purpose, goals and
objectives.
• Or problem can also be defined as the gap between the
existing and the desired situation where problem
solving will try to fill this gap.
2
Department of Information AUGUST 8
Introduction
Chapter 2 2.2 Problem Solving
Problem Solving

• Computers themselves cannot solve a problem.


• Precise step-by-step instructions should be given by
programmers to solve the problem.
• A program is not needed only to solve a problem but
also it should be reliable, (maintainable) portable
and efficient.
• The success of a computer in solving a problem
depends on
• How correctly and precisely we define the problem
• Design a solution (algorithm)
• Implement the solution (program) using a programming
language.

OF-FTI-ALL -18 2 29
Department of Information AUGUST 9
Introduction
Chapter 2 2.2 Problem Solving
Problem Solving

so
• Problem solving is the process of
• Identifying a problem
• Developing an algorithm for the identified
problem
• Implementing the algorithm to develop a
computer program.

OF-FTI-ALL -18 3 30
Department of Information AUGUST 0
Introduction
Chapter 2 2.2 Problem Solving
Problem Solving

Example of Problem Solving


• Suppose while driving a car, the car starts making
a strange noise.
• We might not know how to solve the problem right
away.
• We need to identify from where the noise is coming?
• In case the problem cannot be solved by us, then we
need to take the car to a mechanic.
• The mechanic will
• Analyze the problem to identify the source of the noise
• Make a plan about the work to be done
• Repair the car in order to remove the noise

OF-FTI-ALL -18 3 31
Department of Information AUGUST 1
Steps of Problem
Chapter 2 2.2 Problem Solving
Solving
2.2.2 Steps of Problem Solving
• When problems are straightforward and
easy, we can easily find the solution.
• A complex problem requires a methodical
approach to find the right solution.
• Problem solving begins with the precise
identification of the problem and ends with
a complete working solution in terms of a
program.

OF-FTI-ALL -18 3 32
Department of Information AUGUST 2
Steps of Problem
Chapter 2 2.2 Problem Solving
Solving

Steps of Problem Solving ...


• Key steps required
for solving a problem
using a computer are
shown in Figure 2.1.

Figure 2.1: Steps for problem solving

OF-FTI-ALL -18 Iss 33


ue No 1
Steps of Problem
Chapter 2 2.2 Problem Solving
Solving

Step 1: Analyzing the Problem


• Clearly understand a problem before you begin to find
the solution for it.
• Read and analyze the problem statement carefully to
identify core functionalities that our solution should have.
• By analyzing a problem, we would be able to figure out
what are the inputs that our program should accept and
the outputs that it should produce.
• Understanding the purpose of a program usually involves
understanding:
• Inputs
• Processing
• Outputs
OF-FTI-ALL -18 3 34
Department of Information AUGUST 4
Steps of Problem
Chapter 2 2.2 Problem Solving
Step 2: Developing an Solving

Algorithm
• It is essential to devise a solution before
writing a program code for a given problem.
• The solution is represented in natural
language and is called an algorithm.
• Imagine an algorithm is like a very well-
written recipe for a dish, with clearly defined
steps that, if followed, one will end up
preparing the dish.

OF-FTI-ALL -18 3 35
Department of Information AUGUST 5
Steps of Problem
Chapter 2 2.2 Problem Solving
Solving

Step 3: Coding
• The algorithm need to be converted into
the format which can be understood by the
computer to generate the desired solution.
• Different high level programming languages
can be used for writing a program.
• It is equally important to record the details
of the coding procedures followed and
document the solution.

OF-FTI-ALL -18 3 36
Department of Information AUGUST 6
Steps of Problem
Chapter 2 2.2 Problem Solving
Solving

Step 4: Testing and Debugging


• The program created should be tested on
various parameters.
• The program should meet the requirements of the
user.
• It must respond within the expected time.
• It should generate correct output for all possible
inputs.
• The errors or defects found in the testing phases are
debugged and the program is again tested. This
continues till all the errors are removed from the
program.
OF-FTI-ALL -18 3 37
Department of Information AUGUST 7
Chapter 2 2.2 Problem Solving Algorithm
2.2.3 What is
Algorithm ?

• Here we will focus more on step 1:


algorithm design
• An algorithm is defined as a step-by-
step sequence of instructions that must
terminate and describe how the data is
to be processed to produce the desired
outputs.
• Simply, algorithm is a sequence of
instructions to solve a given problem.
Department of Information AUGUST
3
8
Chapter 2 2.2 Problem Solving Algorithm

• There are system analysis and design tools, that


can be used t/ define the problem in terms of the
steps to its solution. The programmer uses
programming language to communicate the logic
of the solution to the computer.
• Before a program is written, the programmer
must clearly understand what data are to be
used, the desired result, and the procedure to be
used to produce the result.
• The procedure, or solution, selected is
referred to as an algorithm.

3
Department of Information AUGUST 9
Chapter 2 2.2 Problem Solving Algorithm

Example Algorithm for Calculating Gross


Pay

4
Department of Information AUGUST 0
Chapter 2 2.2 Problem Solving Algorithm

• Why do we need an Algorithm?


• The purpose of using an algorithm is to increase the
reliability, accuracy and efficiency of obtaining
solutions.
• If the algorithm is correct, computer will run the
program correctly, every time.
• The programmer first prepares a roadmap of the
program to be written, before actually writing the
code.
• Without a roadmap, the programmer may not be
able to clearly visualize the instructions to be
written and may end up developing a program
which may not work as expected.
OF-FTI-ALL -18 4 41
Department of Information AUGUST 1
Characteristics of a
Chapter 2 2.2 Problem Solving
2.2.4 Characteristics of a Good Good Algorithm
Algorithm
A good algorithm is characterized by the following key attributes:
1. Input Specification
•The algorithm should have well-defined inputs that are clearly specified. It
may take zero or more inputs to process.
2. Output Specification
•The algorithm must produce at least one output, and the output should
be clearly defined and relevant to the problem being solved.
3. Finiteness
•A good algorithm should terminate after a finite number of steps. It
should not go into an infinite loop.
4. Definiteness
•Each step of the algorithm must be clear and unambiguous. There should
be no ambiguity in the instructions.
OF-FTI-ALL -18 Iss 42
ue No 1
Characteristics of a
Chapter 2 2.2 Problem Solving
Good Algorithm

5. Effectiveness
•All operations within the algorithm should be basic enough to be
executed in a finite amount of time using available resources.
6. Correctness
•The algorithm should correctly solve the problem for all defined inputs
and produce the expected outputs.
7. Efficiency
•The algorithm should make optimal use of resources like time (time
complexity) and space (space complexity). It should aim for minimal
computational and memory usage.
8. Robustness
•The algorithm should handle unexpected or invalid inputs gracefully,
providing appropriate feedback or handling mechanisms.

OF-FTI-ALL -18 Iss 43


ue No 1
Algorithm Design
Chapter 2 2.2 Problem Solving
2.2.5 Algorithm Design Techniques

Techniques
• There are three commonly used tools to help to
document program logic (the algorithm). These
are
1. flowcharts,
2. structured chart, and
3. Pseudocode.
• We will use the three methods here.
• Generally, flowcharts work well for small
problems but Pseudocode is used for larger
problems.

OF-FTI-ALL -18 4 44
Department of Information AUGUST 4
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
1. Pseudocode
• Is an artificial and informal
language that helps
programmers develop algorithms
• Allows the designer to focus on the
logic of the algorithm without being
distracted by details of language
syntax
• text-based" detail (algorithmic)
design tool 4
Department of Information AUGUST 5
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques

• Words that can be used for:


• Computation/Assignment
• set the value of "variable" to :"arithmetic expression" or
"variable" equals "expression" or
"variable" = "expression"
• Input/Output
• get "variable", "variable", ...
display "variable", "variable", ...
• Conditional
• if "condition"
(subordinate) statement 1
etc ...
else
(subordinate) statement 2
etc ...
• Iterative
• while "condition"
(subordinate) statement 1 Department of Information AUGUST
4
6
• Examples:
• Write a program that prints “passed” when the student garde
is greater than 60 and “failed” otherwise.
• If student's grade is greater than or equal to 60
• Print "passed"
• else
• Print "failed“
• Pseudo-code the task of computing the final price of an item
after figuring in Value Added Tax(VAT) rate. Note the three
types of instructions: input (get), process/calculate (=) and
output (display)
• 1. start
• 2. get price of item
• 3. get sales tax rate (VAT)
• 4. sales tax = price of item times sales tax rate
• 5. final price = price of item plus sales tax
• 6. display final price
• 7. stop

• Variables: price of item, sales tax rate, sales tax, final


price Department of Information AUGUST
4
7
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
2. Flow Chart
• Algorithm could be designed using many
techniques and tools.
• One tool of designing algorithm is by using
flowcharts.
• Flowchart is a graphical way of expressing the
steps needed to solve a problem.
• A flow chart is a schematic (diagrammatic
description) representation of a process.
• A graphic representation of an algorithm,
often used in the design phase of programming to
work out the logical flow of a program
4
Department of Information AUGUST 8
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Flowchart symbols

4
Department of Information AUGUST 9
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Control Structures
• programs could be written in terms
of 3 structures:
• Sequence – which instruction should be
done next?
• Selection – select between options
• Repetition – repeat an action while a
given condition stays true

5
Department of Information AUGUST 0
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Sequence: Executing instructions one after another as they
appear in the program.
.
Start

Input first
num
Input second
num
Sum=first num + second
num

avg=sum/2

Output sum

Output avg

End
5
Department of Information AUGUST 1
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Selection
• Diamond symbol (decision symbol)
• Indicates decision is to be made
True print
• Contains an expression that can be true
Grade>=60 passed
or false
• Test the condition, follow appropriate
path False
Single Selection (if)
If grade >=60
print passed
Double Selection (if-else)
• If grade >=60 :
passed False True
Grade>=60
else: Failed ? passed
failed

5
Department of Information AUGUST 2
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques

Selection (continued)
• Multiple Selection (switch)
If the light is ... Light True
Red? Stop
red -> stop
False
green -> go Light
True
Go
yellow -> slow down Green?
False
True
Light Slow
Yellow? Down
False

5
Department of Information AUGUST 3
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Repetition

Teaching a baby to
Counter = 1
count from 1 to 10:
counter = 1
Add 1
if counter <= 10:
to counter
increment counter
CounterTrue print counter number
Print
≤ 10?
counter
False

5
Department of Information AUGUST 4
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques

3. Structure Chart
• The structure chart is an important
technique that helps the analyst
design the program for the new
system.
• There are three components in the
structured chart: modules,
connections between modules, and
communication between modules.
5
Department of Information AUGUST 5
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Structure Chart Example
• A Simple Sequence Problem
We want to develop an algorithm (a step by step
process) for a program to calculate the sum and
average of two numbers entered by the user of the
program.

5
Department of Information AUGUST 6
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Cont…
• The structure chart shows the relationship
among the various components of the program.
• The top level is a general description of the
problem to be
• Solved where the lower levels show all the detail
or specifics of the solution.
• NOTE: The second level of a structure
chart attempts to break the solution into
three basic parts – an input module, a
processing module and an output module.

5
Department of Information AUGUST 7
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques

Examples

5
Department of Information AUGUST 8
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Example 1

5
Department of Information AUGUST 9
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution 1 for example 1
(simple)

6
Department of Information AUGUST 0
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution 1 for example 1 (More
technical)

6
Department of Information AUGUST 1
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution 1 for example 1 (Using Flow
chart)

6
Department of Information AUGUST 2
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Example 2
• Write an algorithm which calculates the average
exam grade for a class of 5 students.
What are the program inputs?
the exam grades
Processing:
Find the sum of the grades;
count the number of students; (counter controlled)
calculate average grade = sum of grades / number of students.
What is the program output?
the average exam grade

6
Department of Information AUGUST 3
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution : for example 2 (More
technical)
Pseudocode

6
Department of Information AUGUST 4
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution : for example 2 (Using
flow chart)
Flowchart

6
Department of Information AUGUST 5
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Example 3

6
Department of Information AUGUST 6
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution : for example 3
(simple Pseudo code)

6
Department of Information AUGUST 7
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution : for example 3 (More technical
Pseudo code and flowchart)

6
Department of Information AUGUST 8
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Example 4

6
Department of Information AUGUST 9
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution : for example 4
(Pseudo code)

7
Department of Information AUGUST 0
Algorithm Design
Chapter 2 2.2 Problem Solving
Techniques
Solution : for example 4
(Using flow chart)

7
Department of Information AUGUST 1
3
Program
development
process

72 Introduction to ICT
Mechanics of
Chapter 2 2.3 Program development process Creating a program
(C++ IDE)

OF-FTI-ALL -18 7 73
Department of Information AUGUST 3
Chapter 2 2.3 Program development process Introduction to C++

2.3.1 Introduction to C++


• Where did C++ come from?
• Derived from the C language
• C was derived from the B language
• B was derived from the BCPL language

7
Department of Information AUGUST 4
Chapter 2 2.3 Program development process C++ History

2.3.2 C++ History


• C developed by Dennis Ritchie at AT&T
Bell Labs in the 1970s.
• Used to maintain UNIX systems
• Many commercial applications written in c
• C++ developed by Bjarne Stroustrup at AT&T
Bell Labs in the 1980s.
• Overcame several shortcomings of C
• Incorporated object oriented programming
• C remains a subset of C++

7
Department of Information AUGUST 5
Chapter 2 2.3 Program development process C++ IDE

2.3.3. Mechanics of Creating


a program (C++ IDE)
• C++ programs typically go through
five phases to be executed: these
are
• edit,
• preprocess,
• compile,
• link,
• load:
OF-FTI-ALL -18 7 76
Department of Information AUGUST 6
Chapter 2 2.3 Program development process C++ IDE

---From a High-Level Program to an


Executable File

OF-FTI-ALL -18 7 77
Department of Information AUGUST 7
Chapter 2 2.3 Program development process C++ IDE

---Edit:
• this is accomplished with an editor program.
• The programmer types C++ statements with
the editor and makes corrections if necessary
• The programs source file is then stored on
secondary storage device such as a disk with a
“.cpp” file name.
• After the program is edited, C++ is principally
compiled in three phases: preprocessing,
translation to object code, and linking
• the last two phases are what is generally
thought of as the "compilation"
OF-FTI-ALL -18
process).
Department of Information AUGUST
7
8
78
Chapter 2 2.3 Program development process C++ IDE

---Preprocess:
• In a C++ system, a preprocessor program
executes automatically before the compiler’s
translation phase begins.
• The C++ preprocessor obeys command called
preprocessor directives, which indicate that
certain manipulations are to be performed on the
program before compilation.
• The preprocessor is invoked by the compiler
before the program is converted to machine
language.
• The C++ preprocessor goes
OF-FTI-ALL -18over
Department the program
of Information AUGUST
7
9
79
Chapter 2 2.3 Program development process C++ IDE

---Compile:
• Then, the C++ compiler translates the program
code.
• The compiler converts source code to object
code
• The compiler may be a true C++ compiler
which generates native (assembly or
machine) code.
• The outcome may be incomplete due to the
program referring to library routines which are
not defined as a part of the program.
80

OF-FTI-ALL -18 8
Department of Information AUGUST 0
Chapter 2 2.3 Program development process C++ IDE

---Linking:
• C++ programs typically contain references to
functions and data defined else where, such as
in the standard libraries.
• The object code produced by the C++ compiler
typically contains “holes” due to these missing
parts.
• A linker links the object code with the code for
the missing function to produce an executable
image (with no missing pieces).
• Generally, the linker completes the object code
by linking it with the object
OF-FTI-ALL -18code
Department of any library
of Information AUGUST
8
1
81
Chapter 2 2.3 Program development process C++ IDE

---Loading:
• the loader takes the executable file from
disk and transfers it to memory.
• Additional components from shared
libraries that support the program are
also loaded.
• Finally, the computer, under the control
of its CPU, executes the program.
• In practice all these steps are usually
invoked by a single command and the
user will not even see the intermediate
OF-FTI-ALL -18
Department of Information AUGUST
8
2
82
Chapter 2 2.3 Program development process C++ IDE

OF-FTI-ALL -18 8 83
Department of Information AUGUST 3
OF-FTI-ALL -18 8 84
Department of Information AUGUST 4

You might also like