Introduction To Computer Programming Concepts
Introduction To Computer Programming Concepts
Programming Concepts
Computer Programming
Computers do what we tell them
to do, NOT what we want them to
do
Computer Programming involves
Object Code
Source Code Compiler
ExecuteProgram
Execute Program
Using Interpreter:
Executeaaline
Execute line
Source Code Interpreter ofProgram
Program
of
Well Designed Programs.
Well designed programs must be:
◦ Correct and accurate
◦ Easy to understand
◦ Easy to maintain and update
◦ Efficient
◦ Reliable
◦ flexible
Programming Process
1. Problem definition
◦ What must the program do?
◦ What outputs are required and in what form?
◦ What inputs are available and in what form?
Example: Find a maximum of two numbers
◦ Input two numbers, compare them and print
the maximum value
◦ Inputs and outputs are decimal numbers
◦ Inputs are entered from the keyboard
◦ Result is shown on the monitor
Programming Process
2. Program Design involves creating an
algorithm – sequence of steps, by which a
computer can produce the required outputs
from the available inputs
Top-down design
◦ The main problem is split into subtasks
◦ Then each subtask is divided into simpler
subtasks, etc. unless it is clear how to solve
all such subtasks
Programming Process
#include <stdio.h>
3. Program Coding int main()
means expressing {
the algorithm int number1, number2;
developed for int maximum;
solving a problem,
in a programming printf("Please, enter two numbers: ");
scanf("%d %d", &number1, &number2);
language
if (number1 >= number2)
Example of source maximum = number1;
else
code is on the
maximum = number2;
right
printf(“%d is maximum\n“,
maximum);
return 0;
Programming Process
Program Compilation – translation of a program
written in a high-level programming language into
machine language instructions
Compilation step converts a source program into an
intermediate form, called object code
Linking step is necessary to combine this object code
with other code to produce an executable program
The advantage of this two-step approach:
◦ Source of the large program may be split into more
than one file
◦ These files are worked on and compiled separately
◦ Object code may be stored in libraries and used for
many programs
◦ Then they will be combined into one executable code
Programming Process
4. Program Testing & Debugging
◦ Initially, almost all programs may contain a few
errors, or bugs
◦ Testing is necessary to find out if the program
produces a correct result. Usually it is performed
with sample data
◦ Debugging is the process of locating and removing
errors
Types of Errors.
Syntax Errors: Violation of syntactic rules in a Programming
Language generates syntax errors.
◦ Effect? Interpreters and Compilers can not notice them, but on execution,
they causes unexpected results.
◦ Effect? It occurs on run time and may crash the program execution
Successful Programming
For successful programming
give no ambiguity in program instructions
give no possibility of alternative
interpretations
make sure there is only one course of action
Programming
Programming task can be made easier
◦ by breaking large and complex programs into smaller and
less complex subprograms (modules)
Programming task can be separated into 2 phases
(see Fig. 1)
1. problem solving phase
◦ produce an ordered sequence of steps that describe
solution of problem
◦ this sequence of steps is called an algorithm
2. implementation phase
◦ implement the program in some programming language
(Pascal, Basic, C)
Programming
Difficult
way
What is structured programming
a programming technique that splits the program
into smaller segments (modules) to
decrease program development time
decrease program maintenance cost
improve the quality of software
structured programming achieves these goals by
using
top-down design and use of modules
use of limited control structures (sequence, selection and
repetition)
management control
Types of Programming Languages.
Mov ax, 1
Mov bx, 2
Add bx
Types of Programming Languages.
Assembly Language
Writing programs can be very time-consuming,