Top Banner
1 Introduction to Computer Programming Featuring: C language
33

1 Introduction to Computer Programming Featuring: C language.

Mar 26, 2015

Download

Documents

Ian Byrne
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Introduction to Computer Programming Featuring: C language.

1

Introduction to Computer Programming

Featuring: C language

Page 2: 1 Introduction to Computer Programming Featuring: C language.

2

What is computer?

• Computer is a device which can process data, perform computation and logical operations and gives output

• A computer performs the above using programs and without human intervention

Page 3: 1 Introduction to Computer Programming Featuring: C language.

3

History and Hardware

• Babbage’s analytical engine (1822)• Atanasoff-Berry Computer (ABC, 1937)

– Human operator manipulated external wiring

• Electrical Numerical Integrator and Computer (ENIAC, 1946)– Vacuum tubes

• Mark I (1944)– Mechanical relay switches

• Electronic Delayed Storage Automatic Computer (EDSAC, 1949)– Incorporated a form of memory

Page 4: 1 Introduction to Computer Programming Featuring: C language.

4

History and Hardware (continued)

Page 5: 1 Introduction to Computer Programming Featuring: C language.

5

Computer Hardware & Software

• Hardware – the physical devices of a computer

• Software – the programs or “intelligence” of the computer

Page 6: 1 Introduction to Computer Programming Featuring: C language.

6

Software

• Software – a group of programs

• Program – a specific set of instructions to the computer to perform a task

• Programmer – a person who writes a program

Page 7: 1 Introduction to Computer Programming Featuring: C language.

7

Computer Organization

• Input Unit

• Output Unit

• Memory Unit

• Arithmetic Logic Unit (ALU)

• Central Processing Unit (CPU)

• Secondary Storage unit

Page 8: 1 Introduction to Computer Programming Featuring: C language.

8

Components

Page 9: 1 Introduction to Computer Programming Featuring: C language.

9

Memory and data

• Memory unit: Area to store data and instructions

• Data stored as On or Off pulses

Page 10: 1 Introduction to Computer Programming Featuring: C language.

10

Data representation

• Represented by a combination of eight binary digits (1s and 0s)

• ASCII – American Standard Code for Information Interchange

Page 11: 1 Introduction to Computer Programming Featuring: C language.

11

ASCII representation

• From 00000000 to 11111111; each assigned to a unique character.

• An integer– is stored in memory in its binary equivalence – read as character using its ASCII character

Page 12: 1 Introduction to Computer Programming Featuring: C language.

12

ASCII Table

Page 13: 1 Introduction to Computer Programming Featuring: C language.

13

Evolution of Operating System

• Operating System– A program that controls the execution of an

application program and acts as an interface between the user of a computer and a computer hardware.

• Evolution of Operating system– Simple Batch System– Multi Programmed Batch System– Time Sharing System– Distributed System– Real-time Operating System (Unix, Windows)

Page 14: 1 Introduction to Computer Programming Featuring: C language.

14

PROGRAMMING LANGUAGES

Page 15: 1 Introduction to Computer Programming Featuring: C language.

15

Programming Languages

• Computer program: data and instructions used to operate a computer and produce a specific result

• Programming: writing instructions in a language that the computer can respond to and that other programmers can understand

• Programming language: set of instructions that can be used to construct a program

• Source programs/Source code: Programs written in a computer language

Page 16: 1 Introduction to Computer Programming Featuring: C language.

16

Three General Types of Programming Languages:

• 1940s – Machine Languages– A natural language of a computer, machine dependent– the only language that can be understood and processed directly by

computer

• 1950s – Symbolic/Assembly languages– use of a series of mnemonics to represent commonly used instructions

• 1960s – High-Level Languages – E.g. COBOL, FORTRAN, C, Java

• Note: Machine and assembly languages are low-level languages because they both use instructions that are directly tied to one type of computer

Page 17: 1 Introduction to Computer Programming Featuring: C language.

17

Machine Language

• Executable program: program that can operate a computer

• Executable programs are written with binary numbers, which is a computer’s internal language (machine language)– An example of a simple machine language program

containing two instructions is:11000000000000000001000000000010

11110000000000000010000000000011

• Opcode is short for operation code; tells the computer the operation to be performed

Page 18: 1 Introduction to Computer Programming Featuring: C language.

18

Assembly Language

• Assembly language: uses the substitution of word-like symbols for the opcodes, and decimal numbers and labels for memory addresses

LOAD first

ADD second

MUL factor

STORE answer

Page 19: 1 Introduction to Computer Programming Featuring: C language.

19

Assembly Language (continued)

Page 20: 1 Introduction to Computer Programming Featuring: C language.

20

Earlier high-level programming languages

• COBOL (Common Business Oriented Language)– used primarily for business processing

• FORTRAN (Formula Translation)– primarily perform mathematical calculations

Page 21: 1 Introduction to Computer Programming Featuring: C language.

21

Later High-Level Programming Languages

• PL/I, BASIC, Pascal, Prolog, C, Ada

• C++, Visual Basic

• HTML, Java

Page 22: 1 Introduction to Computer Programming Featuring: C language.

22

Writing, Editing, Compiling and Linking Programs

• Step1 – Write and edit programs

• Step2 – Compile programs– Translate source file into machine language– The output produced by the compiler is called an object

program (machine language version of the source code)

• Step3 – Linking Programs- combines additional machine language code with the object program to create a final executable program

Page 23: 1 Introduction to Computer Programming Featuring: C language.

23

Writing, Editing, Compiling and Linking Programs

Page 24: 1 Introduction to Computer Programming Featuring: C language.

24

Procedural and Object-Oriented Languages

• Procedural language: instructions are used to create self-contained units, called procedures– Procedure: accepts data as input and transforms

it in some manner to produce a specific result as output• Also called function or method

• Procedures conforming to structure guidelines are known as structured procedures

Page 25: 1 Introduction to Computer Programming Featuring: C language.

25

Procedural and Object-Oriented Languages

(continued)• Structured language: high-level

procedural language (e.g., C) that enforces structured procedures

• Object-oriented languages: languages with object orientation such as C++, Java, Visual Basic, and C#

Page 26: 1 Introduction to Computer Programming Featuring: C language.

26

Procedural and Object-Oriented Languages

(continued)

Page 27: 1 Introduction to Computer Programming Featuring: C language.

27

Structured programming

• A technique for organizing and coding computer programs in which a hierarchy of modules is used

• A disciplined approach in writing programs so that it is easier to test, debug and modify.

• Example:– Pascal, Ada, C

Page 28: 1 Introduction to Computer Programming Featuring: C language.

28

History of C language • Developed in the 1970s at AT&T Bell Laboratories by K.

Thompson, D. Ritchie, and B. Kernighan• Evolved from a language called B in the seventies at AT&T Bell

labs• First implemented on the UNIX operating system• Written to help non-scientists develop computer programs• High-level structured language

– Can also access the internal hardware of a computer• C permits a programmer to “see into” a computer’s memory and

directly alter data stored in it• Standard maintained by the American National Standards Institute

(ANSI)• In the 1980s, Bjarne Stroustrup (working at AT&T) developed C++

– C with object-oriented capabilities

Page 29: 1 Introduction to Computer Programming Featuring: C language.

29

The C language

• General purpose programming language• Modern control flow and data structure• Uses economy of expression • Convenient and effective• Useful for writing compilers and operating

systems

Page 30: 1 Introduction to Computer Programming Featuring: C language.

30

Characteristic of C language

• Features structured programming– Top-down: System overview -> Subsystem refined

in detail

– Advantages of top-down programming:• Separating the low level work from the higher level

objects leads to a modular design.

• Modular design means development can be self contained.

• Having "skeleton" code illustrates clearly how low level modules integrate.

• Code is easier to follow, since it is written methodically and with purpose.

Page 31: 1 Introduction to Computer Programming Featuring: C language.

31

The Making of A Quality Program

1. Readability• understandable, with comments and

documentations, using conventions like name of variables and indentations

2. Modularity• problems divided into sub-problems and

assembled in a logical order

3. Efficiency• runs faster and smaller size of program

Page 32: 1 Introduction to Computer Programming Featuring: C language.

32

4. Robustness• Be able to handle all situations in a graceful

manner• Not to crash in unexpected situations or go

to infinite loops

5. Usability• correct, meets the end-user requirement

The Making of A Quality Program (cont.)

Page 33: 1 Introduction to Computer Programming Featuring: C language.

33

Q & A