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

Programming by Haile

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

Programming by Haile

programming language c++
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

PROGRAMMING C++

Introduction to programming
Computer is a machine that needs instruction to perform a
variety of tasks.
A program is a set of instruction that the computer to follow
to perform a given job.
C++ is one of the most powerful programming languages
available.
Language translator software is used by programmers to
develop application software and translate programs into
machine code (object code).
Language software is a generic name consisting of various
programs that serves as editors and translators to develop
programs in different programming language.
It includes translators and high level language software’s.
Type of programming language
1. Machine language: lowest level of programming languages
usually referred to as first generation language.
It is understood completely by computer; Instruction in machine
language is in the form of string of 0s and 1s.

2.Assembly language: referred to as second generation language.


These languages use symbols or mnemonic codes to describe machine
instructions.
It is machine dependent languages.

3.High level language: language that look like natural language.


High level languages are further subdivided into
three generations:
A.Third generation languages: need to spell out in detail each step and
the exact order of steps the computer system must take to accomplish a
task.

 Procedure- oriented language: organize instructions into group of


functions and give little attention to the data that are used by various
function. FORTRAN, PASCAL
 Object- oriented language: treat data as critical element in the
program development

Decompose a problem into a number of entities called objects and


build data and functions around these objects. E.g. Java, C++ visual
basic and so on
B.Fourth generation languages: Allow
computer user to retrieve, manipulate and
analyze data from computer storage
without requiring step by step procedure.
Designed to solve specific problems.
Example Query languages and report
generator.
C.Fifth generation languages: Close to
natural languages. Program written in
5GLs tell the computer what to do not how
to do
A program written in assembly language or high level language
is called the sources code and the translated machine code
program is called the object code.
Translator: is a program that converts one or more language to
another language.
There are three types of translators such as:
1.Assembler:Translating assembly language into object code
2.Compiler:Translating the whole source codes written in high
level languages into the object code prior to loading the whole
source code into main memory and executing.
3.Interpreters: translate and executes and each instruction or
source statements before going onto the next instruction.
In the case of an assembler or a compiler, the source codes
need only be translated once unless the source code itself is
modified.
In the case of interpreter, the source code is translated every
1.2. CHARACTERISTICS OF A GOOD PROGRAM
Every computer requires appropriate instruction set
(programs) to perform the required task.
The quality of the processing depends upon the given
instructions.
If the instructions are improper of incorrect them it is
obvious that the result will also be superfluous.
Therefore, proper and correct instructions should be
provided to the computer so that it can fulfill its duties
appropriately.

Hence, a program should be developed in such a way that it


ensures proper functionality of the computer.
Even from the human point of view, a program should be
written in such a manner that it is easier to understand the
underlying logic.
1. Portability: refers to the ability of an application to run on
different platforms (operating systems) without or with
minimal changes.
Due to rapid development in hardware and the software,
nowadays platform change is a common phenomenon.
Hence, if a program is developed for a particular platform
then the life span of the program is severely affected.
2. Readability: The program should be written in such a way
that it makes other programmers or users follow the logic of
the program is written structurally, it even helps the
programmer himself to follow his own program in a better
way if he is away from in for some time.
Notice that even if you had to sacrifice some computational
efficiency for better readability then it is advisable to use
more user-friendly approach unless the application’s
processing is of utmost importance.
3. Efficiency: Every program requires certain processing time
and memory to process the instructions and data.
As you must have realized, processing power and memory
are the most precious resources of a computer, a program
should be laid out in such a manner that it utilizes the least
amount of memory and processing time.

4. Structural:To develop a program, the task must be broken


down into a number of subtasks. These subtasks should be
developed independently, that is each subtask should be able
to perform the assigned job without the help of any other
subtask.

If a program is developed structurally, the program not only


becomes more readable, but the testing and documentation
process also gets easier.
5. Flexibility: A program should be flexible enough to handle most of the
changes without having to rewrite the entire program. Most of the programs
are developed for a certain period and they require changes from time to
time. For example, in case of payroll management, as the time progresses,
some employees may leave the company while some may join. Hence, the
payroll application should be flexible enough to incorporate all the changes
without having to reconstruct the entire application.
6. Generality: Apart from flexibility, the program should also be general. We
mean that if a program is developed for a particular task then it should also be
used for all similar tasks of the same domain. For example, if a program is
developed for a particular organization then should suit all the other similar
organizations.
7. Documentation: Documentation is one of the most important components
of an application development Even if a program is developed following the best
programming practices, it will be rendered useless if the end user is not able to
fully utilize the functionality of the application A well-documented application is
also useful for programmers because even in the absence of the author, other
programmers can understand it.
1.3 Problem solving techniques
A program consists of a series of instructions that a computer
processes to perform the required operation.
In addition, it also includes some fixed data, required to perform
the instructions, and the process of defining those instructions
and data.
Thus, in order to design a program, a programmer must
determine three basic rudiments:
• the instructions to be performed.
• the order in which those instructions are to be performed.
• the data required to perform those instructions.
Programming involves many stages such as task analysis,
planning the logic, program flowcharting, coding, program
testing, implementation, documentation and maintenance.
There are five steps for program/software development such
as task analysis, program (Algorithm) design, coding testing,
implementation, and maintenance.

1.Analysis: the steps at which defining and understanding the


problem.
In this phase work out what must be done rather than how to
do it. It include identifying
• Which part of the problem is going to be solved
• What input data are needed to the problem
• What output data are expected
• What procedure are needed to achieve the goal
2. Program (Algorithm) design: this phase design a solution to
solve the problem.An algorithm is a finite set of steps to a
problem.
To design an algorithm for specific problem we first break down the
problem into simpler and manageable tasks.
This approach is said to be top down approach.
The algorithm that we select must be:
• Simple and powerful
• There must be no ambiguity in any instruction
• There should not be any uncertainty about which instruction is
to be executed next
• The description of the algorithm must be finite. Algorithm
cannot be open ended
• The execution of algorithm should conclude after a finite
number of steps
• The algorithm must be general enough to deal with any
contingency.
Correct: easy to maintain and correct
Does the algorithm terminate?
Do the appropriate input data produce expected output data?
Does properly handle valid and extreme cases?
Efficient: it does not take too much space and time Before writing an
algorithm for a problem, one should find out what is/are the inputs to the
algorithm and what is/are expected output after running the algorithm.
Now let us take some exercises to develop an algorithm for some simple
problems:
While writing algorithms we will use following symbol for different
operations:
Pseudo code
THANK YOU

You might also like