Professional Documents
Culture Documents
LECTURE 1
1
A B C D E 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
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
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
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.
The base 10 representation then sum of all the number in the last row, which is 128 + 16 + 4 + 2 = 150
26
25
24
23
22
21
20
128
64
32
16
1 1 1 1
_ _ _ _
_ _ _ _
_ 1 1 1
_ _ _ _
_ _ 1 1
_ _ _ 1
_ _ _ _
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
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
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