lecture 1 introduction to computer and programming language

Upload: b041010296

Post on 07-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    1/24

    1

    BITG 1113:Introduction to Computer and

    Programming Language

    LECTURE 1

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    2/24

    2

    History of Electronic Computers

    Have relatively short history.

    Atanasoff-Berry Computer (ABC) was developedin 1930 Iowa State University sole purposeof solving large numbers of simultaneous

    equations.ENIAC military computer. For general

    computations, but the wiring had to bereconfigured each time a new task wasperformed.

    Both, once the electronic wiring was set, only thedata were input to the computers memory.

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    3/24

    3

    History of Electronic Computers cont.

    Mathematician John von Neumann made a majoradvance in computing theory.

    Proposed an alternative to the process of reconfiguringthe wiring.

    Introduced the concept of storing a computersinstructions in its own memory.

    The instructions would dictate the directions andlocations to which electronic pulses would flow sameway that wires dictated the flow.

    Computer built on von Neumanns concept, both data

    and the computers instructions were input to thecomputers memory.

    Writing computer instructions is called Programming.

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    4/24

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    5/24

    5

    History of Electronic Computers cont.

    The stored program concept led the development ofmultipurpose computers only the instructions neededto 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 beaccessed from remote locations on campus.

    } Workstations small enough to fit on a tabletop or next to adesk. Suitable for small to medium-size business. More powerfulthan personal computers.

    } Personal Computers can fit on a desktop. Also been calledmicrocomputer.

    } Laptops can fit into a briefcase and are nearly as powerful aspersonal computers.

    } Palmtop small enough to fit into a pocket and less powerfulthan personal computers and laptops.

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    6/24

    6

    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 processinformation.

    }

    Controllers} Peripherals devices (mass storage disks,

    tapes, CDs, etc; Input/output monitors,keyboards, printers, speakers, etc).

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    7/24

    7

    Using Bits

    Characters and Symbols} early days of data transmission Morse code used

    dashes and dots to represent characters andsymbols.

    } Instead of dashes and dots, customary notation forcomputers is 0 and 1. ASCII is the code used forrepresenting characters and symbols.

    } Example : Symbol ASCII Code

    A 01000001

    B 01000010

    C 01000011

    ? 00111111

    + 01001110

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    8/24

    8

    Using Bits cont.

    Integers} Integers are represented in memory by a type of a binary or base2 system.

    } Base 2 used because only 1s and 0s are needed to representdigits.

    } 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 therightmost placeholder representing 100 (which is 1).

    } Example : five-digit number78,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 of2.The right most placeholder represent 20.

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    9/24

    9

    Using Bits cont.

    Base 2 Placeholders 27 26 25 24 23 22 21 20

    Decimal value of placeholders 128 64 32 16 8 4 2 1

    Binary digits 1 0 0 1 0 1 1 0

    Binary digit times decimal value 128 0 0 16 0 4 2 0

    Example : Determine the base 10 representation of the 8-bit base 2number 10010110.

    Solution : Using the preceding table of placeholders, the value can be

    calculates as follows:

    The base 10 representation then sum of all the number in the last row,

    which is 128 + 16 + 4 + 2 = 150

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    10/24

    10

    Using Bits cont.

    Example : Determine the8-bit binary representation of the decimalnumber 150.

    Solution : can be solved by repeated comparisons of a decimal number

    to the line of power of2.

    27 26 25 24 23 22 21 20

    Decimal value 128 64 32 16 8 4 2 1

    Compare 150 1 _ _ _ _ _ _ _ = 128 150 128 = 22

    Compare 22 1 _ _ 1 _ _ _ _ = 144 150 144 = 6

    Compare 6 1 _ _ 1 _ 1 _ _ = 148 150 148 = 2

    Compare 2 1 _ _ 1 _ 1 1 _ = 150 150 150 = 0

    Step 1 compare the value in

    column 1 to the numbers in

    the line below, which are all

    power of2. Put the value 1

    into the location for the power

    of2 which is just less than or

    equal to the compare value

    (put 0 into unfilled places to

    the left).

    Decimal

    value of

    the

    current

    binary

    number

    Step 2 Get

    the new

    compare value

    by subtracting

    the original

    number fromthe current

    number.

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

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    11/24

    11

    Using Bits cont.

    Hexadecimal and OctalNotation} Computer un general has

    no difficulty in dealing withlarge number of 1s and 0s.

    } For instance the 32-bitrepresentation of635,163,077 is00100101110110111101000111000101.

    } Hexadecimal (or base 16)and Octal (or base 8)

    notation can be used ashuman shorthand forrepresenting large string ofbits.

    Decimal Hexadecimal Octal Bit pattern

    0 0 0 0000

    1 1 1 0001

    2 2 2 0010

    3 3 3 0011

    4 4 4 0100

    5 5 5 0101

    6 6 6 0110

    7 7 7 0111

    8 8 0 1000

    9 9 0 1001

    10 A 0 1010

    11 B 0 1011

    12 C 0 1100

    13 D 0 1101

    14 E 0 1110

    15 F 0 1111

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    12/24

    12

    Using Bits cont.

    The octal digits (0-7) areused to represent 3-bitgroups (ignoring the left-most 0 of the bit pattern).

    And hexadecimal digits (0-F) are used to represent 4-bit groups.

    For instance the bit pattern101001100110011000111011 isrepresented in octal as

    51463073 as shown.Bit

    pattern

    101 001 100 110 011 000 111 011

    Octal

    Digit

    5 1 4 6 3 0 7 3

    And00100101110110111101000111000101 is represented inhexadecimal as 25DBD1C5as shown.

    Bitpattern

    0010 0101 1101 1011 1101 0001 1100 0101

    hexadecimal

    2 5 D B D 1 C 5

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    13/24

    13

    Programming Languages

    The binary code is referred to as machine language.

    Machine language is the only languages that a computer canunderstand.

    The language consists of instructions in binary code (orhexadecimal) 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 intomachine language.

    Assembly Language considered to be one level above machinelanguage. Main advantage of assembly language over machinelanguage is that instructions in assembly language are not in binary

    code but in English word. The word are translated into machinelanguage code with language translating program, but its alsocumbersome to write because each fundamental instruction must begiven.

    High level language further simplify commands written by humanprogrammer.

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    14/24

    14

    C++ programming Language

    Extension ofC

    Support procedure-oriented and object-oriented programming

    approach

    Invented by Bjarne Stroustrup in 1980

    HOW COMPUTER RUN A PROGRAM

    Edit : Source code ( type the program)

    Compile :

    If no syntax errors -> Object

    Code

    Link : Link to library function -> exe module

    Run : Output ( Check for any semantic errors)

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    15/24

    15

    A Typical C++ Program

    # include

    # define P 100

    / / A typical C++ Program

    main ( )

    {

    Variables declaration

    .. ;

    .. ;

    Statements;

    ... ;

    }

    Preprocessor Directive

    Comment

    main function

    End

    Begin

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    16/24

    16

    Simple C++ Program

    # include

    # include

    // Aturcara ini akan mencetak sahaja (Penggunaan arahan cout)void main ( )

    {

    cout

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    17/24

    17

    Welcome to

    KUTKM

    MELAKA

    BANDARAYA BERSEJARAH

    Exercise:

    Write a complete program to print the following output:

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    18/24

    18

    #include #include

    #define P 100

    void main()

    {

    cout

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    19/24

    19

    Exercise:

    Write a complete program to print the following output:-

    SARJANA MUDA KEJURUTERAAN ELEKTRONIK

    KOLEJ UNIVERSITI TEKNIKAL

    ******************MELAKA*******************

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    20/24

    20

    Manipulator ( # include )

    1. \n : Advances the cursor to the beginning of the next line

    e.g cout

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    21/24

    21

    4. setw (n) : sets the streams internal field width variable to n. This setting remainsin effect only for the next insertion.

    e.g cout

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    22/24

    22

    #include

    #include

    #define P 100

    void main()

    { cout

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    23/24

    23

    #include

    #include

    void main()

    {

    cout

  • 8/6/2019 Lecture 1 Introduction to Computer and Programming Language

    24/24

    24

    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 toproduce a creative output.