You are on page 1of 24

BITG 1113:

Introduction to Computer and Programming Language

LECTURE 1
1

History of Electronic Computers


Have relatively short history. Atanasoff-Berry Computer (ABC) was developed in 1930 Iowa State University sole purpose of solving large numbers of simultaneous equations. ENIAC military computer. For general computations, but the wiring had to be reconfigured each time a new task was performed. Both, once the electronic wiring was set, only the data were input to the computers memory.

History of Electronic Computers cont.


 Mathematician John von Neumann made a major advance in computing theory.  Proposed an alternative to the process of reconfiguring the wiring.  Introduced the concept of storing a computers instructions in its own memory.  The instructions would dictate the directions and locations to which electronic pulses would flow same way that wires dictated the flow.  Computer built on von Neumanns concept, both data and the computers instructions were input to the computers memory.  Writing computer instructions is called Programming.

History of Electronic Computers cont.

Data input to cells A - F

A B C D E F

Output from hardwired computer X Y

Data input to cells A - F

Instructions put into the computers memory Send to X Send to X Send to X Send to Y Send to Y Send to X Send to Y

Output from computer with stored instructions

Single purpose wiring

A B C D E F

X Y

Multipurpose wiring Schematic showing output from computer using stored instructions with X = A + B + C and Y = D + E + F

Hardwired schematic with X = A + B + C and Y = D + E + F

History of Electronic Computers cont.


 The stored program concept led the development of multipurpose computers only the instructions needed to be change to change the type of problem to be solved.  Some of the computers in use today include:
} }

Supercomputers largest & fasters of all computers. Used primarily for large scientific or military calculations. Mainframe computers not as fast or as large as supercomputers. Usually take up a portion of a room and can be accessed from remote locations on campus. Workstations small enough to fit on a tabletop or next to a desk. Suitable for small to medium-size business. More powerful than personal computers. Personal Computers can fit on a desktop. Also been called microcomputer. Laptops can fit into a briefcase and are nearly as powerful as personal computers. Palmtop small enough to fit into a pocket and less powerful than personal computers and laptops.
5

Architecture
The architecture of a typical computer, usually consists of a
}

} }

Central Processing Unit (CPU) power of the computers. Main Memory stores information to be processed or instructions on how to process information. Controllers Peripherals devices (mass storage disks, tapes, CDs, etc; Input/output monitors, keyboards, printers, speakers, etc).
6

Using Bits
Characters and Symbols
}

early days of data transmission Morse code used dashes and dots to represent characters and symbols. Instead of dashes and dots, customary notation for computers is 0 and 1. ASCII is the code used for representing characters and symbols. Example : Symbol ASCII Code A 01000001 B 01000010 C 01000011 ? 00111111 + 01001110

Using Bits cont.


 Integers
}

Integers are represented in memory by a type of a binary or base 2 system. Base 2 used because only 1s and 0s are needed to represent digits. Binary system contrasts with our everyday number system, which is decimal or base 10. In base 10, each placeholder represents a power of 10 with the rightmost placeholder representing 100 (which is 1). Example : five-digit number 78,326 is interpreted as (7 x 104) + (8 x 103) + (3 x 102) + (2 x 101) + (6 x 100) Standard binary scheme, placeholders all represent power of 2. The right most placeholder represent 20.

Using Bits cont.


Example : Determine the base 10 representation of the 8-bit base 2 number 10010110. Solution : Using the preceding table of placeholders, the value can be calculates as follows: Base 2 Placeholders Decimal value of placeholders Binary digits Binary digit times decimal value 27 128 1 128 26 64 0 0 25 32 0 0 24 16 1 16 23 8 0 0 22 4 1 4 21 2 1 2 20 1 0 0

The base 10 representation then sum of all the number in the last row, which is 128 + 16 + 4 + 2 = 150

Using Bits cont.


Example : Determine the 8-bit binary representation of the decimal number 150. Solution : can be solved by repeated comparisons of a decimal number to the line of power of 2.
Step 1 compare the value in column 1 to the numbers in the line below, which are all power of 2. Put the value 1 into the location for the power of 2 which is just less than or equal to the compare value (put 0 into unfilled places to the left). Step 2 Get the new compare value by subtracting the original number from the current number.

Decimal value of the current binary number

27 Decimal value Compare 150 Compare 22 Compare 6 Compare 2

26

25

24

23

22

21

20

128

64

32

16

1 1 1 1

_ _ _ _

_ _ _ _

_ 1 1 1

_ _ _ _

_ _ 1 1

_ _ _ 1

_ _ _ _

= 128 = 144 = 148 = 150

150 128 = 22 150 144 = 6 150 148 = 2 150 150 = 0

The final result is that decimal 150 is equal to binary 10010110


10

Using Bits cont.


 Hexadecimal and Octal Notation
}

Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F

Octal 0 1 2 3 4 5 6 7 0 0 0 0 0 0 0 0

Bit pattern 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

Computer un general has no difficulty in dealing with large number of 1s and 0s. For instance the 32-bit representation of 635,163,077 is 0010010111011011110100 0111000101. Hexadecimal (or base 16) and Octal (or base 8) notation can be used as human shorthand for representing large string of bits.

11

Using Bits cont.


 The octal digits (0-7) are used to represent 3-bit groups (ignoring the leftmost 0 of the bit pattern). And hexadecimal digits (0F) are used to represent 4bit groups.  For instance the bit pattern 101001100110011000111011 is represented in octal as 51463073 as shown.
Bit pattern Octal Digit 101 001 100 110 011 000

 And 0010010111011011110100011 1000101 is represented in hexadecimal as 25DBD1C5 as shown.


Bit pattern hexadec imal 0010 0101 1101 1011 1101 0001 1100 0101

111

011

12

Programming Languages
 The binary code is referred to as machine language.  Machine language is the only languages that a computer can understand.  The language consists of instructions in binary code (or hexadecimal) specific to the particular computer processor.  Because machine language is so cumbersome and tedious to write, most programs are written in other languages and translated into machine language.  Assembly Language considered to be one level above machine language. Main advantage of assembly language over machine language is that instructions in assembly language are not in binary code but in English word. The word are translated into machine language code with language translating program, but its also cumbersome to write because each fundamental instruction must be given.  High level language further simplify commands written by human programmer.
13

C++ programming Language


Extension of C Support procedure-oriented and object-oriented programming approach Invented by Bjarne Stroustrup in 1980 HOW COMPUTER RUN A PROGRAM Edit Compile Link Run : Source code ( type the program) : If no syntax errors -> Object Code : Link to library function -> exe module : Output ( Check for any semantic errors)
14

A Typical C++ Program # include <header files> # define P 100 / / A typical C++ Program main ( ) Begin { Variables declaration .. ; .. ; Statements; ... ; }
End Preprocessor Directive

Comment

main function

15

Simple C++ Program # include <iostream.h> # include <iomanip.h> // Aturcara ini akan mencetak sahaja (Penggunaan arahan cout) void main ( ) { cout << Welcome to KUTKM \n; cout << MELAKA BANDARAYA BERSEJARAH; } Output Welcome to KUTKM MELAKA BANDARAYA BERSEJARAH

16

Exercise: Write a complete program to print the following output: Welcome to KUTKM MELAKA BANDARAYA BERSEJARAH

17

#include <iostream.h> #include <iomanip.h> #define P 100 void main() { cout << "WELCOME TO KUTKM" << setfill('$') << setw(40); cout << "MELAKA BANDARAYA BERSEJARAH\n"; cout << " " <<P <<"\n"; cout << "SELAMAT\tMAJU\tJAYA" <<endl <<endl; } Output WELCOME TO KUTKM$$$$$$$$$$$$MELAKA BANDARAYA BERSEJARAH 100 SELAMAT MAJU JAYA

18

Exercise: Write a complete program to print the following output:SARJANA MUDA KEJURUTERAAN ELEKTRONIK KOLEJ UNIVERSITI TEKNIKAL ******************MELAKA*******************

19

Manipulator ( # include <iomanip.h>) 1. \n e.g : Advances the cursor to the beginning of the next line cout << Mummy The Return\n\n; cout << The Sixth Sense << endl; Mummy The Return The Sixth Sense 2. endl : Advances the cursor to the beginning of the next line. Forces any data remaining in the archive buffer to be written to the file. Same as \n 3. \t e.g. Output: : Horizontal tab cout << Mummy\tThe\tReturn\n\n Mummy The Return
20

Output:

4.

setw (n)

: sets the streams internal field width variable to n. This setting remains in effect only for the next insertion. cout << setw(10) << 567 << setw(30) << "Pearl Harbour";

e.g Output 5.

^^^^^^^567^^^^^^^^^^^^^^^^^Pearl Harbour

setfill (?) : This parameterized manipulator sets the streams fill character. The default is a space. This setting remains in effect until the next change.

e.g Output

cout << setfill (*) setw(5) << 567 << setw(20) << Pearl Harbour **567*******Pearl Harbour

21

Solutions

#include <iostream.h> #include <iomanip.h> #define P 100 void main() { cout << "SARJANA MUDA KEJURUTERAAN ELEKTRIK" << endl; cout << " KOLEJ UNIVERSITI TEKNIKAL\n\n"; cout << "*****************MELAKA****************"; } #include <iostream.h> #include <iomanip.h> void main() { cout << "SARJANA MUDA KEJURUTERAAN ELEKTRONIK\n" ; cout << " KOLEJ UNIVERSITI TEKNIKAL"; cout << \n\n****************MELAKA****************"; }

22

#include <iostream.h> #include <iomanip.h> void main() { cout << "SARJANA MUDA KEJURUTERAAN ELEKTRONIK\n"; cout << setw(30) <<"KOLEJ UNIVERSITI TEKNIKAL\n"; cout << "\n" << setfill('*') << setw(20) <<"MELAKA" << setfill('*') << setw(15) << endl; }

#include <iostream.h> #include <iomanip.h> #define P 100 void main() { cout << "SARJANA MUDA KEJURUTERAAN ELEKTRIK\n"; cout << " KOLEJ UNIVERSITI TEKNIKAL\n\n"; cout << setfill('*') << setw(34) <<"MELAKA**************" << endl; }

23

Exercise 1. Write a program to print the following output: ********** **INTRO** ********** 2. Write a program that will print your name and matric number. Please use the programming instructions you have learned to produce a creative output.

24

You might also like