Lecture 6 - Intro to Prog
Lecture 6 - Intro to Prog
ICT
By Dr. Mir Yasir Umair
Associate Professor, MCS, NUST
•
Computer
Computers
Systems
o Devices for performing computations at high speeds with great accuracy
o A machine that can be programmed to manipulate symbols. Can perform complex & repetitive
procedures quickly, precisely and reliably. Can quickly store and retrieve large amounts of data.
• Program
o A set of instructions for a computer to follow, written in specific programming language
Computers and Computer Languages
• Computers are everywhere
o how many computers do you own?
I/O Devices
CPU
Secondary Memory
Main Memory
Hardware (HW):
Central Processing Unit (CPU)
• Executes programs
• Performs calculations
o Arithmetic
• Add, subtract, divide, multiply, … etc.
o Logical
• Compare, test for true/false
• Controls & coordinates the other parts of the computer.
• The CPU controls just about everything else by executing
instructions
o stores data in memory
o retrieves data from memory
o performs computations
o sends and gets data from other devices
Hardware (HW): Memory
• Main (Primary) Memory:
o Ordered sequence and specific number of memory locations
(Bytes, words) that have unique addresses indicating their
relative positions
o Fast, expensive, short term memory
o Holds intermediate results and serves as “scratch paper”
o Needed to carry out program instructions
o Types:
• RAM: Random Access Memory
(vs. Sequential Access Memory)
• Volatile (i.e. contents disappear when the computer is switched off)
• Writable (except where forbidden by the software)
• ROM: Read Only Memory
• Non-volatile
• Also usually random access
Hardware (HW): Memory
• Secondary (auxiliary) memory
o Used for keeping a permanent records of information
o Holds programs and data between jobs
o Keeps data or program files for later use
o Slower, cheaper, long-term memory
o Common forms
• Diskettes, magnetic tapes, hard disk, CD-ROM’s, DVD
o Some types are removable
Hardware (HW)
• I/O (Input/Output) devices
o Allow the user to communicate with the computer.
o A single computer could be connected to more than one input or output device.
o Examples:
• Input: Keyboard, mouse, scanner, voice
• Output: Screen, printer, voice
Hardware Devices
( Examples)
• Input:
o Keyboard
o Mouse, Touchpad, Joystick
o Pen & tablet, Perforated cards
• Output:
o Printer
o Screen (monitor)
o Teletype
• Input & Output:
o Auxiliary Devices:
• disks (hard disk, floppies, DVDs/CDs, USB keys, Flash memories)
• tape drives
o Touch screen
o Network cards (intranet, internet)
Hardware Devices (3)
• Bus: A group of wires through which the other devices
communicate.
• Costs
o Hardware costs dropping
o Software development costs rising
• Software development complexity
• Programmer salaries
• Cost of slipping schedules
o Unanticipated interactions in complex systems
o Unpredictability of software development times
Hardware/Software
Architectures
• Mainframe Era
o 1940’s-70’s: mainframe computer, minicomputers
o Environments:
• Batch environments, batch processing
o Files are basis for I/O: fixed formats, minimal device I/O
o Error recovery
o Lack of timing constraints
• Interactive environments
o Terminal and file I/O:
o Interactive error handling
o Faster performance
• Personal Computers Era
o 1978: the Apple II ran BASIC
• Educational use
o 1981: IBM released the first PC
o 1984: Macintosh
o Window environments:
• OO models are ideal (Smalltalk)
• Must interact with many I/O devices (file I/O is less important)
o Embedded systems
• Error handling
• Real-time response
• Distributed systems with concurrently running tasks
• Networking Era:
o LANs (Local Area Networks):
client-server model
• Airline reservations, banking
o Internet
• 70’s: ARPANET: telnet, FTP, SMTP protocols
• late 80’s: HTML and HTTP added
o Issues and Effects:
• Static web pages with URLs for access
URL = Uniform Resource Locator
• Dynamic web pages for e-commerce (Perl, JAVA, etc.)
• Security
• Performance (multiple clients)
o Offloading work to client
Hardware/Software Concepts
• Computers manipulate instructions and data
o Represented in similar ways
o Used in different ways
o Representation is binary (digital hardware is binary)
• Numbers vs. symbols
o Computers represent everything as numbers
o But numbers can represent symbols
o Can perform “symbolic” computation
• Beginning of Artificial Intelligence
HW/SW Concepts: Data
· What is it?
- Numbers, characters, images, or other method of recording
- Can be assessed by a human or (especially) input into a computer, stored and
processed there, or transmitted on some digital channel.
- Nearly always represent data in binary.
- Has no meaning on its own.
- When interpreted by data processing system it takes on meaning and becomes
information.
· Storage
o Setting of individual bits to specific values, destroying its previous contents
· Retrieval
o Copying the contents of a particular memory cell to another storage area.
o Original data remains unchanged
HW/SW Concepts: Representation
• Digit / Bit
o Smallest unit of information/storage, sufficient to hold one bit
o Can take one of two values
(true/false, 1/0, or yes/no)
o Corresponds to an input/output being on or off
• Byte
o Smallest addressable unit of storage
o Usually 8 bits
o Typically holds one character
o Can represent 256 different values
HW/SW Concepts: Representation
• Word
o Fundamental unit of storage in a computer
o Word size is one of its chief distinguishing characteristics of a computer
o Typical size in modern computers: 32 bits (4 bytes) or 64 bits (8 bytes)
o An instruction is usually one or more words long
o A word can be used to hold a whole number of characters
Software
Categories
Software Categories
• System SW
o Programs written for computer systems
• Compilers, operating systems, …
• Application SW
o Programs written for computer users
• Word-processors, spreadsheets, & other application
packages
A Layered View of the Computer
Application Programs
Word-Processors, Spreadsheets,
Database Software, IDEs,
etc…
System Software
Compilers, Interpreters,Preprocessors, etc.
Operating System, Device Drivers
Operation Address
• Case Sensitive
o Main vs main
Listing 1.2
• Output?
Listing 1.3
• Output?
Output?
C++ Program
Development Cycle
Programming Style and
Documentation
• Appropriate Comments
• Comment Styles
• Proper Indentation and Spacing
Errors?
Programming Errors
• Syntax Errors
• Runtime Errors
• Logic Errors
Programming Errors
• Syntax Errors
;
Programming Errors
• Syntax Errors
• Runtime Errors
Programming Errors
• Syntax Errors
• Runtime Errors
• Logic Errors
Common Errors