ME 2002 Computer Programming-I: Course Teachers
ME 2002 Computer Programming-I: Course Teachers
Computer Programming-I
Course Teachers:
Dr. Md. Anowar Hossain
Associate Professor, Department of Mechanical Engineering
Biplob Kumar Roy
Lecturer , Department of Mechanical Engineering
2
Typical Computer Block Diagram
Main Secondary
memory memory
Internal
Memory
(registers)
Input Output
devices Control devices
Unit
Arithmetic
logic
Unit
Central
Central processing
processing unit
3
Major Components of a Computer
• The CPU: The central processing unit is the heart of any computer. It is
divided into a control unit, an arithmetic logic unit (ALU), and internal
memory.
• Control Unit: Controls all other parts of the computer, interprets the
instruction of the program, fetches data from input devices or main
memory, send data to output devices or main memory etc.
4
Major Components of a Computer (Contd..)
5
Major Components of a Computer (Contd..)
• Input and output device: Data is entered into a
computer through an input device and is output
through an output device.
6
Data Presentation in a Computer
7
Data Presentation in a Computer (Contd..)
• The smallest common grouping of bits is called a byte.
Byte is a group of 8 bits used to represent a binary
number. It is the fundamental unit to measure the
capacity of a computer’s memory.
8
Decimal and Binary Number System
Decimal number system ( Base 10)
122
1’s place (100)
10’s place (101)
100’s place (102)
11
Types of data stored in Memory
3 types of data are stored in a computer’s memory: Character
data, Integer data & Real data.
Character data:
The 26 uppercase letters A through Z
12
Types of data stored in Memory (Contd..)
1 byte of memory is used to store each character
Two coding systems ASCII & EBCDIC are used to represent
character or symbol
ASCII- American Standard Code for Information Interchange.
Most of computer manufacturers in the world used the ASCII
coding system.
EBCDIC- Extended Binary Coded Decimal Interchange Code.
IBM uses EBCDIC on its mainframe computers.
Chinese and Japanese contain around 4000 characters so they use
a new coding system called Unicode in which each character is
stored in 2 bytes of memory. The UNICODE coding system can
represent character data in any language.
13
Types of data stored in Memory (Contd..)
Integer Data
14
Types of data stored in Memory (Contd..)
15
Types of data stored in Memory (Contd..)
16
Types of data stored in Memory (Contd..)
Real Data
Stores numbers in a type of scientific notations.
Ex. 299,800,000 m/s is converted to 2.998 108 m/s.
2.998 part is called mantissa and the exponent (in the 10 system)
is 8.
Real numbers usually occupy 32 bits of memory: a 24 -bits
mantissa and an 8-bits exponent.
Computer works in the base 2 system instead of the base 10
system for real data handling
Value = mantissa 2exponent.
17
Computer Languages
Computer Program???
• A program is the tool a user employs to exploit the power of the computer.
• A program is written in a language which is understood by the computer
hardware.
• A program consists of a sequence of steps which when executed result in a
task being carried out. Execution means that the computer is able to
interpret each step (instruction), interpretation refers to understanding what
is required and instructing the hardware to carry it out. Each instruction
might require a calculation to be performed, or a decision to be selected, or
some information to be stored or retrieved. The nature of the instruction
depends on what programming language is used.
• Each programming language has its own set of statements.
18
Computer Languages
19
History of the FORTRAN
Fortran is the grandfather of all scientific languages.
The name Fortran is derived from FORmula TRANSlation
Fortran was first developed in 1954 by IBM.
20
PROGRAM QES
IMPLICIT NONE
INTEGER :: a, b, c, D
REAL :: Real_Part, Imag_Part
WRITE(*,*) ''Type in values for a, b and c''
READ(*,*) a, b, c
IF (a /= 0) THEN ! Calculate discriminant
D = b*b-4*a*c
IF (D == 0) THEN ! one root
WRITE(*,*) ''Root is '', b/(2.0*a)
ELSE IF (D > 0) THEN ! real roots
WRITE(*,*) ''Roots are'',(b+SQRT(REAL(D)))/(2.0*a),&
''and'', (bSQRT(REAL(D)))/(2.0*a)
ELSE ! complex roots
Real_Part = b/(2.0*a) ! D < 0 so must take SQRT of D
Imag_Part = (SQRT(REAL(D))/(2.0*a))
WRITE(*,*) ''1st Root'', Real_Part, ''+'', Imag_Part, ''i''
WRITE(*,*) ''2nd Root'', Real_Part, '''', Imag_Part, ''i''
END IF
ELSE !a=0
WRITE(*,*) ''Not a quadratic equation''
END IF
END PROGRAM QES