0% found this document useful (0 votes)
58 views32 pages

Programming Fundamentals Overview

The document outlines the fundamentals of programming, including problem-solving processes, algorithms, pseudocode, and flowcharts. It discusses computer systems, their components, and the distinction between hardware and software, as well as programming languages from machine language to high-level languages. Additionally, it explains how computers store data and execute programs through various stages including compilation and interpretation.

Uploaded by

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

Programming Fundamentals Overview

The document outlines the fundamentals of programming, including problem-solving processes, algorithms, pseudocode, and flowcharts. It discusses computer systems, their components, and the distinction between hardware and software, as well as programming languages from machine language to high-level languages. Additionally, it explains how computers store data and execute programs through various stages including compilation and interpretation.

Uploaded by

imzainabdeura
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

PROGRAMMING

FUNDAMENTALS

UNIVERSITY OF MANAGEMENT AND


T E C H N O L O G Y, S I A L K O T C A M P U S

Lecturer : Fatima Khalil Butt


WEEK # 1
Reference Books:

• Book#1:
Starting out with Python, 4th Edition, Tony Gaddis. 2017 [Chapter#1
(1.2,1.3,1.4), Chapter#2 (2.1(Pseudocode, Flowchart),2.2)]

• Book#2:
C How to Program with an introduction to C++, 8th Edition by Paul Deitel &
Harvey Deitel 2015. [Chapter#1 (1.4,1.9)]

• Book#3:
Problem Solving and Program Design in C++, 7th Edition by Jeri R. Hanly &
Elliot B. Koffman 2000. [Chapter#1 (1.2,1.3,1.4)]
LECTURE # 1
Introduction to Problem Solving:
 Programming is a process of Problem Solving.
 In a programming environment, the problem-solving
process requires the following three steps:
1. Analyze the problem, outline the problem and its
solution requirements, and design an algorithm to
solve the problem.
2. Implement the algorithm in a programming
language, such as C++, and verify that the
algorithm works.
3. Maintain the program by using and modifying it if
the problem domain changes.
How to Write a Program?
Algorithms:
Input
Algorithm: A step-by-step procedure for solving a problem in a
finite amount of time.
Features of an algorithm:
Finiteness: An algorithm terminates after a fixed number of steps. Set of instructions that need to be
followed to obtain expected output
Definiteness: Each step of the algorithm is precisely defined. for given input
Effectiveness: All the operations used in the algorithm can be
performed exactly in a fixed duration time.
Input: An algorithm has certain precise inputs before the
execution of the algorithm begins. Output
Output: An algorithm has one or more outputs
Pseudocode:
 Word “pseudo” means fake, so pseudocode is fake code.
 It is an informal language that has no syntax rules and is not meant
to be compiled or executed.
Rules to follow while writing pseudocode:
• Write in plain language that describes the logic of the program.
• Use meaningful names for variables and functions that convey
their purpose.
• Use indentation to show hierarchy and structure, like how code is
structured.
• Clearly indicate the end of structures and procedures
Flowchart

 A flowchart is a diagram that graphically


depicts the steps that take place in a program.

 There are three types of symbols in the


flowchart: ovals, parallelograms, and a
rectangle. Each of these symbols represents a
step in the program.
1. Make cup of tea.
2. C = A + B
3. Z = (A + B) – C
Practice: Algorithms,
• Condition : S = A+B. If S < C, then add C to S until S
Pseudocode, become greater than C
Flowchart 4. Z = (A+B) – (C+D)
• Condition : S=A+B T=C+D. If S < T, then add T to S until
S become greater than T
5. Check whether ‘n’ is even or odd number.
6. Check whether user is “Teacher” or “Student”
Practice: Check whether given number "n" is even or odd. If n
is even, then print “even” else print “odd”.

Algorithm: START
Flowchart:
1. Start
2. Input the value of n
3. If n%2 = 0 then print Input ‘n’
(“even”).Go to Step 5.
4. print(“odd”)
5. Stop

Pseudocode:
If n%2 == 0?
NO YES
START
READ n Print
Print (“EVEN”)
IF (n%2 = 0 ) THEN
(“ODD”)
print(“even”)
ELSE
print(“odd”)
ENDIF
END END
LECTURE # 2
What is Computer System?
 Computers are programmable devices which receive,
store, process, and output information.

 Computers are digital electronic device which


understands only 0’s and 1’s.

 They can perform all type of arithmetic computations


(Addition, multiplication...) and non arithmetic
computations (copy, choose, move, compare….)
Computer Systems:
Modern computers are categorized according to their size and performance.

Super Computer Mainframe computer Personal Computer (PC)

• Largest Capcity and Fastest • High performance • General-purpose computer


(in terms of speed of computer designed for individual use.
processing data) • Used for large-scale, • Used for personal work
• Used in Weather compute-intensive such as making an
Forecasting, Scientific purposes & tasks that assignment, watching a
Research Laboraraties, require greater availability movie etc.
Stock Market etc. and security like ATM & • For example, Laptops and
other Banking sectors etc. desktop computers.
Components of Computer System:
Computer Components fall into two major categories: Hardware and Software

Computer Hardware: Computer Software: Set of programs


Physical equipment used to perform the that enable us to solve problems with a
necessary computations computer by providing it with lists of
instructions to perform.
Computer Programs and Programming
Languages:
 Computer Program: Set of instructions that a
computer follows to perform a task. Set of programs are
commonly referred to as Software.

 Without Computer Programs, Computer is virtually


useless as it does not have any thinking or decision-taking
power of its own.

 Programming languages allow us to write computer


programs and thus to communicate with computers.
Computer Organization | Von Neumann
Architecture
 Most modern computers are based on a stored-program
concept introduced by John Von Neumann.

 In this stored-program* concept, programs


(instructions) and data are stored in the same memory.

 Computer built with this architecture would be much


easier to reprogram.
Computer Organization | Von Neumann
Architecture
Computer Hardware
All physical devices or components of which a computer is made are referred to as the
computer’s hardware.
Most computer system consists of the following major components:
o Main Memory:
• Main memory stores programs, data, and results. 1
• Main memory is commonly known as random-access memory,
or RAM. 2
• RAM is a volatile type of memory that is used only for temporary
storage while a program is running.

o Central Processing Unit (CPU):


• Also known as microprocessors.
Computer Hardware
• Part of the computer that follows the instructions (program) stored in main
memory.1
• Made up of the arithmetic/logic unit (ALU)2 and control unit (CU)3

o Secondary storage devices:


• Can hold data for long periods of time, even when there is no power to the
computer.
• Programs are normally stored in secondary memory and loaded into main
memory as needed.

o Input Devices: Devices that feed data and programs into computers e.g.,
keyboard, mouse, touchscreen, scanner, microphone and secondary storage
devices.

o Output Devices: Devices that computer uses to display results e.g.,


monitor, printer, and secondary storage devices.
Computer Software
Set of programs that allow the hardware to operate are called Software.
 All software are written in programming languages.
 Two general categories of software:

• Programs that control & manage the basic operations of a computer


System Software • System Software includes these types of programs: Operating System
(OS)1, Utility Programs2, Software Development Tools3

• Assist a computer user in accomplishing specific tasks.


Application • Examples: Microsoft Word - word processing program, PowerPoint -
Software presentation program, game programs, database management system
etc.
LECTURE # 3
How Computer Store Data?
 All Instructions and data that are stored in a computer’s
memory are converted to sequences of 0s and 1s.

 Binary Code - Sequence of 0s and 1s is referred to as a


binary code or a binary numbers.

 Bytes - Computer’s memory is divided into tiny storage


locations known as bytes.

1 Byte = 8 bits
 Bits - Each byte is divided into eight smaller storage
locations known as bits. Could be 0 or 1.
Computer Languages : Machine
Language
Machine Language:
• Computer’s CPU can only understand and execute
programs(instructions) that are written in machine
language (sequence of 0s and 1s).

• Drawback of machine language is that it is not


standardized, and machine dependent.

• Only consistency among computers is that in any


modern computer, all data and instructions are stored
together in the computer’s memory using binary codes.
Computer Languages: Machine
Language
How Does Computer Run Program (Instructions)?

 When a computer(CPU) executes the


instructions in a program, it perform a
process known as the fetch-decode-execute
cycle.

 This cycle, which consists of three steps, is


repeated for each instruction in the program.
Computer Languages: Assembly
Language
Assembly Language:
• For programmers, programming in machine language was
tedious and time-consuming process as it was prone to
error and difficult to read and modify.

• For this reason, Assembly Languages were developed to


make the programmer’s job easier.

• Instead of using binary numbers for instructions, assembly


language uses short , easy-to-remember words that are
known as mnemonics.
Computer Languages: Assembly
Language
How Does Computer Run Program (Instructions)?
• Computer (CPU) cannot execute assembly
language instructions directly.

• Instructions first must be translated into


machine language.

• Special program called an assembler


translates the assembly language
instructions into machine language.

• Machine language program that is created


by the assembler can then be executed by
the CPU.
Computer Languages: High-Level
Language
High Level Languages:
• Assembly language is primarily a direct substitute for
machine language, but like machine language, it
requires that programmer must know how the CPU
works.

• Also, in assembly language, programmers still had to


use numerous instructions to accomplish even the
simplest tasks.

• To speed the programming process, High-Level


Languages were developed in which single
statements could be written to accomplish basic tasks.
Computer Languages: High-Level
Language
High Level Languages:
• High-level language allows you to create complex programs without knowing how the CPU works.

• High-level languages are machine-independent and standardized programming languages that


combines algebraic expressions and English symbols.

• As the computer understands only machine language


instructions, programs that are written in a high-level
language must be translated into machine language.

• Depending on the language in which a program has been


written, the programmer will use either a compiler or an
interpreter to make the translation.
Computer Languages: High-
Level Language

Compiler:
• Compiler is a program that translates a high-
level language program into a separate
machine language program.

• Converts entire high-level language


programs to machine language at once

• Examples: C, C++ , Java, Rust, Swift


Computer Languages: High-
Level Language

Interpreter:
• Interpreter is a program that both
translates and executes the instructions
in a high-level language program.

• Because interpreters combine


translation and execution, they typically
do not create separate machine
language programs.

• Examples: Python, JavaScript, Ruby,


PHP
Computer Languages: High-Level
Language
How Does Computer Run a C++ Program?

• Step-1: Write C++ program in editor and save it


on secondary storage device.
• Step-2: Preprocessor* program executes
automatically before the compiler’s translation
phase begins.
• Step-3: Compiler** translates the C++ program
into machine-language code.
• Step-4: Resolve the references to functions
defined elsewhere, such as in the standard
libraries or in the private libraries. ***
Computer Languages: High-Level
Language
How Does Computer Run a C++ Program?

• Step-5: Before a program can be executed, the


program must first be placed in memory.
• Step-6: CPU executes the program one
instruction at a time

You might also like