8/21/2019 PSP Lecture1
1/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Problem Solving and Programming
Zafar [email protected]
8/21/2019 PSP Lecture1
2/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Course Outline
Sessional# 1
Sessional# 2
Terminal
If time permits
Course Evaluation
Sessional (Each): 12.50%
Quizzes 5%
Assignments 10%
Project 10%
Final 50%
Topic Sessions
Introduction to Problem Solving and Programming 1
Problem Solving Concept for the Computer 2--4
Constants and Variables -- Rules and Data types -- Operators -- Expression and Equality
Logic Structures 5--7
Programming Structures -- Modules and Functions -- Cohesion and Coupling
Local and Global Variables -- Pointers/Parameters/Return Values
Sequential Logic Structures 8--9
Flow Charts -- Sequential Logic
Decision Logic Structures 10--11
Decision Logic Structures [IF, ELSE IF, ELSE] -- Case Logic Structure
Loop Logic Structures 12--14
Counter Loop -- Conditional Loop -- Repeat Until -- Array
Introduction to Programming: Syntactic Constructs
Syntactic and Program Conventions -- Decision Logic and Loop logic Structures 15--18
Function, Parameters and Overloading 19--21
Project Assignment
User Define Data type/ Pointers/ Array and Link List 22--24
File Processing 25--26
Sequential Access
Program Testing and Debugging 27--28
Documentation 29--30
Some additional topics
8/21/2019 PSP Lecture1
3/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Books
Problem Solving and Programming Concepts 7th Ed.
By Maureen Sprankle
How to solve it by Computer.By R. G. Dromey
Algorithm Development and Program Design using C.
By Gary J. Bronson
8/21/2019 PSP Lecture1
4/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Introduction to ComputerSystem
Lecture# 1
8/21/2019 PSP Lecture1
5/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Lecture Objectives
Introduction to Computer Systems
Components of a Computer System Input/Output Devices
Motherboard Processor
Memory Main memory
Secondary memory
Bits and Bytes
Software Types of software
8/21/2019 PSP Lecture1
6/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Introduction to Computer Systems
A data processing machine capable ofperforming computations and makinglogical decisions very fast
A computer is a complex system consistingof both hardwareand softwarecomponents.
Computer System
Hardware Software
8/21/2019 PSP Lecture1
7/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
A computer system consists of bothhardware and software components.
The hardwarecomponents of a computer
system are the electronic and mechanicalparts.
The softwarecomponents of a computersystem are the intangible parts: the dataand the computer programs.
Components of a Computer System
8/21/2019 PSP Lecture1
8/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
The major hardware components of acomputer system are: Processor
Main memory
Secondary memory
Input devices
Output devices
The processor, main memory, secondarymemory, and power supply are inside thesystems unit/Box.
Components of a Computer System
8/21/2019 PSP Lecture1
9/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Components of a Computer System
Peripheral Devices Keyboard
Mouse
Monitor .. etc Input Devices
Mouse
Keyboard .. etc
Output Devices Monitor
Printer .. etc
8/21/2019 PSP Lecture1
10/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Input/Output Devices
Input and output devices allow the computer system tointeract with the outside world by moving data intoand out
ofthe system.
An input device is used to bring data into the system.
Some input devices are: Keyboard
Mouse
Microphone
Bar code reader
Light pen
An output deviceis used to send data out of the system.
8/21/2019 PSP Lecture1
11/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Some output devices are: Monitor, Printer, Speaker etc
Input/output devices are usually called I/O devices.
They are directly connected to an electronic moduleinside the systems unit called a device controller.
For example, the speakers of a multimedia
computer system are directly connected to a device
controller called an audio card (such as a
SoundBlaster), which in turn is connected to the rest
of the system.
Input/Output Devices
8/21/2019 PSP Lecture1
12/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
The terms "input" and "output" say if dataflow into or out of the systems unit.
The picture shows the major hardwarecomponents of a computer system. Thearrows show the direction of data flow.
Components of a Computer System
8/21/2019 PSP Lecture1
13/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Components of a Computer System
Main board, often called motherboard.
All computer Components are attached directlyor indirectly with the motherboard.
The power supplysupplies power for mostof the components.
8/21/2019 PSP Lecture1
14/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
The busis a group of wires on the maincircuit board of the computer.
It is a pathway for data flowing betweencomponents.
Most devices are connected to the busthrough a controllerwhich coordinates theactivities of the device and the bus.
Theprocessoris an electronic device about a
one inch square. Inside the square is an even smaller square
of silicon containing millions of tiny electricalparts.
Components of a Computer System
8/21/2019 PSP Lecture1
15/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
A processor may contain 100 milliontransistors.
The processor is the "brain" of the computersystem.
It does the fundamental computing within thesystem, and directly or indirectly controls allthe other components.
The processor is sometimes called the
Central Processing Unitor CPU.
Processor
L #1 I d i PSP P bl l i P i
8/21/2019 PSP Lecture1
16/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
A CPU contains arithmetic and logic unit(ALU), control unit (CU) and registers.
ALU performs calculations such as addition,subtraction, multiplication and division and
logical operations such as comparing twonumbers.
CU controls the order in which programinstructions are executed.
Registers are high speed memory cells usedto store temporary results produced by ALUas well as certain control information
Processor (cont..)
L t #1 I t d ti t PSP P bl l i P i
8/21/2019 PSP Lecture1
17/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
The processor is the brain of the computer.All fundamental computing takes place in theprocessor.
Unlike a human brain, which combines
memory with processing power, a computerprocessor has very little memory.
It must rely on other components to holddata and programs and to save results.
The memory in a computer system is of twofundamental types: Main memory
Secondary memory
Memory
L t #1 I t d ti t PSP P bl l i P i
8/21/2019 PSP Lecture1
18/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Closely connected to the processor. contents are quickly and easily changed.
holds the programs and data that theprocessor is actively working with.
interacts with the processor millions of timesper second.
Main memory is where programs and dataare kept when the processor is actively usingthem.
Main Memory
L t #1 I t d ti t PSP P bl l i P i
8/21/2019 PSP Lecture1
19/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
When programs and data become active,they are copied from secondary memory intomain memory where the processor caninteract with them.
A copy remains in secondary memory.
Main memory is intimately connected to theprocessor, so moving instructions from the
program and data into and out of theprocessor is very fast.
Main Memory (cont..)
L t #1 I t d ti t PSP P bl l i P i
8/21/2019 PSP Lecture1
20/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Also called RAM (Random Access Memory). "Random" means that the memory cells can
be accessed in any order.
One megabyteof memory is enough to holdapproximately one million charactersof aword processing document.
Nothing permanent is kept in main
memory.
Main Memory (cont..)
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
21/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Connected to main memory through the busand a controller.
The contents are easily changed, but changesare slow compared to main memory.
Used for long-term storage of programs anddata.
Before its data and programs can be used,
they must be copied into main memory.
Secondary Memory (cont..)
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
22/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Secondary memory is where programs and data arekept on a long-term basis.
Common secondary storage devices are the harddisk and flash drives.
The hard disk has enormous storage capacitycompared to main memory.
The hard disk is usually contained in the systemsunit of a computer.
Data and programs on the hard disk are organizedinto files.
A fileis a named section of the disk.
Secondary Memory (cont..)
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
23/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
The reason for having two types of storage is this
contrast:
Primary memory Secondary memory
1. Fast Slow2. Expensive Cheap
3. Low capacity Large capacity
4. Works directly with Not connected directly
the processor to the processor
Secondary Memory (cont..)
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
24/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
In both main and secondary memory, information is storedas patterns of bits.
A bitis a single on/offvalue. Only these two values arepossible. The two values may go by different names, suchas true/false, or 1/0. There are many ways in which a bit
can be implemented. One bit of information is so little that usually computer
memory is organized into groups of eight bits.
Each eight bit group is called a byte.
When more than eight bits are required for some data, awhole number of bytes are used. One byte is about enoughmemory to hold a single character.
Bits and Bytes
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
25/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Bits and Bytes (cont..)
A is a character and represented in 8 bits as
01000001 in computer
Similarly B represented as 01000010
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
26/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Often very much more than eight bits are requiredfor data, and thousands, millions, or even billions of
bytes are needed. These amounts have names, as
seen in the table.
Name Number of Bytes power of 2
Byte 1 20
kilobyte 1024 210
megabyte 1,048,576 220
gigabyte 1,073,741,824 230
terabyte 1,099,511,627,776 240
Bits and Bytes (cont..)
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
27/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Computer software consists of both programsand data.
Programs are lists of instructionsfor the processor.
Data can be any information that a program needs:character data, numerical data, image data, audio data, andcountless other types.
The distinction between programs and data is not as clear-cut as you might think, however.
Software
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
28/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Fundamental Idea: Both programs and data are saved incomputer memory in the same way.
The electronics of computer memory (both main memory
and secondary memory) make no distinction betweenprograms and data.
Software (cont..)
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
29/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
There are two categories of programs.
Applicationsoftware (usually called just
"applications") are programs that people use to get
their work done.
Systemssoftware keep all the hardware and
software running together smoothly.
Computers exist because people want to run these
programs.
Types of Software
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
30/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Application Programs Systems Programs Word processors Operating system
Game programs Utilities
Spreadsheets Programming languages
Data base systems Data Recovery
Graphics programs Data backup
Web browsers
The most important systems program is the operatingsystem.
The operating system is always present when the computeris running.
It coordinates the operation of all the hardware and softwarecomponents of the computer system.
Types of Software (cont..)
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
31/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
Types of Software (cont..)
Application Software
System Software
System Hardware
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
32/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
The operating system is responsible for startingapplication programs running and finding theresources that they need.
For example, when a command is given for printing
a document, OS allocate the printer to theapplication.
Modern operating systems usually come with agraphical user interface(GUI) that enables users to
easily interact with programs by using windows,buttons, menus, icons, the mouse, and thekeyboard.
Types of Software (cont..)
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
33/34
Lecture #1: Introduction to PSP Problem solving Programming
Quaid-i-Azam University Islamabad
When a computer is first started, the hardware willautomatically load the operating system and start it
running.
This process is called booting.
Once the operating system is running, it is used to
start up application programs.
Starting a Program
Lecture #1: Introduction to PSP Problem solving Programming
8/21/2019 PSP Lecture1
34/34
Lecture #1: Introduction to PSP Problem solving Programming
Here is a (simplified) list of what happens when the user(you) starts up an application.1. The user asks to run an application. This could be done by clicking
on an icon, making a menu choice, or other means.
2. The OS determines the name of the application.
3. The OS finds the section of the hard disk where the applicationprogram and where its data are stored.
4. The OS finds an unused section of main memory that is largeenough for the application.
5. The OS makes a copy of the application and its data in that sectionof main memory.
6. The OS sets up resources for the application.
7. Finally, the OS starts the application running.
Starting a Program (cont..)