0% found this document useful (0 votes)
33 views23 pages

C++ Chapter 1

The document provides an overview of programming fundamentals, including the definition of programming, the importance of programming languages, and the skills required to be a programmer. It categorizes programming languages into five generations and discusses various programming paradigms such as procedural, structured, and object-oriented programming. Additionally, it outlines the problem-solving process, algorithm design, and the mechanics of creating a program, specifically in C++.

Uploaded by

yesusgooftadha6
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)
33 views23 pages

C++ Chapter 1

The document provides an overview of programming fundamentals, including the definition of programming, the importance of programming languages, and the skills required to be a programmer. It categorizes programming languages into five generations and discusses various programming paradigms such as procedural, structured, and object-oriented programming. Additionally, it outlines the problem-solving process, algorithm design, and the mechanics of creating a program, specifically in C++.

Uploaded by

yesusgooftadha6
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

Fundamentals of Programming

Introduction to Computer
Programing

Salale University
College of Natural Science
Department of Computer science
Computer Science Staff
2021

05/14/2025 Fundamentals of Database Systems 1


TOutline
Introduction
Programming
 A skill that can be acquired by a computer professional that gives him/her the knowledge of making the computer perform the
required operation or task.
Computer programming
 Critical if one wants to know how to make the computer perform a task.
 Most users of a computer only use the available applications on the computer.
 These applications are produced by computer programmers.
Programming Language:
 A set different category of written symbols that instruct computer hardware to perform specified operations required by the designer.

What skills Programming Language Skill: knowing one or more programming


do we language to talk to the computer and instruct the machine to
need to be perform a task.
a • Problem Solving Skill: skills on how to solve real world problem
programm
• Algorithm Development: skill of coming up with sequence of simple and human
er? understandable set of instructions showing the step of solving the problem.
Those set of steps should not be dependent on any programming language or
 machine.
Every programming Language there are sets of rules that govern the symbols used in a programming language.
 These sets of rules are called syntax.
Generations of programming language

Programming languages are categorized into five generations: (1st, 2nd, 3rd, 4th and 5th generation
languages)
o Low level languages are machine specific or dependent.(first and second generation languages)
o High level languages like COBOL, BASIC are machine independent and can run on variety of computers.
First Generation (Machine languages, 1940’s):
 Difficult to write applications with.
 Dependent on machine languages of the specific computer being used.
 Is more powerful in utilizing resources of the computer.
 Gives power to the programmer.
 They execute very quickly and use memory very efficiently.
Second Generation (Assembly languages, early 1950’s):
 Uses symbolic names for operations and storage locations.
 A system program called an assembler translates a program written in assembly
language to machine language.
 Programs written in assembly language are not portable.
 They are highly used in system software development.
Cont’d…

Third Generation (High level languages, 1950’s to 1970’s):


Uses English like instructions and mathematicians were able to define
variables with statements such as Z = A + B
Such languages are much easier to use than assembly language.
Programs written in high level languages need to be translated into
machine language in order to be executed.
The use of common words (reserved words) within instructions makes
them easier to learn.
All third generation programming languages are procedural languages.
In procedural languages, the programmer is expected to specify what is
required and how to perform it.
Fourth Generation (since late 1970’s):
Have a simple, English like syntax rules; commonly used to access
databases.
Forth generation languages are non-procedural languages.
In non-procedural languages the programmer is not required to write
traditional programming logic.
Cont’d…
Fifth Generation (1990’s):
These are used in artificial intelligence (AI) and expert systems; also used for accessing
databases.
5GLs require very powerful hardware and software because of the complexity involved in
interpreting commands in human language

Tip
Common high level languages include:
FORTRAN (Formula Translator) - designed for scientific and engineering applications.
COBOL (Common Business Oriented Language) - developed for business data processing
applications.
BASIC (Beginners All purpose symbolic instruction code) - designed for end user
programming (interactive programming)
Pascal - developed specifically to incorporate structured programming concept.
C - a powerful language for the construction of system programs
C++ - an enhanced version of C that includes object orientation
Java - used for programming WWW applications and corporate intranets and extranets.
Major Programming Paradigms

Procedural Programming.
 Procedural programming is often a better choice than simple sequential programming in many
situations which involve moderate complexity or which require significant ease of maintainability.
Possible benefits: the ability to re-use the same code (function or procedure) at different places, an
easier way to keep track of program flow than a collection of “GO TO” or “JUMP” statements.
Structured Programming.
 Structured programs are built up from units called modules, which normally correspond to single
procedures or functions.
Object-Oriented Programming.
 The idea behind OOP is that, a computer program is composed of a collection of individual units,
or objects as opposed to traditional view in which a program is a list of instructions to the
computer.
 Object-oriented programming is claimed to give more flexibility, easing changes to programs.
 The OOP approach is often simpler to develop and maintain.
Problem solving process
The systems Preliminary Investigation
approach to Analysis
problem Design
solving Implementation
involves the
Testing and Maintenance
following
system
development
life cycles
(SDLC):
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.

top-down development and the alternate approach is called bottom-up development.

In top-down design
• systematic approach based on the concept that the structure of the
problem should determine the structure of the solution and what
should be done in lower level.
• This approach will try to disintegrate a larger problem into more
smaller and manageable problems to narrow the problem domain.
Bottom up Development

•Bottom up design: is the reverse process where the lowest level


component are built first and the system builds up from the bottom
until the whole process is finally completed.
Basic Program development tips

The program we Reliable: the program should always do what it is expected to do and handle
design in any all types of exception.
programming ƒ Maintainable: the program should be in a way that it could be modified
language need to and upgraded when the need arises.
be: ƒ Portable: It needs to be possible to adapt the software written for one type
of computer to another with minimum modification.
ƒ Efficient: the program should be designed to make optimal use of time,
space and other resources of the computer.
Algorithm designing
When developing a program to solve a given problem, one should follow the
following steps

Understan Algorithm Coding Implementation


ding the design (writing the • Debugging -process of
problem •is generating a source code) removing errors by using error
• Closely looking finite set of • the stage where diagnosing features of the
into the unambiguous steps each statement language and by tracing.
problem which, if followed of the algorithm • Testing- process of checking to
domain and correctly, will is translated in determine whether the program
clearly solve the problem. to a target does what it is designed to do.
identifying the programming • Documenting- is about creating
inputs and language. related information and
outputs comments about the program.
Cont’d…
Algorithm: is an ordered set of unambiguous, executable steps, defining a termination process.
Important property of an algorithm
• Correct
 Always returns the desired output for all legal instances of the problem.
• Unambiguous
 the statements must be interpretable in a unique way
 Each step must be clearly defined, having only one interpretation.
• Precise
 Simple but efficient
• Efficient
 Can be measured in terms of
• Time, Space
 Time tends to be more important
• Executability
 it must be possible to execute each statement (in a finite amount of time) given the available
resources
Problem Solving Techniques
 There are three program logic (the algorithm).
 Flowcharts
 structured chart
 Pseudo code

Generally, flowcharts work well for small problems but Pseudo code is used for larger
problems.

05/14/2025 Compiled by Tadesse B (MSc) 13


Pseudo code
 A program design technique that uses English words.
 Has no formal syntactical rules.
 typically omits details such as subroutines, variables declarations and system-specific syntax.
Example:
 Write a program that obtains two integer numbers from the user. It will print out the sum
of those numbers.
Pseudo code:
Prompt the user to enter the first integer
Prompt the user to enter a second integer
Compute the sum of the two user inputs
Display an output prompt that explains the answer as the sum
Display the result

05/14/2025 Compiled by Tadesse B (MSc) 14


structured chart
 Depicts the logical functions to the solution of the problem using a chart.
 Confirms the solution to the problem without excessive consideration to detail.
 It is high-level in nature.
Example:
 Write a program that asks the user to enter a temperature reading in centigrade and then
prints the equivalent Fahrenheit value.

Celsius To Fahrenheit
Input Process Output (Main Function)
Centigr  Prompt for Fahrenh
ade centigrade eit
value Centigrade Fahrenheit
 Read
Calculate
centigrade Input Centigrade
Fahrenheit
Output Fahrenheit
value
 Compute
Fahrenheit Fahrenheit
05/14/2025 value Compiled by Tadesse B (MSc) 15

Flowchart
 A schematic representation of an algorithm or a process.
 it doesn’t depend on any particular programming language
 translate an algorithm to more than one programming language.
 uses different symbols (geometrical shapes) to represent different processes.

05/14/2025 Compiled by Tadesse B (MSc) 16


Cont’d…

05/14/2025 Compiled by Tadesse B (MSc) 17


Cont’d…
Example 1:
 Draw flow chart of an algorithm to add two numbers and display their result.
Algorithm description The flow chart is
Read the rules of the two numbers (A and B)
Add A and B Start

Assign the sum of A and B to C


Read A, B
Display the result ( C)
C=A+ B

Print C

End

05/14/2025 Compiled by Tadesse B (MSc) 18


Cont’d…
Example 2:
 Write an algorithm description and draw a flow chart to check a number is negative or
not.
Algorithm description
Read a number x
if x is less than zero write a message negative
else write a message not negative

05/14/2025 Compiled by Tadesse B (MSc) 19


Compilers and Interpreters
 Any program written in a la be translated to machine language. The set of instructions that do this task are known as translators.
 There are different kinds of translator software's among which compilers and interpreters are of interest for most programmers.

Compilers: a compiler is a computer program that translates a series of statements written in source code (a
collection of statements in a specific programming language) into a resulting object code (translated
instructions of the statements in a programming language).
Example: C++, Pascal, FORTRAN, etc.
Interpreters: is a computer program that translates a single high level statement and executes it and then
goes to the next high level language
• line etc.
Example: QBASIC, Lisp etc.
Mechanics of Creating a program (C++)
 C++ programs typically go through five edit, preprocess, compile, link, load:
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"
process).
Preprocess: a preprocessor program executes automatically before the compiler’s translation
phase begins.
The preprocessor is invoked by the compiler before the program is converted to machine
language.
The C++ preprocessor goes over the program text and carries out the instructions specified by the
preprocessor directives (e.g., #include).
Cont’d…
Compile: Then, the C++ compiler translates the program 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.
example, the << operator which is actually defined in a separate IO library.
Linking: 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 code of any library
modules that the program may have referred to.
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.
Cont’d…

You might also like