CP Chapter 1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 52

Chapter 1

Introduction to Computer Programming

1
2
Introduction cont..
• A Computer is an electronic device that accepts:

 Data

 performs computations, and

 makes logical decisions according to instructions that have been given to it.

• 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 app to the complex nuclear energy production.


3
Introduction cont..

• In order to solve a given problem, computers must be given the correct instruction about

how they can solve it.

• Electrical signals are used inside the computer to process information.

• Analog signals are continuous wave forms used to represent things as sound. Audio

tapes, for example, store data in analog signals.

• Digital signals represent information with a sequence of 0s and1s. A 0 represents a low

voltage, and a 1 represents a high voltage.

• The digit 0 or 1 is called a binary digit, or bit or binary code or binary number
4
Introduction cont..
• Machine language, is a sequence of 0s and 1s that computer reads and interprets.

• The most basic language of a computer, the machine language, provides program

instructions in bits.
• Even though most computers perform the same kinds of operations, the designers of the

computer may have chosen different sets of binary codes to perform the operations.
• Therefore, the machine language of one machine is not necessarily the same as the

machine language of another machine.


• The only consistency among computers is that in any modern computer, all data is stored

and manipulated as binary codes.


5
The evolution of programming and programing language

• The terms computer programs, software programs, or just programs are the instructions that

tells the computer what to do.

• Computer programming (often shortened to programming or coding) is the process of

writing, debugging/troubleshooting,testing, and maintaining the source code of computer

programs.

• A computer program usually consists of two elements:

 Data – characteristics

 Code – action
6
cont..

• A computer program (also known as source code) is 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 English), are defined by syntactic

and semantic rules which describe their structure and meaning respectively.
7
cont..

• 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.

• In general, programming languages allow humans to communicate instructions to

machines.

 Programming languages can be divided in to two major categories:

 Low-level languages

 High-level languages
8
Low-level languages
• The most basic language of a computer which provides instruction in bits.

• 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.
9
cont..
• 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: Wages = rate • hours

• If binary code 100100 stands for load, 100110 stands for multiplication, and 100010 stands

for store.

• In machine language, you might need the following sequence of instructions to calculate

weekly wages:
10
cont..
100100 010001

100110 010010

100010 010011

• Assembly language is nothing more than a symbolic representation of machine code,

which allows symbolic designation of memory locations.

• In assembly language, an instruction is an easy-to-remember form called a mnemonic.

• However, no matter how close assembly language is to machine code, computers still

cannot understand it.


11
cont..

• The instructions first have to be translated into machine language. A program called an

assembler translates the assembly language instructions into machine language(object

code). Some examples of instructions in assembly language and their corresponding

machine language code.

• You can calculate the weekly wages as follows:

LOAD rate

MULT hours

STOR wages
12
High-level languages
• Programming in assembly language is slow, cumbersome hardware specific. The lack of

portability between different computers led to the development of high-level languages.

• High-level languages are more English-like and, therefore, make it easier for programmers

to "think" in the programming language.

• High-level languages also require translation to machine language before execution.

• Compilers translate the entire source code program before execution.

• Interpreters translate source code programs one line at a time.


13
cont..

Some example:

• FORTRAN (FORmula TRANslator),

• BASIC (Beginner’s All Purpose Symbolic Instruction Code),

• PASCAL,

• C/C++/C#

• Python,

• Java

• JavaScript/PHP.
14
Programming Paradigm
• The question of which language is best is ,common question among computer

professionals,one that consumes less time and energy is preferable.

• Every language has its strengths and weaknesses.There is no single standard for

classifying programming languages.

• One way programming languages are characterized (categorized) is by programming

paradigm. It is an approach to solve problem using some programming language or it is

a method to solve a problem using tools and techniques that are available to us following

some approach.
15
Procedural Programming Languages
• Procedural programming specifies a list of operations that the program must complete to

reach the desired state.

• Each program has a starting state, a list of operations to complete, and an ending point.

This approach is also known as imperative programming.

• Procedures, also known as functions, subroutines, or methods, are small sections of code

that perform a particular action.


16
cont..

• By splitting the programmatic tasks into small pieces, procedural programming allows a

section of code to be re-used in the program without making multiple copies.

• It also makes it easier for programmers to understand and maintain program structure.

• Two of the most popular procedural programming languages are FORTRAN and BASIC.
 FORTRAN Programming
program addNumbers Output:
real :: a, b, result The total is 27.0
a = 12.0
b = 15.0
result = a + b
print *, 'The total is ', result
end program addNumbers
17
Structured Programming Languages
• Structured programming is a special type of procedural programming.

• It provides additional tools to manage the problems that larger programs were creating.

• Structured programming requires that programmers break program structure into small

pieces of code that are easily understood.

• One of the well-known features of structural programming is that it does not allow the use of

the GOTO statement.

• It is often associated with a "top-down" approach to design.

• The most popular structured programming languages include C, Ada, and Pascal.
18
Structured Programming Languages
 C Programming
#include <stdio.h>
Output:
int main()
27
{
int number1, number2, sum;
number1=12;
number2=15;
// calculate the sum
sum = number1 + number2;
printf("%d", sum);
return 0;
}
19
Object-Oriented Programming Languages

• Object-oriented programming is one the new and most powerful paradigms.

• In object- oriented programs, the designer specifies both the data structures and the types

of operations that can be applied to those data structures.

• This pairing of a piece of data with the operations that can be performed on it is known as an

object oriented programming.

• A program thus becomes a collection of cooperating objects, rather than a list of

instructions.
20
cont..

• Objects can store state information and interact with other objects, but generally each

object has a distinct, limited role.


• Some example:
• C++,
• Java,
• Smalltalk,
• Delphi,
• C#,
• Perl,
• Python,
• Ruby,
• and PHP.
21
cont..
 Java Programming
import java.util.Scanner; Output:
public class SumOfNumbers2 Enter the first number: 12
{ Enter the second number: 15
public static void main(String args[]) The sum of two numbers x and y is: 27
{
int x, y, sum;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the first number: ");
x = sc.nextInt();
System.out.print("Enter the second number: ");
y = sc.nextInt();
sum = x+y;
System.out.println("The sum of two numbers x and y is: " + s
um);
}
}
22
Problem solving Techniques
• In computer programming two facts are given more weight:

 Defining the problem and logical procedures to follow in solving it.

 Introduces the means by which programmers communicate those procedures to the

computer system so that it can be executed.

• There are system analysis and design tools, particularly flowchart and structure chart, that

can be used to 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.
23
cont..
• 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 execute and

describe how the data is to be processed to produce the desired outputs.

• Simply algorithm is a sequence of instructions.

• There are three commonly used tools to help to document program logic (the algorithm).

These are flowcharts, structured chart, and pseudo code.


24
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 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.


25
cont..

• 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 syntax rules of any

particular language;

• there is no systematic standard form, although any particular writer will generally borrow

the appearance of a particular language.


26
cont..
Example1:

Original Program Specification: Write a pseudocode for a program that obtains two integer

numbers from the user and 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
27
cont..
Example2: Write a pseudocode to find the largest of two numbers by accepting numbers from
user and print out the largest one.
BEGIN
NUMERIC nNum1,nNum2
DISPLAY "ENTER THE FIRST NUMBER : "
INPUT nNum1
DISPLAY "ENTER THE SECOND NUMBER : "
INPUT nNum2
IF nNum1 > nNum2
DISPLAY nNum1 + " is larger than "+ nNum2
ELSE
DISPLAY nNum2 + " is larger than " + nNum1
END
28
cont..

Exercise:

Write a pseudocode for a program that obtains one integer number from the user and print out

the square of the number.


29
Structured Charts
• Structured chart depicts the logical functions to the solution of the problem using a chart. It

provides an overview that 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.


30
cont..
31
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 be 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.


32
cont..
33
Cont..
• Example 1: Draw flow chart of an algorithm to add two numbers and display their result.
34
Cont.….
• Example2: Draw flow chart of an algorithm that check whether a number is negative or not.
35
Cont..
 Loops
• Sometimes there is a situation in which it is necessary to execute a group of statements
repeatedly until some condition is satisfied. This situation is called a loop.
• Loop is a sequence of instruction, which is repeated until some specific condition occurs.
• The general execution flow structure of loops looks like the following.
36
Cont..

• Example 3: - Write the algorithmic description and draw a flow chart to find the following

sum.

• Sum = 1+2+3+…. + 50
37
Cont..
Example 4: Draw flowchart to find factorial of a positive integer n
38
Cont..
Example 5: Draw flowchart to calculate tax deduction of employees based on the following
requirement:
Requirement: For salary more than 500 birr, tax is 5% of the salary, and for salary less than
500 birr, tax is 3% of the salary.
39
Cont..
Example 6: Draw flowchart to find largest of two numbers.
40
Cont..
Example 7: Draw flowchart to find largest number from three numbers.
41
Cont..
Example 8: Draw a flowchart and algorithm that will determine and print out the sum of all
even and odd integer numbers from 1 to 100.
42
System Development Life Cycle (SDLC)
• The Systems 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:

• Feasibility study • Implementation

• Requirements analysis • Testing

• Designing solution • Maintenance


43
Cont.…
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.

• 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.


44
Cont..
• 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:


• Organizational Feasibility: How well the proposed system supports the strategic objectives

of the organization.

• Economic Feasibility • Decreased investment


• Cost savings • Increased revenue
• Increased profits
45
Cont..
• Technical Feasibility

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

• Operational Feasibility

• End user acceptance

• Management support

• Customer, supplier, and government requirements


46
Cont..

Requirements analysis

• Requirements analysis is a software engineering task that bridges the gap between system

level requirements engineering and software design.

• Requirements analysis provides the software designer with a representation of information,

function, and behavior that can be translated to data, architectural, interface, and component-

level designs.

• End users must be involved in this process to ensure that the new system will function

adequately and meets their needs and expectations.


47
Cont..

Designing solution

• Software design is an iterative process through which requirements are translated into a

“blueprint” for constructing the software.

• Initially, the blueprint depicts a holistic view of software.

• That is, the design is represented at a high level of abstraction , a level that can be directly

traced to the specific system objective and more detailed data, functional, and behavioral

requirements.
48
Cont..

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.

• Implementation requires programming, but it also requires database creation and

population, and network installation and testing.

• Product implementation can be an exciting phase for the customer, because their idea for

the project becomes something tangible.


49
Cont..
Testing

• Testing, mostly known software testing, is an activity performed for evaluating product

quality and for improving it by identifying defects and problems.

• Software testing can be conducted as soon as executable software (even if partially

complete) exists.

• A primary purpose of testing is to detect software failures so that defects may be discovered

and corrected.

• Testing is not performed only during testing phase.


50
Cont..
• Implementation teams, the software coders, are expected to perform two forms of testing

Unit testing and Integration testing.


Target of the test are:

Errors: These are actual coding mistakes made by developers. In addition, there is a
difference in output of software and desired output is considered as an error.

Fault: When error exists fault occurs. A fault, also known as a bug, is a result of an error
which can cause system to fail.

Failure: failure is said to be the inability of the system to perform the desired task.
Failure occurs when fault exists in the system.
51
Cont..
Maintenance

• Maintenance is simply the bulkiest and life long process out of the software development
activities.

• It mainly is concerned with keeping the delivered software operational by providing


maintenance services in time of failure and new needs arise.

• This may not be performed by the development team instead the customer company may
hire additional IT expert to look after this job.
52

You might also like