[go: up one dir, main page]

0% found this document useful (0 votes)
20 views24 pages

Chapter One - Introduction - Part I

Document

Uploaded by

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

Chapter One - Introduction - Part I

Document

Uploaded by

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

{

Start course;

Computer Programming (CoSc1012);


{

Start chapter;
{
Chapter One→ Introduction;

June 1, 2024 By Kibru G. 1


Introduction to Programming
▪ Computer ?
▪ 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.
▪ Computer programs ?
▪ Sets of instructions that control a computer’s processing of data
▪ the instructions that tells the computer what to do
▪ Computer programming ?
▪ is the process of writing, testing, debugging / troubleshooting, and
maintaining the source code of computer programs.
June 1, 2024 By Kibru G. 2
Introduction to Programming

▪ Computer programs (also know as source code) is often


written by professionals known as Computer Programmers

▪ A computer program usually consists of two elements:


▪ Data – characteristics-what is being manipulated.
▪ Code – actions on the data- the operations the program does.

June 1, 2024 By Kibru G. 3


Introduction to Programming

▪Computer programs are Sequences of instructions


expressed in specific programming language:
▪ as a result, programs cannot be ambiguous
▪ all instructions together are called source code
▪ Executed by computer by carrying out or following
individual instructions
June 1, 2024 By Kibru G. 4
Introduction to Programming
▪ Source code is written in a programming languages.
▪ What is Programming Language?
▪ Programming Language – is an artificial language with a set of
rules, symbols, and special words used to construct a computer
program. It is used for controlling the behavior of a computer.
▪ Is defined by:
▪ Syntactic - describes the possible combinations of symbols that
form a syntactically correct program
▪ Semantic - The meaning given to a combination of symbols
▪ computers do exactly what they are told to do

June 1, 2024 By Kibru G. 5


Types and usage of computer languages
▪ There are many languages for writing programs. But they can be categories broadly into
three categories.
1. Machine language(binary language)
▪ The most elementary and first type of computer language invented, was machine
language.
▪ Machine language is a collection of binary digits or bits that the computer reads and
interprets.
▪ Machine language was machine dependent means different computers understand
different sequences.
▪ It is computer’s native language, sequence of zeroes and ones (binary)
▪ Machine languages are the only languages understood by computers.
▪ Might be hard for humans to understand: 01010001

June 1, 2024 By Kibru G. 6


Cont.
2. Assembly language

▪ A program written in assembly language consists of a series of instructions mnemonics that


correspond to the executable instructions.

▪ Assembly language instructions and their translation into zeros and ones differ from machine
to machine.

▪ machine language programming was simply too slow tedious for most programmers.

▪ still hard for humans to understand on complex program: example ADD X Y Z

▪ Any Assembly language program must be translated into machine language (by a program
called an assembler) before the computer can understand and execute the program.

June 1, 2024 By Kibru G. 7


Cont.
3. High-level languages
▪ They are designed to be easy for human beings to write programs in and to be easy for human
beings to read.
▪ High level languages are the computer language in which it is much easier to write a program than
the low level language.
▪ A program written in high level language is just like giving instruction to person in daily life
▪ closer to natural language such as English easier to read and understand:
▪ Low-level languages are closer to the language used by a computer, while high-level languages are
close to human languages.
▪ FORTRAN, Pascal, BASIC, C, C++, Java, etc.

June 1, 2024 By Kibru G. 8


Interpreting vs Compiling program
▪ Any high-level language program must be translated into machine language
before the computer can understand and follow the program.
▪ Each type of computer only “understands” its own machine language (zeroes
and ones)
▪ Compiler: is to transform a program written in a high level programming
language from source code into object code.
▪ Interpreter: is a program that executes instructions written in a high-level
language. They do the same thing but interpreter works each statement at a
time.
▪ https://www.geeksforgeeks.org/difference-between-compiler-and-interpreter

June 1, 2024 By Kibru G. 9


What is Compiler?
▪ A compiler is a computer program that transforms code written in a high-level
programming language into the machine code.
▪ It is a program which translates the human-readable code to a language a
computer processor understands (binary 1 and 0 bits).
▪ The computer processes the machine code to perform the corresponding tasks.
▪ A compiler should comply with the syntax rule of that programming language
in which it is written.
▪ However, the compiler is only a program and can not fix errors found in that
program.
▪ So, if you make a mistake, you need to make changes in the syntax of your
program. Otherwise, it won’t compile.

June 1, 2024 By Kibru G. 10


Compiler compiling phases
▪ It is used by the compiler to achieve compile-time efficiency.
▪ It is used by various phases of the compiler as follows:-
▪Lexical Analysis: Creates new table entries in the table, for example like entries about tokens.
▪Syntax Analysis: Adds information regarding attribute type, scope, dimension, line of
reference, use, etc. in the table.
▪Semantic Analysis: Uses available information in the table to check for semantics i.e. to verify
that expressions and assignments are semantically correct(type checking) and update it
accordingly.
▪Intermediate Code generation: Refers symbol table for knowing how much and what type of
run-time is allocated and table helps in adding temporary variable information.
▪Code Optimization: Uses information present in the symbol table for machine-dependent
optimization.
▪Target Code generation: Generates code by using address information of identifier present
in the table.

June 1, 2024 By Kibru G. 11


How compiler works?

June 1, 2024 By Kibru G. 12


Basic Compiling and linking process

June 1, 2024 By Kibru G. 13


What is Interpreter?
▪ An interpreter is a computer program, which converts each high-level program
statement into the machine code.

▪ This includes source code, pre-compiled code, and scripts.

▪ Both compiler and interpreters do the same job which is converting higher level
programming language to machine code.

▪ However, a compiler will convert the code into machine code (create an exe) before
program run.

▪ Interpreters convert code into machine code when the program is run.

June 1, 2024 By Kibru G. 14


Cont.

June 1, 2024 By Kibru G. 15


Cont.
▪ Compiler transforms code written in a high-level programming language into
the machine code, at once, before program runs,
▪ whereas an Interpreter converts each high-level program statement, one by one,
into the machine code, during program run.
▪ Which one is faster, compiler or interpreter? Reading assignment
▪ Compiler displays all errors after compilation, on the other hand, the Interpreter
displays errors of each line one by one.
▪ Compiler is based on translation linking-loading model, whereas Interpreter is
based on Interpretation Method.
▪ Compiler takes an entire program whereas the Interpreter takes a single line of
code

June 1, 2024 By Kibru G. 16


Problem Solving Techniques

June 1, 2024 By Kibru G. 17


Programming paradigm
▪ A computer program usually consists of two elements:
▪ Data – characteristics
▪ Code – action
▪ Some program development approaches conceptually organize the program around the code:
▪ Around what is happening
▪ known as Process oriented approach/ method, which characterizes the program as serious
linear steps.
▪ Code acting on data
▪ Other programming languages conceptually organize the program around data:
▪ Who is being affected
▪ designed to manage increasing complexity.
▪ Ask not what your code does to your data structure, but what your data structure can do for
you

June 1, 2024 By Kibru G. 18


Programming paradigm
▪ It is a fundamental style of computer programming, a way of building the structure
and elements of computer programs.

▪ Capabilities and styles of various programming languages are defined by their


supported programming paradigms;

▪ Some programming languages are designed to follow only one paradigm, while others
support multiple paradigms

▪ Programming paradigms that are often distinguished include declarative, Procedural


and object-oriented programming

June 1, 2024 By Kibru G. 19


Procedural (imperative) programming
▪ Based upon the concept of procedure call and top down approach. A procedure call is
used to invoke the procedure

▪ Procedures (routines, subroutines, methods, functions) simply contain a series of


computational steps to be carried out to solve a problem.

▪ Any given procedure might be called at any point during a program's execution,
including by other procedures or itself.

▪ Procedural programming is a list or set of instructions telling a computer what


to do step by step and how to perform from the first code to the second code.
June 1, 2024 By Kibru G. 20
Cont.
We have a single program, which is divided into small pieces called procedures

Procedural programming languages include C++, FORTRAN, Pascal, and BASIC.

June 1, 2024 By Kibru G. 21


Declarative (Functional) Programming
▪ Is when you write your code such a way that is describes what you want to do not how
you want to do it. It needs to perform logic.

▪ Program describes logic rather than control flow

▪ Program describes “what” rather than “how”.

▪ Aims for correspondence with mathematical logic

▪ Automatic reasoning by applying inference rules

▪ SQL , Markup languages, Lisp, Prolog.

▪ Functional programming is becoming popular paradigm now days.

June 1, 2024 By Kibru G. 22


Object Oriented Programming
▪ Is a method of implementation in which programs are organized as cooperative
collections of objects.
▪ Data and operations are grouped together
▪ Each object is capable of receiving messages, processing data, and sending
messages to other objects
▪ Modeling of the domain as objects so that the implementation naturally reflects
the problem at hand.
▪ Examples: C++,Java…C#..

June 1, 2024 By Kibru G. 23


Cont.

June 1, 2024 By Kibru G. 24

You might also like