Вы находитесь на странице: 1из 92

During the lecture sessions:

No Mobile phones, pdas, tablets,


notebooks, netbooks, gaming consoles,
mp3 players

No Sessional Report Writing

No Quiz/CT Preparation

Rule-breakers will be severely penalized.


ME 171 : Computer Programming Language
3.00 Credit Hours
Course Teacher: Dr. Md. Mamun, Mr. Adnan Morshed

Introduction to computer hardware and its working principle;


Programming logic, algorithms, and flowcharts.
Introduction to structured programming;

Overview of C and C++ programming languages; C and C++ fundamentals


data types and expressions; Operators; Libraries and keywords; Statements;
Arrays and strings; Functions; Control statements; Pointers; Input and output
systems.

Object Oriented programming;


Introduction to advanced programming.
ME 171 : Computer Programming Language

References:

1.Introduction to Computers Peter Norton, McGraw-Hill Publications


2.Computer Fundamentals Pradeep K. Sinha, BPB Publications

3.Teach Yourself C Herbert Schildt, Osborne


4.Let Us C Yashavant Kanetkar, BPB Publications
5.The C Programming Language Brian. W. Kernighan and Dennis M.
Ritchie, Pearson Education

[Any suitable book on C programming]

Softwares:

Codeblocks (used in the sessional)


Any suitable compiler for C programming.
Introduction To Computers
Dr. Md. Mamun
November, 2013

Bangladesh University of Engineering and Technology

Department of Mechanical Engineering


What is a Computer ?
A computer is an electronic device, which can input, process,
and output data.

input processin output


g

A computer is a machine that stores data, interact with


devices, and execute programs (provides computing capabilities
to its users).
A computer is an electronic device that stores, retrieves, and
processes data, and can be programmed with instructions. A
computer is composed of hardware and software, and can exist in
a variety of sizes and configuration.
What is a Computer ?
A computer System:

Computer Very Completely


System Powerful Stupid

AI Artificial Intelligence Extremely Sophisticated Programming


by Human for Machines
Major Components of a Computer System
A computer system consists of two sub-systems: hardware and
software.

Hardware is the electronic and mechanical parts of a computer


system.
Software is the data and the computer programs of a computer
system.
Hardware vs. Software
Hardware Physical Components
Software Logical Instructions
Firmware Logical Instructions imprinted
on physical Components
Computer Hardware
Main Hardware Components of a Processing Unit:
o CPU Central Processing Unit (Processor)
o Motherboard (MainBoard)
o RAM Random Access Memory (Main
Memory)
o Hard Disk and/or other Storage Devices
(Secondary Memory / Auxiliary Storage)
o Power Supply Unit (PSU)
Basic Computer System
Main Hardware Components
+

Main Software Components:


OS - Operating System
[User Software Programs / Packages]
+
One Input device + One Output device
[Keyboard/Mouse + Monitor/Printer]
Computer Hardware
Computer hardware is divided into three major
Components:
1. The Central Processing Unit (CPU)
2. Computer memory
3. Input/Output (I/O) devices

Basic hardware components


Processing Unit
CPU
The CPU is the "brain" of the computer system.
It does the fundamental computing within the system
It directly or indirectly controls all the other components
The CPU has a limited storage capacity. It relies on memory to
hold data and programs and to save results.
The CPU consists of:
1. The Arithmetic and Logic Unit (ALU).
2. The Control Unit (CU).
3. Registers.
CPU takes each instruction in primary memory and executes it
CPU may also store new data values as program executes
The CPU components are connected by a group of electrical wires
called the CPU bus.
Bus : ISA bus, EISA bus, PCI bus, AGP, USB, PCI-E etc.
CPU
The CPU is connected to memory and I/O devices by the System bus
The System bus consists of: Address-, Control- and Data-buses.

PC: Program Counter Register

MAR: Memory Address Register

MDR: Memory Data Register


CPU
Computer Memory
The main function of computer memory is to store software.
Computer memory is divided into primary memory and secondary memory.
Primary memory is divided into random access memory (RAM) and read-
only memory (ROM):
RAM holds the programs and data that the processor is actively working
with.
ROM contains software that is used in Input/Output operations. It also
contains software that loads the Operating System in Primary Memory.
The CPU can read and write to RAM but it can only read from ROM.
RAM is volatile while ROM is not.

Secondary memory is used for long-term storage of programs and data.


Examples of secondary memory devices are: hard disks, floppy disks and
CD ROMs.
Primary Memory
Primary memory is divided into a number of
memory cells (bits) or bytes.
A bit (binary digit) is the smallest storage unit within a computer.
It is a tiny electrical circuit that can be in one of two states:
A voltage high represented by the symbol 1
A voltage low represented by the symbol 0

Any system of symbols can be represented by bit or byte patterns.


Each byte has a unique integer address and it is usually 8 bits.
Address Primary Memory
Value UNIT SYMBOL POWER Number of
OF 2 bytes
Byte 0 1
2

Kilobyte KB 10 1,024
2

Megabyte MB 20 1,048,576
2

Gigabyte GB 30 1,073,741,824
2

Terabyte TB 40 1,099,511,627,776
2
Primary Memory
RAM Modules
Mainboard / Motherboard
Mainboard / Motherboard

Switching Mode Power Supply


(SMPS)
Primary and Secondary Memory
Comparison
Primary memory Secondary memory
Fast Slow
Expensive Cheap
Low capacity Large capacity
Connects directly to the Not connected directly to
processor the processor
Fetch Decode Execute Cycle
The CPU continuously transfers data to and from the
primary memory
Data transfer is done in units called instructions or words
When a computer is switched on, the CPU continuously goes
through a process called fetch-decode-execute cycle:
The Control Unit fetches the current instruction from memory, decodes it
and instructs the ALU (Arithmetic Logic Unit) to execute the instruction.
The execution of an instruction may generate further data fetches from
memory
The result of executing an instruction is stored in either a register or RAM
Fetch-Decode-Execute-Store Cycle
Instruction
Cycle
Main
Main Memory
Memory
1 Control Unit
Fetch 2 Decode

cpu

RAM
Execution
Cycle
Execute
Store 3
4

Arithmetic/Logic Unit
Computing Environments

Personal computing

Distributed computing Time-sharing


Software
Software is the programs and data that a computer uses.
Programs are lists of instructions for the processor
Data can be any information that a program needs: character
data, numerical data, image data, audio data, etc.
Both programs and data are saved in computer memory in the
same way.
Computer software is divided into two main categories:
1. Systems software
2. Applications software
System software manages computer resources and makes
computers easy to use.
An applications software enables a computer to be used to do a
particular task.
Computer Software

Hardware Abstraction
Layer (HAL)
Types of software
Software
Application Programs Systems Programs


Word processors Operating system.
Game programs Networking system.
Spreadsheets Programming
Data base systems language software.
Graphics programs Web site server.
Web browsers Data backup.
Operating Systems
The most important systems program is the operating
system.
It is a group of programs that coordinates the
operation of all the hardware and software
components of the computer system.
It is responsible for starting application programs
running and finding the resources that they need.

Examples of operating systems are: Windows 7/Vista,


Windows XP, Linux, Unix, Windows NT, MS-DOS, Mac
OS X, Solaris, OS/2, etc.
Computer Languages

Computer language evolution

Note:

The only language understood by a


computer is machine language.
Program Execution

Executing programs
I/O (Input/Output)Devices
Input devices are used to enter programs and
data into a computer.
Examples: keyboard, mouse, microphone, scanner,
webcam, digital pen, bar code reader, etc.
Output devices are where program output is
shown or is sent.
Examples: monitor, printer, and speaker.
An I/O device is directly connected to the
System, but through a device controller.
Input devices

Keyboard
Mouse

Joystick Webcam Digital Camera


A standard keyboard consists of :
Alphanumeric keys ( Letters, numbers, Tab, Caps lock, Backspace, Enter)
o Modifier keys. (SHIFT, ALT and CTRL)
o Numeric keypad. (The right side portion of keyboard)
o Functions keys. (F1,F2 and so on)
o Cursor movement key ( Arrow indicator)
o Special purpose key ( Start, Windows, Shortcut key)

Fig: A standard keyboard


Reading devices
Several input devices that work on reading principle includes

Optical mark reader (OMR)


Optically reads marks on carefully printed forms

Optical character reader (OCR)


It can convert data from a source document in to a machine-recognizable
form.

Hand written character reader (Handwriting Recognition/Tablet input)


Most sophisticated and versatile OCR devices capable of reding hand written
character.

Smart card
Requires special card reading terminal.
These card contain microchips that can keep permanent records and updated
each time it is inserted in the card reader.
A mouse is a hand-movable device that controls the position of cursor on the screen.
Generally of two types
1. Mechanical mouse
Consists of a box with buttons on the top and a ball on the bottom.
The mouse is placed on a flat surface.
Balls movement on the surface causes the cursor movement on screen.

Fig : A mouse
2. Optical mouse
Non-mechanical.
This type of mouse emits a beam of light whose reflection is used as a
signal.

2. Track ball
A track ball is a pointing device that works like an upside mouse.
In order to move the pointer the ball is rolled.

Fig: Track ball


3. Track pad
Also called touch pad.
Stationary pointing device.
Less tiring to use than mouse or track ball.
Movement of finger is translated to the movement of pointer.

Fig : Track pad/Touch pad


4. Joy stick

These are used with video games for user input.

These devices may also used to move the cursor around the screen to
facilitate input to a graphical display .
5. Touch screen

Touch screen accept input by allowing the user to place a fingertip


directly on the computer screen.
This technique is useful when dirt or weather would render key boards
and pointing devices useless.

Scanning devices
This category includes
1. Scanners
2. Bar code reader
3. Digital camera
1. Scanner
It converts any printed image in to electronic form by shining light on to the
image and then measuring the intensity of light at every point.
Text image can also be edited with the help of Optical character recognition
software.
Three basic types are
1. Sheet-fed scanner ( Mechanical rollers move the paper past the scanner
head)
2. Flatbed scanner (The paper is stationary over a glass window and the
head move past the scan head)
3. Hand-held scanner. (Human head is required to move the scan head)
2. Bar code reader
A device for scanning or reading a bar code.
Bar code is printed code that consists of parallel different bars of different
width and spacing.
Usually common in the coding of food and other goods. Also found in
library system and security systems.

3. Digital camera
It uses light sensitive electronic technique instead of film to capture
images.
This images taken in the digital camera is stored in its own memory and
can be transferred to any hard or floppy drive or to a PC card via USB port.
Image quality can be improved by using different image editing software's
like Painter, Adobe Photoshop etc.
Other input devices
Audio input device (Microphone)
A voice input device.
Converts spoken words in to electrical signals by comparing the electrical
patterns produced by a speakers voice with a set of prerecorded patterns.
Output devices

LCD/LED Monitor Printer

Multimedia Projector Speakers with Subwoofer


Generally two types of monitors are
used with PCs. These are
1. CRT monitor.
2. Flat-panel LCD/LED displays
All monitors can also be classified as
1. Monochrome monitors
2. Grayscale monitors
3. Color monitors

CRT monitor
Looks like a television.
The main component is a large vacuum tube
called cathode ray tube (CRT)
Fig: How image is produced in
CRT monitor.
Fig: Scanning pattern of CRT
monitor

The smallest numbers of dots that a a electron gun can focus is called pixel in other
words the minimum unit of screen.
In case of a monochromatic monitor there is one electron gun.
In case of a color monitor there are three electron guns for three basic colors
Two main drawbacks of CRT monitors are
1. Bulky
2. Requires lot of power
Flat panel monitors
A flat panel monitor occupy less space than CRT monitor.
It runs cooler than CRT motor.
There are several types of flat panel monitor. The most
common is the LCD (Liquid crystal display) monitor.

Fig : A flat panel


monitor

Fig : Comparing size between a standard CRT monitor


and Flat panel monitor.
LCD (Liquid Crystal Display) monitor
Uses a clear liquid chemical trapped in tiny pockets between two pieces of glass.
Each pocket of liquid is covered both front and back by very thin wires.
When a small amount of current is applied to both wires, a chemical reaction turns the
liquid dark thereby blocking light.
Principle advantages of LCD monitors are
low power consumption
Low cost
Small size.
Major disadvantages includes
Image has very little contrast
Optimum view angle is narrow.
Resolution is not as good as
Factors to be considered in case of a monitor
1. Size
Monitors are measured diagonally in inches across the front of screen.
Actual viewing area is smaller than its overall size.
Actual viewing area of LCD monitor is larger than CRT monitor of same
size.

2. Resolution
The term resolution refers to the sharpness of images.
The monitors resolution is determined by the number of pixels on the screen.
The more pixels a monitor can display the higher the resolution and thus the
clearer images.
A resolution of 640x480 means, 640 pixels in horizontally and 480 pixels
vertically down the screen.
3. Refresh rate
The monitors refresh rate is the number of times per second that the electron
gun scan every pixel on the screen.
It is important because phosphor dots fade quickly after the electron gun
charges them with electrons.
Refresh rate is measured in Hz
Refresh rate over 72 Hz is favorable.

4. Dot pitch
Important parameter for color monitor.
Briefly, the dot pitch is the measure of how much space there is between a
display's pixels.
When considering dot pitch, remember that smaller is better.
Usually it is measured as a fraction of mm.
Should be 0.22 mm or even less is better.
5. Color depth
color bit depth refers to the number of bits used to describe the color of a
single pixel. The bit depth determines the number of colors that can be
displayed at one time.
Fig : Dot pitch of color monitor

Bit-Depth Number of Colors

1 2
(monochrome)

2 4
(CGA)

4 16
(EGA)

8 256
(VGA)

Table : Color depth and number of bit 16 65,536


(High Color, XGA)

24 16,777,216
(True Color, SVGA)

32 16,777,216
(True Color + Alpha Channel)
Working Principle of CRT

Cathode Ray Tube (CRT)


Facts about Video display
Basic colors Red Green Blue (RGB)
Resolution (Max) 800x600, 1024x786, 1920x1280
Refresh rate 70 - 80 Hz (Non-Intl)
Interface types AGP,PCI, VESA
Screen size 15 17 (13 laptop)
Color depth 16, 24, 32 bit
Video memory 128 MB, Shared/Dedicated
VGA/SVGA/XGA Super Video graphics array
Monitor / TV Monitor is better
Power consump. 100 W
Video card
The quality of the images on the monitor, depends on
video card as much as on the monitor itself.
A video card is an intermediary devices between CPU and
monitor.
In most cases it is a separate devices plugged in to
motherboard.
In many computer the video circuitry is built directly into
the motherboard eliminating the need of a separate card.
The speed of video cards chip determines the refresh rate
of monitor.
video cards also posses their own video ram and processor
in order to provide speedy operation and to reduce load on
CPU.
For example if you operate in a resolution of 640x480
with 256 color mode you have to send 640x480 bytes of
information to monitor for each screen. If the refresh rate is
72 Hz than the amount of data transmitted to monitor in Fig : A typical video card
each second is 640x480x72 bytes!!!!!!!
Sound card
The most important part of sound system of computer is sound card.
It is a circuit board that converts sound from analog to digital form and vice versa.
It has both input and output function.

Fig : How a computer uses a


speaker to create sound.
Printer
It is a common output device.
Produces permanent visual record of the computer output.
Currently available printers are capable of printing from 150 to 50,000 lines per
minute with each line having 150 characters-that means approx. 50,000 characters
per second is possible.
Printers are broadly classified as follows
1. Impact printer (Ex. Dot matrix printer)
2. Non-impact printer (Ex. Ink-jet printer, Laser printer)

Fig : Dot matrix printer.


Fig: How a ink-jet printer creates an images.
Fig : How laser printer creates a printed documents.
Storage Devices

FDD : Floppy disk


HDD : Hard disk
CD-ROM / CD-RW : Compact disk
DVD : Digital Video disk
Zip/Jaz drive
Tape drive
USB Flash disk / pen drive
Micro Storage Devices, SD, CF, MMC etc.
Storage Capacities
Hard disk 80 GB to 2 TB
Compact disk 700 MB
Digital Video disk 4.7 GB
Floppy disk 1.44 MB
Zip/Jaz drive 100 MB / 2 GB
Tape drive 40 GB
USB Flash Disk 1 GB to 128 GB
Sectors - Tracks - Cylinders
Facts about HDD
Seek time 10 - 20 ms
Data rate 20 - 30 MB/sec
Interface types SATA, IDE, SCSI
Motor speed 10000 rpm
Platters High precision, Lub.
Jumper setting DS, SP, CS
Formatting FAT, addressing
Partitioning Security, Multiple OS
Defragmentation Space utilization
Scandisk Disk Condition
Internal Construction of a HDD
Internal Construction of a HDD
Power and Signal Cables

Logic Board
(Controller Circuit)

Signal Cable Power Cable


Optical Disk Drives

VCD/DVD

CD DRIVE
Zip and Jaz drives

1/2 GB

100/250 MB
USB Flash Disk (Pen drive)
Mini / Micro Storage Devices
Peripheral Devices
Require Hardware I/O ports, such as PCI, COM,
LPT, USB, etc, to physically connect with the CPU.
Require Software drivers to communicate and/or
interact with the Operating System.
Peripheral Devices
File systems
Method the OS uses to store information
Storage unit, directories, subdirectories (Windows, VMS)
Single arborescence (Linux, MacOSX, all Unix)
What exactly is a file?
a piece of information (text, graphic, data, music
program, script)
it is identified by a name and an logical address (or path)
other informations: date, size, type, creator, ownership,
physical address
File system organisation

Disk 1 Disk 2 Disk 2


C: D: /

DOCS PROGS CONFIG DATA Directories /usr /home


Disk 1
WORD EXCEL EXPT1 EXPT2 Subdirectories local phil john

bin lib

emacs X11

Windows Unix
Path
The path is the logical address used by the
system or the user to locate a file.
Example:
/bd_du_Palais/35/etage/4/appart/12/Dupont_ Jean.txt

suffix
filename
path
File types
Executable Special cases in Unix
.exe STDIN
.app STDOUT
Unix requires x STDERR

Data
Text (.txt)
Music (.mp3)
Image (.jpg, .gif)
Movie (.mpg, .mov)
Binary (.bin)
Encryption / compression
Compression
Reducing the size of files
E.g., .mp3, .gz, .jpg, .zip
Encryption
Protecting your privacy
E.g., .pgp
Packing
Grouping the files
E.g., .tar
Languages
Low level (processor dependent)
Machine code, assembler
High level: structured, procedural
Fortran, C, Pascal
High level: object oriented
C++, Java, C#, Perl, Objective-C
Virtual machines
Java, C#
Scripting
Perl, Python, JavaScript
Programming Languages
Machine language
Hardware-dependent, cumbersome manipulation of
series of numbers (1s and 0s)
Assembly language, e.g.
LOAD BALANCE
ADD TAX
STORE TOTAL

High-level languages (compiled or interpreted)


Pascal, Lisp, Ada, Java, Basic, C, C++, etc.
The C Programming Language
C was originally created in 1972 by Dennis
Ritchie at Bell Labs.

C is a relatively low-level high-level


language; i.e. deals with numbers,
characters, and memory addresses.
Functions (verbs to Deitel)
C programs consist of modules called functions

Functions are groups of instructions that operate


on data to produce and often return results

Known in other languages as methods, procedures,


subs, among others
Objects (Nouns to Deitel)
Object-oriented programming seeks to
model the behavior of objects
There are data and operations (functions) that
work on just that data
Benefits
Reusability
Quicker development
Easier maintenance
Structured Programming
Disciplined approach to writing programs
that are clear, correct and easy to maintain
and modify

The goal of this course is to make you into


structured programming.
Source code -> Object code
Compiler+linker Compiler+linker
Fortran, C, Pascal, C++ Fast to execute, but slow to
debug
Interpreter Interpreter
Basic, Perl Slow to execute, but fast to
debug (no need to recompile)
Intermediate
Intermediate Slow
Java
Source code
Instructions Data structures
Statement, blocks Variable
Affectation List
Operators Array
Loops Hash
Tests Pointers
Subroutines Objects
Comments
Source code
Statement, blocks Variable
One or more A region in memory
instructions for the that can be modified
processor Exists in different types
Affectation Scalar, char, numeric,
Change to a variable boolean
List, array
Operator
Hash
affect one or more
Combination->data
variable structure
+ * - / AND OR NOT
Source code
Loops Pointers
Allow the computer to Reference to region in
repeat blocks
memory (address)
Tests
Objects
Decide what to do
Combination of data
Subroutines
and code
Programs frequently
called (functions)
Comments
The most important lines
of the source code
Object-oriented Programming (OOP)

Class
tool for encapsulating data and operations (methods)
into one package
defines a template or model for creating and
manipulating objects
Objects
data created using the class and its methods
an object is an instance of the class
creating an object is instantiation
OOP Advantage: Reuse
Well-written classes can be reused in new
applications
Shortens development time because
programmers don't need to write new code
Programs are more robust because the class
code is already tested
Algorithms
An algorithm is an exact specification of how to solve a computational
problem
An algorithm must specify every step completely, so a computer can
implement it without any further understanding
An algorithm must work for all possible inputs of the problem.
Algorithms must be:
Correct: For each input produce an appropriate output
Efficient: run as quickly as possible, and use as little memory as possible
more about this later
There can be many different algorithms for each computational
problem.
The running time of your program will depend upon:
The algorithm
The input
Your implementation of the algorithm in a programming language
The compiler you use
The OS on your computer
Your computer hardware
Describing Algorithms
Algorithms can be implemented in any programming language
Usually we use pseudo-code to describe algorithms

Testing whether input N is prime:

For j = 2 .. N-1
If j|N
Output N is composite and halt
Output N is prime
How Does a Computer think?
Transistors form switches that are in on or
off states.
The Pentium 4 chip has over 42 million,
Core 2 Duo has over 291 million and 6-core
Core-i7 has over 1.2 billion transistors.
Each transistor creates one bit.
8 bits create one byte
Why are Bytes Important?
ASCII (American Standard Code for
Information Interchange) tables
Unicode addresses the ASCII limitations
http://www.asciitable.com/
ASCII & Unicode
All data in memory is numeric. Characters are stored
by using a character code that maps numbers to
characters. One of the most common character codes
is known as ASCII.
A new, more complete code that is supplanting ASCII
is Unicode.
e.g. ASCII maps the byte 4116 (6510) to the character
capital A; Unicode maps the word 004116.
This is important for representing characters for all the
languages of the world.

Вам также может понравиться