0% found this document useful (0 votes)
55 views9 pages

C++ Module Chapter 1

The document discusses introduction to computers and programming, types of programming languages including low-level and high-level languages, compilers and interpreters, and software development life cycle including feasibility study, requirements analysis, and designing solution.

Uploaded by

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

C++ Module Chapter 1

The document discusses introduction to computers and programming, types of programming languages including low-level and high-level languages, compilers and interpreters, and software development life cycle including feasibility study, requirements analysis, and designing solution.

Uploaded by

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

Fundamental of programming I 2010

Chapter One

1. Introduction to programming
1.1 General introduction to computer and programming

A Computer is an electronic device that accepts data, performs computations, and makes logical
decisions according to instructions that have been given to it; then produces meaningful
information in a form that is useful to the user. In current world we live in, computers are almost
used in all walks of life for different purposes. They have been deployed to solve different real
life problems, from the simplest game playing up to the complex nuclear energy production.
Computers are important and widely used in our society because they are cost-effective aids to
problem solving in business, government, industry, education, etc.

In order to solve a given problem, computers must be given the correct instruction about how
they can solve it. The terms computer programs, software programs, or just programs are the
instructions that tells the computer what to do. Computer requires programs to function, and a
computer programs does nothing unless its instructions are executed by a CPU. Computer
programming (often shortened to programming or coding) 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. Each instruction is relatively simple, yet because of the
computer's speed, it is able to run millions of instructions in a second. A computer program
usually consists of two elements:
 Data – characteristics
 Code – action
Computer programs (also known as source code) are often written by professionals known as
Computer Programmers (simply programmers). Source code is written in one of programming
languages. A programming language is an artificial language that can be used to control the
behavior of a machine, particularly a computer. Programming languages, like natural language
(such as Amharic), are defined by syntactic and semantic rules which describe their structure and
meaning respectively. The syntax of a language describes the possible combinations of symbols
that form a syntactically correct program. The meaning given to a combination of symbols is
handled by semantics. Many programming languages have some form of written specification of
their syntax and semantics; some are defined only by an official implementation. In general,
programming languages allow humans to communicate instructions to machines.

A main purpose of programming languages is to provide instructions to a computer. As such,


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. So computers need to be

Compiled by: Inst. Mezgebe A. Department of Computer SciencePage 1


Fundamental of programming I 2010
instructed to perform all the tasks. The combination of the language definition, the program, and
the program's inputs must fully specify the external behavior that occurs when the program is
executed. Computer languages have relatively few, exactly defined, rules for composition of
programs, and strictly controlled vocabularies in which unknown words must be defined before
they can be used.
Types of programming languages
 programming languages can be categorized into two broad categories:
1. low level programming languages
A. Machine languages:
 Difficult to write applications with.
 Dependent on machine languages of the specific computer being used.
 Machine languages allow the programmer to interact directly with the hardware, and it can
be executed by the computer without the need for a translator.
 Is more powerful in utilizing resources of the computer.
 Gives power to the programmer.
 They execute very quickly and use memory very efficiently.
B. Assembly languages:
 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. i.e., different computer
architectures have their own machine and assembly languages.
 They are highly used in system software development.
2. High level Programming languages
 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.

Compilers and Interpreters


 Any program written in a language other than machine language needs to be translated to
machine language. The set of instructions that do this task are known as translators.
 There are different kinds of translator software, 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). A compiler changes or translates the whole source code into executable

Compiled by: Inst. Mezgebe A. Department of Computer SciencePage 2


Fundamental of programming I 2010
machine code (also called object code) which is output to a file for latter execution. E.g.
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. E.g. QBASIC, Lisp etc.

1.2 Software Development Life Cycle (SDLC)

A Software Development Life Cycle (SDLC) is a conceptual model used in project management
that describes the stages involved in a computer system development project from an initial
feasibility study through maintenance of the completed application. The phases of SDLC are
discussed below briefly.

1.2.1 Feasibility study

The first step is to identify a need for the new system. This will include determining whether a
business problem or opportunity exists, conducting a feasibility study to determine if the
proposed solution is cost effective, and developing a project plan.

This process may involve end users who come up with an idea for improving their work or May
only involves IS people. Ideally, the process occurs in tandem with a review of the
organization's strategic plan to ensure that IT is being used to help the organization achieve its
strategic objectives. Management may need to approve concept ideas before any money is
budgeted for its development.

A preliminary analysis, determining the nature and scope of the problems to be solved is carried
out. Possible solutions are proposed, describing the cost and benefits. Finally, a preliminary plan
for decision making is produced.

The process of developing a large information system can be very costly, and the investigation
stage may require a preliminary study called a feasibility study, which includes e.g. the following
components:

a. Organizational Feasibility

 How well the proposed system supports the strategic objectives of the organization.

b. Economic Feasibility

 Cost savings
 Increased revenue
 Decreased investment
 Increased profits

c. Technical Feasibility

 Hardware, software, and network capability, reliability, and availability

Compiled by: Inst. Mezgebe A. Department of Computer SciencePage 3


Fundamental of programming I 2010
d. Operational Feasibility

 End user acceptance


 Management support
 Customer, supplier, and government requirements

1.2.2 Requirements analysis

Requirements analysis is the process of analyzing the information needs of the end users, the
organizational environment, and any system presently being used, developing the functional
requirements of a system that can meet the needs of the users. Also, the requirements should be
recorded in a document, email, user interface storyboard, executable prototype, or some other
form. The requirements documentation should be referred to throughout the rest of the system
development process to ensure the developing project aligns with user needs and requirements.

End users must be involved in this process to ensure that the new system will function
adequately and meets their needs and expectations.

1.2.3 Designing solution

After the requirements have been determined, the necessary specifications for the hardware,
software, people, and data resources, and the information products that will satisfy the functional
requirements of the proposed system can be determined. The design will serve as a blueprint for
the system and helps detect problems before these errors or problems are built into the final
system. The created system design, but must reviewed by users to ensure the design meets users'
needs.

1.2.4 Testing designed solution

A smaller test system is sometimes a good idea in order to get a “proof-of-concept” validation
prior to committing funds for large scale fielding of a system without knowing if it really works
as intended by the user.

1.2.5 Implementation

The real code is written here. Systems implementation is the construction of the new system and
its delivery into production or day-to-day operation. The key to understanding the
implementation phase is to realize that there is a lot more to be done than programming.
Implementation requires programming, but it also requires database creation and population, and
net work installation and testing. You also need to make sure the people are taken care of with
effective training and documentation. Finally, if you expect your development skills to improve
over time, you need to conduct a review of the lessons learned.

i. Testing

There are different testing methods some of these are as follows:

Compiled by: Inst. Mezgebe A. Department of Computer SciencePage 4


Fundamental of programming I 2010
1.2.6.1 Unit testing

Normally programs are written as a series of individual modules, these subjects to separate and
detailed test.

1.2.6.2 Integration and System testing

Brings all the pieces together into a special testing environment, then checks for errors, bugs and
interoperability. The system is tested to ensure that interfaces between modules work (integration
testing), the system works on the intended platform and with the expected volume of data
(volume testing) and that the system does what the user requires (acceptance/beta testing).

1.2.7 Maintenance/Documentation

What happens during the rest of the software's life: changes, correction, additions, and moves to
a different computing platform and more. This, the least glamorous and perhaps most important
step of all, goes on seemingly forever.

1.3 Algorithm development and representation


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. 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. Algorithms are a fundamental
part of computing. There are two commonly used tools to help to document program logic (the
algorithm). These are flowcharts and Pseudocode. We will use the two methods here.
Generally, flowcharts work well for small problems but Pseudocode is used for larger problems.

1.3.1 Pseudocode

Pseudocode (derived from pseudo and code) is a compact and informal high-level description of
a computer algorithm that uses the structural conventions of programming languages, but
typically omits details such as subroutines, variables declarations and system-specific syntax.
The programming language is augmented with natural language descriptions of the details,
where convenient, or with compact mathematical notation. The purpose of using pseudocode is
that it may be easier for humans to read than conventional programming languages, and that it
may be a compact and environment-independent generic description of the key principles of an
algorithm. No standard for pseudocode syntax exists, as a program in pseudocode is not an
executable program. As the name suggests, pseudocode generally does not actually obey the
synatx rules of any particular language; there is no systematic standard form, although any
particular writer will generally borrow the appearance of a particular language.

The programming process is a complicated one. You must first understand the program
specifications, of course, Then you need to organize your thoughts and create the program. This
is a difficult task when the program is not trivial (i.e. easy). You must break the main tasks that
must be accomplished into smaller ones in order to be able to eventually write fully developed

Compiled by: Inst. Mezgebe A. Department of Computer SciencePage 5


Fundamental of programming I 2010
code. Writing pseudocode will save you time later during the construction & testing phase of a
program's development.

Example:

Original Program Specification:

Write a program that obtains two integer numbers from the user. It will print out
the sum of those numbers.

Pseudocode:

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

1.3.2 Flowchart

A flowchart (also spelled flow-chart and flow chart) is a schematic representation of an


algorithm or a process. The advantage of flowchart is it doesn’t depend on any particular
programming language, so that it can used, to translate an algorithm to more than one
programming language. Flowchart uses different symbols (geometrical shapes) to represent
different processes. The following table shows some of the common symbols.

Compiled by: Inst. Mezgebe A. Department of Computer SciencePage 6


Fundamental of programming I 2010

Example 1: - Draw flow chart of an algorithm to add two numbers and display their result.
Algorithm description Start
 Read the rules of the two numbers (A and B)
 Add A and B
 Assign the sum of A and B to C Read A, B
 Display the result ( c)
The flow chart is
C= A+B

End

Example 2: Write an algorithm description and draw a flow chart to check a number is negative
or not.

Algorithm description.
1/ Read a number x
2/ If x is less than zero write a message negative
else write a message not negative

start
Compiled by: Inst. Mezgebe A. Department of Computer SciencePage 7
Fundamental of programming I 2010

read x

NO
x<0 print not -ve
yes

print -ve

stop

Sometimes there are conditions in which it is necessary to execute a group of statements


repeatedly. Until some condition is satisfied. This condition is called a loop. Loop is a sequence
of instructions, which is repeated until some specific condition occurs. A loop normally consists
of four parts. These are:
Initialization: - Setting of variables of the computation to their initial values and setting the
counter for determining to exit from the loop.
Computation: - Processing
Test: - Every loop must have some way of exiting from it or else the program would endlessly
remain in a loop.
Increment: - Re-initialization of the loop for the next loop.

Example 3: - Write the algorithmic description and draw a flow chart to find the following sum.
Sum = 1+2+3+…. + 50
Algorithmic description
1. Initialize sum to 0 and counter to 1
1.1. If the counter is less than or equal to 50

• Add counter to sum


• Increase counter by 1
• Repeat step 1.1
1.2. Else
• Exit

Compiled by: Inst. Mezgebe A. Department of Computer SciencePage 8


Fundamental of programming I 2010

2. Write sum

Compiled by: Inst. Mezgebe A. Department of Computer SciencePage 9

You might also like