computer programming (tmk 3102) lecture notes 1

Upload: mamat88

Post on 30-May-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    1/22

    Chapt er 1: In t roduc t ion t o Com put er & Program m ing

    Session Plan (Week1):To understand:

    Computer Hardware Concept

    Computer Software Concept

    Programming Language

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    2/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    2

    What i s a c om puter? An electronic device that stores &

    process data

    Consists of: Hardware: physical aspect of the computer

    that can be seen

    Software: set of instruction that control thehardware and make it performs specific tasks

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    3/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    3

    Com put er Syst em

    Computer User

    Application Software

    System Software

    Computer Hardware

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    4/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    4

    Com puter Hardw are

    Compute r Hardw are

    Keyboard (Input Device)

    Speaker

    (Output

    Device)

    Floppy disk (Secondary Storage)

    Mouse (Input Device)

    Printer (Output Device)

    Monitor

    Screen

    (Output

    Device)

    CD ROM, DVD ROM

    (Secondary Storage)

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    5/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    5

    Com puter Hardw are

    A computer hardware consists of a CPU,memory, hard disk, floppy disk, monitor,printer, and communication devices.

    Memory

    CPU

    Storage

    DevicesDisk, CD, and

    Tape

    Input

    Devices

    Output

    Devices

    Keyboard,

    Mouse

    Monitor,

    PrinterCommunication

    DevicesModem, and

    NIC

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    6/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    6

    Comput er Hardw are - CPU

    The central processing unit (CPU) is the brain of acomputer. It retrieves instructions from memory andexecutes them. The CPU speed is measured inmegahertz (MHz), with 1 megahertz equaling 1 million

    pulses per second. The speed of the CPU has beenimproved continuously.

    Memory

    CPU

    Storage

    Devices

    Disk, CD, and

    Tape

    Input

    Devices

    Output

    Devices

    Keyboard,

    Mouse

    Monitor,

    PrinterCommunication

    DevicesModem, and

    NIC

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    7/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    7

    Compute r Hardw are - Mem ory

    Memoryis to store data and program instructions for CPU toexecute. A memory unit is an ordered sequence of bytes, eachholds eight bits. A program and its data must be brought tomemory before they can be executed. A memory byte is neverempty, but its initial content may be meaningless to your program.The current content of a memory byte is lost whenever newinformation is placed in it.

    Memory

    CPU

    Storage

    DevicesDisk, CD, and

    Tape

    Input

    Devices

    Output

    Devices

    Keyboard,

    Mouse

    Monitor,

    PrinterCommunication

    DevicesModem, and

    NIC

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    8/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    8

    Compute r Hardw are - Mem ory

    Data of various kinds, such as numbers,characters, and strings, are encoded as aseries of bits (zeros and ones).Computers use zeros and ones becausedigital devices have two stable states,which are referred to as zeroand oneby

    convention. The programmers need not tobe concerned about the encoding anddecoding of data, which is performedautomatically by the system based on theencoding scheme. The encoding schemevaries. For example, character J isrepresented by 01001010 in one byte. Asmall number such as three can be stored

    in a single byte. If computer needs tostore a large number that cannot fit into asingle byte, it uses a number of adjacentbytes. No two data can share or split asame byte. A byte is the minimum storageunit.

    .

    .

    .

    2000

    2001

    2002

    2003

    2004

    .

    .

    .

    01001010

    01100001

    01110110

    01100001

    00000011

    Memory contentMemory address

    Encoding for character J

    Encoding for character a

    Encoding for character v

    Encoding for character a

    Encoding for number 3

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    9/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    9

    Comput er Hardw are - St o rage

    Memory is volatile, because information is lost when the power isoff. Programs and data are permanently stored on storagedevices and are moved to memory when the computer actuallyuses them. There are three main types of storage devices:Disk

    drives (hard disks and floppy disks), CD drives (CD-R and CD-RW), and Tape drives.

    Memory

    CPU

    Storage

    Devices

    Disk, CD, and

    Tape

    Input

    Devices

    OutputDevices

    Keyboard,

    Mouse

    Monitor,

    PrinterCommunication

    DevicesModem, and

    NIC

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    10/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    10

    Com puter Hardw are I /O

    Keyboard and Mouse received data from user(input)

    Monitor and printer displays information (output)Memory

    CPU

    Storage

    Devices

    Disk, CD, and

    Tape

    Input

    Devices

    Output

    Devices

    Keyboard,

    Mouse

    Monitor,

    PrinterCommunication

    DevicesModem, and

    NIC

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    11/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    11

    Com puter Hardw are -

    Communica t ion

    A regular modemuses a phone line and can transfer data in a speed up to56,000 bps (bits per second). A DSL (digital subscriber line) also uses aphone line and can transfer data in a speed 20 times faster than a regularmodem. A cable modemuses the TV cable line maintained by the cablecompany. A cable modem is as fast as a DSL. Network interface card

    (NIC) is a device to connect a computer to a local area network (LAN).The LAN is commonly used in business, universities, and governmentorganizations. A typical type of NIC, called 10BaseT, can transfer data at10 mbps (million bits per second).

    Memory

    CPU

    Storage

    DevicesDisk, CD, andTape InputDevices

    Output

    Devices

    Keyboard,Mouse

    Monitor,

    PrinterCommunication

    DevicesModem, and

    NIC

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    12/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    12

    Quest ions

    What is the physical aspect of thecomputer?

    Give examples of computer hardware. What are the communication hardware?

    What is bit? 1 byte consists of?

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    13/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    13

    Com puter Sof tw are

    Software

    An executable program that is run in the computer System Software: Windows, Linux ,hardware drive etc. Application Software: word processing, browser etc.

    Program An organized list of instruction that when executed causes the

    computer to behave in a predetermined manner

    Without program, computers are useless. A program is like arecipe. It contains a list of ingredients (called variables) and a listof directions (called statement) that tell the computer what to dowith the variables. The variables can represent numeric data, textor graphical images

    Program are written using computer programming language

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    14/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    14

    Program m ing Language

    Machine Language

    Assembly Language

    High Level Language

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    15/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    15

    Mac hine Language

    Machine language is a set of primitiveinstructions built into every computer. Theinstructions are in the form of binary code, so

    you have to enter binary codes for variousinstructions. Program with native machinelanguage is a tedious process. Moreover theprograms are highly difficult to read andmodify. For example, to add two numbers, you

    might write the an instruction in binary like this:1101101010011010

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    16/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    16

    Assem bly Language

    Assembly languages were developed to makeprogramming easy. Since the computer cannotunderstand assembly language, however, aprogram called assembler is used to convertassembly language programs into machinecode. For example, to add two numbers, youmight write an instruction in assembly code likethis:

    ADDF3 R1, R2, R3

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    17/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    17

    High -Leve l Language

    The high-level languages are English-like and

    easy to learn and program. For example, to

    add two numbers, you might write aninstruction in high level language codelike this:

    R3 = R1 + R2;

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    18/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    18

    Popular High Leve l Language

    Java (This is what are we going to learn) COBOL (COmmon Business Oriented Language) FORTRAN (FORmula TRANslation) BASIC (Beginner All-purpose Symbolic Instructional Code)

    Pascal (named for Blaise Pascal) Ada (named for Ada Lovelace) C (whose developer designed B first) Visual Basic (Basic-like visual language developed by

    Microsoft)

    Delphi (Pascal-like visual language developed by Borland) C++ (an object-oriented language, based on C)

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    19/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    19

    Compi l ing

    A program written in a high-level language is called a sourceprogram. Since a computer cannot understand a sourceprogram. Program called a compileris used to translate thesource program into a machine language program called anobject program. The object program is often then linked with

    other supporting library code before the object can beexecuted on the machine.

    CompilerSource File Object FileLinker Excutable File

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    20/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    20

    Com pi l ing (2)

    You can port a source program to any machine with appropriatecompilers. The source program must be recompiled, however, becausethe object program can only run on a specific machine. Nowadayscomputers are networked to work together. Java was designed to runobject programs on any platform. With Java, you write the program

    once, and compile the source program into a special type of objectcode, known as bytecode. The bytecode can then run on any computerwith a Java Virtual Machine, as shown in Figure 1.5. Java VirtualMachine is a software that interprets Java bytecode.

    Java Bytecode

    Java VirtualMachine

    AnyComputer

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    21/22

    TMK 3102-Chap 1: Introduction toCom uter & Pro rammin

    21

    Quest ions

    What are 2 types of software?

    Give 3 types of programming language.

    List examples of High LevelProgramming Language?

    What is the meaning of compiling?

  • 8/9/2019 COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 1

    22/22

    TMK 3102-Chap 1: Introduction to 22

    Thank you.