9/14/2012

CHAPTER 1: INTRODUCTION TO COMPUTERS AND PROGRAMMING
Lizawati Binti Mi Yusuf
Faculty of Computer Science and Information Systems (FSKSM) Department of Modeling and Industrial Computing (PPI) N28-438-03 (Level 4) 07-55 32095 lizawati@utm.my

1

What is a program?
• Computer: programmable machine
designed to follow instructions instructions.

• Program: instructions in computer
memory to make it do something.

• Programmer: person who writes
instructions (programs) to make computer perform a task

• SO without programmers, no SO, programmers
programs…

• Without programs, a computer cannot
do anything…

2

1

9/14/2012 Computer Components 3 Computer Components SECONDARY STRORAGE Stores data and programs Central Processing Unit (CPU) Executes computer instructions Control Unit Arithmetic & Logic Unit (ALU) INPUT Sends data to the central processing i unit (CPU) OUTPUT Makes processed information i f ti available Memory Holds data and programs temporarily PROCESSING 4 2 .

Hardware optimized for high-speed numeric calculation. • Control Unit o o Retrieves and decodes program instructions. yes/no decisions. false) or 1 (on.9/14/2012 Central Processing Unit (CPU) • The “administrative” section of the computer. Each byte in memory is identified by a unique number known as an address. Has values 0 (off. Main memory is erased when program terminates or volatile computer is turned off. Coordinates activities of all other parts of computer.Contains the decision mechanisms that allow the computer 5 Main Memory • Stores instructions and data that are to be processed by the • • • • computer. . It is volatile. o o o 6 The number 149 is stored in the byte (10010101) with the address 16. • It is the computer’s coordinator • It is responsible for supervising the operation of the other sections. and the number 72 (01001000) is stored at address 23. • Arithmetic and Logic Unit o o Hardware designed for true/false. 3 . . Also called Random Access Memory (RAM). coordinator. true) o Byte: 8 consecutive bits. Organized as follows: Information is stored in bits or binary digits. Bytes have addresses.Responsible for performing calculations. Bit: Smallest piece of memory.

• Data retained when program is not running or computer is turned off. • Many devices can provide input: o o o o o Keyboard Mouse Scanner Digital camera Microphone 8 4 . hard drive o Optical disc: CD-ROM.9/14/2012 Secondary Storage • It is non-volatile. connected to the USB port: pen drive 7 Input Devices • Devices that send information to the computer from outside. DVD-ROM o Flash drives. zip disk. • Comes in a variety of media: o Magnetic disc: floppy disk.

games. programs to solve specific problems. Linux. Examples: Windows. • Categories of software: o Operating system: programs that manage the computer hardware and the programs that run on them. o Application software: programs that provide services to the user user. • The output is sent to an output device • Many devices can be used for output: Computer monitor o Printer o Speaker o Plotter o 9 Software • Programs that run on a computer. Examples: word processing.9/14/2012 Output Devices • Output is information sent from a computer program to the outside world. 10 5 . UNIX.

Step 5: Multiply the number of hours by the amount paid per hour. call it A Step 2: Determine the second number. store it in memory. call it C i the thi d b ll Step 4: Find the sum of A. store it in memory. Once the user enters a number.9/14/2012 Programs and Programming Languages • A program is a set of instructions that the computer follows to perform a task.B and C. • Programming language: a language used to write programs • We start with an algorithm. The message must include the result of the calculation performed in Step 5. and store the result in memory. Step 6: Display a message on the screen that tells the amount of money earned. Once the user enters a number. call it the RESULT Step 6: Present the RESULT 11 Programs and Programming Languages • Example algorithm for calculating gross pay: o o o o o o Step 1: Display a message on the screen asking "How many hours did you work?" Step 2: Wait for the user to enter the number of hours worked. which is a set of well-defined steps. call it X Step 5: Divide X by 3. 12 6 . • Example algorithm for calculating the average of 3 numbers: o o o o o o Step 1: Determine the first number. call it B Step 3: D t St 3 Determine th third number. Step 3: Display a message on the screen asking "How much do you get paid per hour?" Step 4: Wait for the user to enter an hourly pay rate.

it is not ready to be executed on the computer. A low level language that is processor dependent. o • High-level language Closer to human language A language that language. • The computer only executes machine language instructions. o • Assembly language One level above machine language. programmers use programming languages. such as 1011010000000101 • Rather than writing programs in machine language language. o High level programming languages are not processor dependent. 14 7 . • Machine language instructions are binary numbers. o Each CPU has its own assembly language. and understand.9/14/2012 Types of Programming Language • Machine language The only language the computer can understand. o A program written in a high-level language must be translated into a language that can be understood by a computer before it can be run. write. o 13 Machine language • Although the previous algorithm defines the steps for calculating the gross pay. people can read. understand o In binary machine code (0’s/1’s) directly.

• Step 3: Run compiler to convert source program into machine instructions. • Step 4: Run linker to connect hardware-specific code to machine instructions. o 16 8 . producing an executable file. Steps (2) to (4) are often performed by a single command or button click click. • Step 2: Run preprocessor to convert source file directives to source code program statements. o Errors detected at any step will prevent execution of following steps.9/14/2012 Some Well-known Programming Languages 15 From A High-level Program To An Executable File • Step 1: Create file containing the program with a text editor.

CodeWarrior. compile. and debug a program into a single software application application. etc. combine all the tools needed to write. • Examples are Microsoft Visual C++. or IDE.9/14/2012 From A High-level Program To An Executable File Source Code p Compiler Object Code Preprocessor Linker Modified Source Code Executable Code 17 Integrated Development Environments (IDEs) • An integrated development environment. 18 9 . Borland C++ Builder.

9/14/2012 What is a program made of? • Common elements in programming languages: o o o o o o Key W d K Words Programmer-Defined Identifiers Operators Punctuation Syntax Variables 19 Sample C Code #include <stdio. world…\n").h> int main (void) { printf (“Hello. return 0. } 20 10 .

Procedures/functions are written to process data. Processing and Output • Three steps that a program typically performs: o Gather input data G th i td t * From keyboard * From files on disk drives Process the input data o Display the results as output * Send it to the screen * Write to a file o 21 Procedural and object-oriented programming • Procedural programming o o Focus iis on the process. Messages sent to objects to perform operations. Focus is on objects. which contain data and the means to manipulate the data.9/14/2012 Input. • Object-Oriented programming o o 22 11 .

Sign up to vote on this title
UsefulNot useful