You are on page 1of 37

Programming Fundamentals

Maryam Imtiaz Malik


maryam.imtiaz@numl.edu.pk
Books

Recommended Textbook(s) 1. C++ How to Program by Deitel and Deitel, 10th Edition, Pearson (2016)

Referenced Books 1. Starting out with Python, Tony Gaddis, Pearson; 4th edition (2017)
2. Starting out with Programming Logic & Designs, Tony Gaddis, Pearson; 4th
edition (2015)
3. Introduction to Computation and Programming Using Python: With
Application to Understanding Data, 2nd Edition by Guttag, John, MIT Press;
2nd edition (2016)
4. Practice of Computing Using Python by William Punch & Richard Enbody,
Pearson; 2nd edition (2012)
5. A first book of C++, Garry Bronson, 4th edition, Cengage Learning (2011)
Computer

A computer is a programmable electronic device that accepts raw data as input


and processes it with a set of instructions (a program) to produce the result as
output.
Program

A program is a set of instructions that a computer uses to perform a specific


function. 

Computer Programs are written in programming languages.

A person who develops a computer program is called Programmer.


Hardware and Software
Components of Computer/ Logical units
Anatomy of Memory

Memory Cell
Address of a memory cell
Contents of a memory cell
Stored Program Concept
RAM
ROM
Anatomy of Memory Contd.

Memory cell an individual storage location in memory

Address of a memory cell the relative position of a memory cell in the computer’s
main memory

Contents of a memory cell the information stored in a memory cell, either a


program instruction or data
Anatomy of Memory Contd.

Stored Program Concept instructions are represented in binary form and stored in
computer for execution.

Random Access Memory (RAM) is volatile memory. Data is not permanently


written. When you power off your computer the data stored in RAM is deleted.

Read Only Memory (ROM) is non volatile memory. Data is permanently written and
is not erased when you power off your computer.
Computer Languages

Lists of instructions for a computer to execute

Types of Computer Languages:


Low level Languages
High-level languages
1. Low level Languages

Near to computer hardware and far from human languages

Requires deep knowledge of internal structure of computer hardware

Programs in low level language are fast in execution


Machine Language

First Generation Language


A type of language in which instructions are written in binary form
It is directly understood by computer
It is not standardized
Different machine language for every type of CPU
Execution speed is very fast
Difficult to write, understand and modify
Assembly Language

Second Generation Language


One step higher than machine language
Computer operations are represented by mnemonic codes rather than binary
numbers.
Also called symbolic language
Example
2. High-Level Languages

Machine-independent programming language that combines algebraic expressions and English


symbols.
Easier to read, write and maintain.
The closer the instructions are to English-type words or human languages the more difficult it is
for the computer to interpret these instructions. 
High-level languages must be interpreted or converted (we would say, compiled) into machine
language before they can be executed/run by the computer 
High-level languages

Procedural Languages (tells computer what to do and how to do)


Non Procedural Languages (tells computer what to do not how to do)
Object Oriented Languages (programs are written on the basis of objects)
Procedural Languages (3GL)

FORTAN (Formula Translation)


Used for engineering
BASIC (Beginner All Purpose Symbolic Execution Code)
Solving simple problems
Used in education process
COBOL (Common Business Oriented Language)
Business application
Program are lengthy but easy to read, write and maintain
PASACAL
Scientific and business application
C (Middle level language)
Used to write application and system software
Non Procedural Languages (4GL)

Commonly used in database programming

SQL (Structured Query Language)


Database query language
Works with database program like
MS access
MS SQL Server
Object Oriented Languages

C++
Java
High Level Languages
Example

Machine binary language Low-level assembly High-level


Source Code & Object Code

Source Code Object Code


Source Code is written in high level or Object Code is written in machine
assembly language language through compliers
Source Code is easy to understand & Object Code is difficult to understand &
modify modify
Language Processor

Software that converts a high-level language program into machine language.


Compiler
Interpreter
Interpreter & Compiler

Interpreter Compiler

Interpreter converts a program into machine Compiler converts a program into machine code
code statement by statement as a whole

Interpreter does not create object code file Complier creates object code file

Interpreter converts high level program each Complier converts high level program that can
time it is executed be executed many times.

Program execution is slow Program execution is fast.

Interpreter displays the syntax error on each Compiler displays syntax errors after compiling
statement of program. the whole program.
Interpreter & Compiler
Entering, Translating & Running a
High Level Language Program
Linker & Loader

Linker Loader
It generates the executable module of a source It loads the executable module to the main memory.
program
It takes as input, the object code generated by a It takes executable module generated by a linker.
compiler.
It combines all the object modules of a source It allocates the addresses to an executable module in
code to generate an executable module. main memory for execution.
Problem Solving

Process of identifying a problem and finding the best solution for it.
Different strategies, techniques and tools are used to solve a problem.
Computers are used as a tool to solve complex problems by developing computer
programs
Problem Solving Activities in Daily Life

To make a Cup of tea

To get admission in BS

To create a statistical sheet for calculating & maintaining student records.


Problem Solving Techniques

Program

Algorithm & Pseudo code

Flowchart

etc.
Program

A set of instructions that tells a computer program what to do.

Computer Programs are written in programming languages.

A person who develops a computer program is called Programmer.


Programming

Process of writing a computer program in a language the computer can respond to and other
programmers can understand.
The set of instructions, data, and rules used to construct a program is called a programming
language.
Advantages of Computer Program

Solve many problems by giving instructions to computer


Perform a task repeatedly and quickly
Process a large amount of data easily
Display the results in different styles
Less time consuming
Algorithm

An Algorithm is a step-by-step procedure to solve a problem.

It is better to write algorithm before writing the actual computer program.

It is used to specify program logic in an English like manner that is independent of any
programming language.

A computer is an “algorithm-responding” machine; it’s not an “heuristic responding” machine.


Algorithmic & Heuristic Solutions

Algorithmic Solution
Sequence of actions to perform a task

Heuristic Solution
Require reasoning built on knowledge and experience.
Solutions that cannot be reached through a direct set of steps.
e.g. How to buy the best stock?
Example

Problem 1: How to add two numbers.

Solution:

1 Start
2 Enter number1
3 Enter number2
4 Result = number1 + number2
5 Display Result
6 End
References

Gary j. Bronson, A first book of C++, Garry Bronson, 4th edition (Section 1.1 of Chapter
1)
Maureen Sprankle et al, Problem Solving and Programming Concepts, 9th Ed. Prentice
Hall, 2011. (Chapter 1 + All the related topics of Flowchart and algorithms in book)

You might also like