TOPIC 1 INTRODUCTION TO COMPUTER SYSTEM AND COMPUTER

  • Slides: 51
Download presentation
TOPIC 1: INTRODUCTION TO COMPUTER SYSTEM AND COMPUTER PROGRAM Faculty of Computer and Mathematical

TOPIC 1: INTRODUCTION TO COMPUTER SYSTEM AND COMPUTER PROGRAM Faculty of Computer and Mathematical Sciences

Chapter Objectives At the end of this chapter you should be able to: 1.

Chapter Objectives At the end of this chapter you should be able to: 1. Explain the component of a computer system 2. Identify the differences between software and hardware 3. Identify the elements of a computer programs 4. Adopt a good programming styles

TOPIC 3. Elements Of A Computer Program 4. The Importance Of Programming 2. Program

TOPIC 3. Elements Of A Computer Program 4. The Importance Of Programming 2. Program and Programming Languages 1. Elements Of A Computer System 5. Good Programming Styles 7. History of Programming Language (C++) 6. Relationship Between Compiler, Interpreter And Program

Elements of Computer System that m s e ic v e d l a

Elements of Computer System that m s e ic v e d l a he physic ystem s consist of t r e t u p m o up your c ake Hardware Computer Software is the se t tell the of instructions comput er hard or program th ware ho a w and w t to do hat is an electronic device (hardware), operating under the control of instruction (software) stored in its own memory, that can accept data, process the data according to specified rules, produce results, and stores the results for future use. Main Menu

Hardware H A R D W A R E Input devices – for capturing

Hardware H A R D W A R E Input devices – for capturing information Keyboard, Mouse, Microphone, Scanner, Digital Camera and Web Cam Output devices – for presenting information Monitor, Speaker and Portable Media Player System unit – for creating new information and data processing Memory , Central Processing Unit (CPU), Motherboard, Power Supply Storage – for storing information Hard Disk, Compact Disc, USB Flash Drive, Memory Card Telecommunication devices – for communicating information Modem and Network Card Connecting devices – for moving information to and from various hardware Cables, Telephone Lines, Satellite

Software S O F T W A R E System Software Application Software 1.

Software S O F T W A R E System Software Application Software 1. Uses to run computer. 2. To control and maintain the operation of computer and its devices. 3. Serve as the interface between computer hardware, user and application software. 4. Example: Operating System (Microsoft Windows XP) and Utility Program (Antivirus). 1. Program designed to make user more productive. 2. Assist user to with personal task and perform specific information processing task such as writing term paper, and creating presentation slide, and writing and program. 3. Example: Microsoft Office 2007, Microsoft Power. Point 2007

Memory is an electronic components that stores instructions waiting to be executed by the

Memory is an electronic components that stores instructions waiting to be executed by the processor, data needed by those instructions, and the results of processed data (information). Memory stores three (3) basic categories of items: ØThe operating system and other system software that control or maintain the computer and its devices. ØApplication program that carry out specific task such as word processing. ØThe data being processed by the application program and resulting information. Bytes and Addressable Memory Type of Memory Size Memory Access Time

Byte and Addressable Memory A byte (character) is the basic storage unit in memory.

Byte and Addressable Memory A byte (character) is the basic storage unit in memory. When application program instructions and data are transferred to memory from storage devices, the instruction and data exist as bytes. Each byte resides temporarily in a location in memory that has an address. An address simply is a unique number that identifies the location of the byte in memory. To access data or instruction in memory, the computer references the address that contains byte of data. Each byte stored in unique location called an address, similar to seats in a concert hall.

Memory Size Term Abbreviation Approximately Exact Amount of Number of Bytes Kilobyte KB or

Memory Size Term Abbreviation Approximately Exact Amount of Number of Bytes Kilobyte KB or K 1 thousand 1, 024 Approximate Number of Pages of Text ½ Megabyte MB 1 million 1, 048, 576 500 Gigabyte GB 1 billion 1, 073, 741, 824 500, 000 Terabyte TB I trillion 1, 099, 511, 627, 776 500, 000 Ø 1 byte = 8 bits = 1 character ØTo simplify memory and storage definitions, computer users often round a kilobyte down to 1, 000. ØFor example if a memory chip can store 100 KB, it can hold approximately 100, 000 bytes (characters).

Types of Memory Volatile Memory Data/information lose when power is turn off. Temporary means

Types of Memory Volatile Memory Data/information lose when power is turn off. Temporary means for holding data, instruction or information currently being processed. Example: 1. Random Access Memory (RAM) - Consist of memory chips that can be read from and write to by the processor and other devices. The processor (CPU) interprets and executes a program’s instructions while the program is in RAM. 2. Cache – Sit between RAM and processor. Cache speeds up processing time because it stores frequently used instructions and data. The contents of memory retained although the computer’s power is turned off. Permanent means to hold data, instruction, information that is currently being processed. Non-Volatile Example: 1. Read Only Memory (ROM) - data on most ROM chips cannot be modified. 2. Flash Memory - Can be erased electronically and rewritten. 3. CMOS (complementary metal-oxide semiconductor) - store a computer’s startup information such as calendar, date and time.

What is Memory Access Time? Access time is the amount of time the processor

What is Memory Access Time? Access time is the amount of time the processor to read data, instructions, and information from memory.

Processor also called central processing unit (CPU), interprets and carries out the basic instructions

Processor also called central processing unit (CPU), interprets and carries out the basic instructions that operate the computer. Processor significantly impacts overall computing power and manages most of a computer’s operations. Two common multi-core processors used today are: 1. Dual core chip that contains two separate processors 2. Quad-core chip that contains four separate processors Arithmetic Logic Unit (ALU) Control Unit CPU Machine Cycle Data Representation

Components of Processor contain a control unit and an arithmetic logic unit (ALU). These

Components of Processor contain a control unit and an arithmetic logic unit (ALU). These two components work together to perform processing operations. Control Unit Arithmetic Logic Unit Directs and coordinates most of the operations in the computer. Performs arithmetic, comparison and other operations. Interprets each instruction issued by a program and then initiates the appropriate action to carry out the instruction. Arithmetic operations include basic calculations such as addition, subtraction, multiplication, and division. Comparison operations involve comparing one data item with another to determine whether the first item is greater than, equal to, or less than the other item. Depending on the result of the comparison, different actions may occur.

What is a Machine Cycle? Ø Four operations of the CPU comprise a machine

What is a Machine Cycle? Ø Four operations of the CPU comprise a machine cycle Step 1. Fetch Obtain program instruction or data item from memory Memory Step 2. Decode Step 4. Store Translate instruction into commands Write result to memory Processor ALU Step 3. Execute Carry out command Control Unit

Data Representation How do computers represent data? Ø Most computers are digital § §

Data Representation How do computers represent data? Ø Most computers are digital § § § Recognize only two discrete states: on or off Use a binary system to recognize two states Use Number system with two unique digits: 0 and 1, called bits (short for binary digits)

Data Representation What is a byte? Ø Ø Eight bits grouped together as a

Data Representation What is a byte? Ø Ø Eight bits grouped together as a unit Provides enough different combinations of 0 s and 1 s to represent 256 individual characters § § § Numbers Uppercase and lowercase letters Punctuation marks

Data Representation What are two popular coding systems to represent data? Ø Ø ASCII—American

Data Representation What are two popular coding systems to represent data? Ø Ø ASCII—American Standard Code for Information Interchange EBCDIC—Extended Binary Coded Decimal Interchange Code ASCII 00110000 00110001 00110010 0011 Symbol 0 1 2 3 EBCDIC 11110000 11110001 11110010 11110011

Data Representation How is a letter converted to binary form and back? Step 1.

Data Representation How is a letter converted to binary form and back? Step 1. Step 2. The user presses the capital letter T (SHIFT+T key) on the keyboard. An electronic signal for the capital letter T is sent to the system unit. T Step 4. After processing, the binary code for the capital letter T is converted to an image, and displayed on the output device. Step 3. The system unit converts the scan code for the capital letter T to its ASCII binary code (01010100) and stores it in memory for processing.

Computer Program and Programming What is a computer program? Computer program or program is

Computer Program and Programming What is a computer program? Computer program or program is a set of instructions that tells the computer what to do. You must remember that a computer is only a machine and it will not do anything until it is given instructions. What or who is a programmer? Programmer is a person who writes and modifies a computer program using programming languages. What is programming languages? Programming languages is a specific computer language used to write an instruction (program) for the computer (machine). What are the types of programming languages? There are two (2) types of programming languages which are: 1. Low-Level Programming Languages 2. High-Level Programming Languages

Low-Level Programming Languages Machine Language (1 GL) §Is the only language that computer can

Low-Level Programming Languages Machine Language (1 GL) §Is the only language that computer can directly understand. §Uses a series of binary digits (1 s and 0 s) with a combination of numbers and letters that represent binary digits. §Example… Assembly Language (2 GL) §Instructions made up of symbolic instruction codes, meaningful abbreviations and codes. §Source program contains code to be converted to machine language §Uses assembler to translate to machine code §Example…. Low. Level

Machine Language

Machine Language

Assembly Language

Assembly Language

High-Level Programming Language Procedural Language (3 GL) Visual Programming Language (5 GL) High-Level Programming

High-Level Programming Language Procedural Language (3 GL) Visual Programming Language (5 GL) High-Level Programming Language Non-Procedural Language (4 GL) Object-Oriented Programming Language

Procedural Language Ø Uses series of English-like words to write instructions. Ø Most widely

Procedural Language Ø Uses series of English-like words to write instructions. Ø Most widely used are BASIC, COBOL, and C. Ø Uses compiler to translate to machine code.

Object-Oriented Programming Language (OOP) What is an object-oriented programming (OOP) language? Used to implement

Object-Oriented Programming Language (OOP) What is an object-oriented programming (OOP) language? Used to implement object-oriented design Object is item that contains data and procedures that act on data Major benefit is ability to reuse existing objects Event-driven— Event-driven checks for and responds to set of events Event is action to which program responds Java, C++, C#, and Visual Basic are complete object-oriented languages

Example Of Java Language (OOP)

Example Of Java Language (OOP)

Example of C++ //This program displays a status based on the mark #include <iostream.

Example of C++ //This program displays a status based on the mark #include <iostream. h> #include <conio. h> void main() { int mark; cout << “Enter the mark : ”; cin >> mark; if (mark>=50) cout << “PASSED” <<endl; getch(); }

Non-Procedural Language Ø Ø Nonprocedural language that allows access to data in database Popular

Non-Procedural Language Ø Ø Nonprocedural language that allows access to data in database Popular 4 GL is SQL, query language that allows users to manage data in relational DBMS

Visual Programming Languages Ø Provides visual or graphical interface for creating source code Ø

Visual Programming Languages Ø Provides visual or graphical interface for creating source code Ø Often used in RAD (rapid application Development)environment Available in Visual Studio 2005, Delphi and Power. Builder

Other Available Programming Languages ALGOL ADA BASIC FORTH FORTRAN LOGO LISP PASCAL APL PILOT

Other Available Programming Languages ALGOL ADA BASIC FORTH FORTRAN LOGO LISP PASCAL APL PILOT SMALLTALK HYPERTALK MODULA-2 PL/1 PROLOG Main Menu

Elements of Computer Program 1. Identifiers: Variable, Constant (ie: x, y, z, sum, var,

Elements of Computer Program 1. Identifiers: Variable, Constant (ie: x, y, z, sum, var, temp) 5. Control Structure – -Sequential -Conditional (if, switch case) -Repetition/Iteration (while do, do while, for) Elements of A Computer Program 4. 1. Assignment (ie: sum=x+y, x=y, sum=0) 4. 2. Expression: Arithmetic (ie: x+y), Logical (ie: x && y), Relational (ie: x<y) 2. Data Types: int, float, char (ie: int x, float y, char name) 3. Statement: cout (ie: cout<<“Key in number ”), cin (ie: cin>>number)

 • • int x = 1; float y=4. 9; Sum=x+y; cout>>sum;

• • int x = 1; float y=4. 9; Sum=x+y; cout>>sum;

Sample Program /* This is a program that computes the sum of two integer

Sample Program /* This is a program that computes the sum of two integer numbers */ Identifier (Variable: x, y, sum) #include <iostream. h> //Preprocessor to handle cout and cin statement #include <conio. h> //Preprocessor to handle screen void main() //This is directive { Data Type int x, y, sum; //Declaration (int) cout << “n. Enter first number: “; //This a prompt cin >> x; //Input from console cout << “ n. Enter second number: “; Statement (cin, cout) cin >> y; Expression (x+y) sum = x + y; //Adding x and y Assignment cout << “n. Sum = “ << sum; //Output to console (sum = x+y) getch(); //function to handle screen } Main Menu

The Importance of Programming Easy to express task from particular problem domain Allow user

The Importance of Programming Easy to express task from particular problem domain Allow user to instruct computer to do specific task in a certain instances A skill required for a computer scientist and software engineer A skill required to create a successful computer program (software) An activity that is closer to computer science Improve reasoning and critical thinking Main Menu

Good Programming Styles Spacing – each instruction begin with new line Indent – each

Good Programming Styles Spacing – each instruction begin with new line Indent – each instruction has indention depends on it structure Comment – help a human reader to understand the program Variable name – use descriptive name Rules of naming the variable: - Other than reserved word (do not use char, int, float, double, long, String etc. . ) - Alphanumeric A-Z, a-z, 0 -9, - (underscore) but do not use number (0 -9) as variable. - Length recommended 3 -8 characters

Spacing • Each instruction should begin with new line(s) //Good main() { } cur.

Spacing • Each instruction should begin with new line(s) //Good main() { } cur. Year = 2004; cout << "Please enter year born: "; cin >> year. Born; age = cur. Year - year. Born; cout << "Your age is " << age; //Bad main(){cur. Year = 2004; cout << "Please enter year born: "; cin >> year. Born; age; }

Indent //Good main() { cout << "Please enter year born: "; cin >> year.

Indent //Good main() { cout << "Please enter year born: "; cin >> year. Born; age = cur. Year - year. Born; cout << "Your age is " << age; } //Bad main() { cout << "Please enter year born: "; cin >> year. Born; age = cur. Year - year. Born; cout << "Your age is " << age; }

Comment //This program calculates age main() { //input year born cout << "Please enter

Comment //This program calculates age main() { //input year born cout << "Please enter year born: "; cin >> year. Born; age = cur. Year - year. Born; cout << "Your age is " << age; } //calculate age //output age to console

Meaningful Variable Name //Good main() { } //Bad main() { } cur. Year =

Meaningful Variable Name //Good main() { } //Bad main() { } cur. Year = 2004; cout << "Please enter year born: "; cin >> year. Born; age = cur. Year - year. Born; cout << "Your age is " << age; number 2 = 2004; cout << "Please enter year born: "; cin >> number 1; number 3 = number 2 – number 1; cout << "Your age is " << number 3;

What is a Good Programming Style? A good program is a program that is

What is a Good Programming Style? A good program is a program that is easy to read and easy to be understood by other programmers…

More Example Comment Preprocessor Directive Function name Begin Block Function Body End Block /*

More Example Comment Preprocessor Directive Function name Begin Block Function Body End Block /* This program is to compute the sum of two integer numbers */ #include <iostream. h> //Preprocessor to handle cout and cin statement #include <conio. h> //Preprocessor to handle screen, getch() void main() //This is directive { int x, y, sum; //Declaration cout << “n. Enter first number: “; //This a prompt cin >> x; //Input from console cout << “ n. Enter second number: “; cin >> y; sum = x + y; //Adding x and y cout << “n. Sum = “ << sum; //Output to console getch(); //function to handle screen } Semicolon = delimiter. Use to end of statement or line.

Comments Ø Comment is used to explain the function of the program or statement

Comments Ø Comment is used to explain the function of the program or statement in order to help them or others read and understand the programs or statement. Ø Use two different punctuation marks § Begin with /* and end with */ - use if the comments runs more than one line. § // - use if takes a line or less Ø Anything placed after the // or inside /* */ are considered comments and will not be executed by the computer.

The "Include" Directive and Header Files Ø #include <iostream. h> is called an include

The "Include" Directive and Header Files Ø #include <iostream. h> is called an include preprocessor directive. It is used to enables the program to use certain functions contained in the external file iostream. h. As the file is placed before the program proper, it is called a header file (with the extension. h) Ø There are numerous of predefined functions stored in header files and this is to simplify programming and reduce programming time. Ø Each header files stores functions that are related to a particular application. For example two of the functions contained in the external file iostream. h are Ø cin >> used for reading data from the keyboard Ø cout << used for sending output to the monitor Ø Preprocessor directive should begin with # symbol. Some other preprocessor directives: Ø #include Ø #define (commonly used along with constant value declaration)

Functions Ø All C++ are written in terms of functions. Ø A C++ must

Functions Ø All C++ are written in terms of functions. Ø A C++ must have at least main() function is a reserved word. Program running started from main() function when it is been executed. Ø Every C++ function, including main() must have a body enclosed in braces {}. The function body (also called block) can be any size. Ø A function always but not all end with return command. This command signals end of a function. C++ then returns control to whatever was in control of the program before the function. Ø If the function is void, therefore no value is returned. Ø If the function is other than void (i. e. int, char, float, double, string etc), therefore, it should return a value.

Braces (Begin And Ending Block) Ø Braces is used to mark the beginning and

Braces (Begin And Ending Block) Ø Braces is used to mark the beginning and ending the block of code. Ø Open “{“ is beginning of the block code. Ø Close “}” is ending of the block code Ø Braces “{“ and “}” should be coupling. One of the braces missing will cause syntax error in your program. Main Menu

Relationship Between Compiler, Interpreter And Program What are the compiler and interpreter? Compiler and

Relationship Between Compiler, Interpreter And Program What are the compiler and interpreter? Compiler and interpreter are the program called language translator that accept humanreadable source statement (code) and produces machine-readable instruction. Assembler is also language translator.

Relationship Between Compilers, Interpreters And Programs Compilers q. Program that converts entire source program

Relationship Between Compilers, Interpreters And Programs Compilers q. Program that converts entire source program (high level language) into machine language before executing it. q. Translate the source code once and saves to be reused. q. Requires less memory and runs faster. qi. e. PASCAL, C++, COBOL Language Translator Assemblers q. A program that translates the assembly language program into machine language. qi. e. MASM Interpreters q. Program that translates one program code (high level language) statement into machine language and executes one at a time. q. Does not produce object code (object program). q. Program is easier to develop. qi. e. BASIC.

Steps In Running A Program Using Compiler Tools Step Editor (Borland C++) Edit Preprocessor

Steps In Running A Program Using Compiler Tools Step Editor (Borland C++) Edit Preprocessor Source module/source code/source program: a program written in a highlevel language. Product Preprocess Source Module Compiler Compile Object Module Linker Link Library Executable Module Loader Load Run Result / Output Object module/object program/object code: the machine language version of the high-level language program. Linker: a program that combines object module with other program in the library and is used in the program to create executable module. Loader: a program that loads an executable program into main memory

Steps In Running A Program Using Intepreter Interpreters q. Program that translates one program

Steps In Running A Program Using Intepreter Interpreters q. Program that translates one program code (high level language) statement into machine language and executes one at a time. q. Does not produce object code (object program/object module). q. Program is easier to develop. qi. e. BASIC, Java Source Program Data (Library) Interpreter Result Main Menu

A Brief History of Programming Languages (C++) q C++ (OOP) is built upon the

A Brief History of Programming Languages (C++) q C++ (OOP) is built upon the foundation of C (structured programming language). q C++ is a superset of C and C++ compilers can be used to compile C programs. q C++ is an expanded and enhanced version of C that embodies the philosophy of object-oriented programming. q C was invented and first implemented by Dennis Ritchie in 1970 s, while C++ invented by Bjarne Stroustrup in 1979 at Bell Laboratories in Murray Hill. q The reason for invention of C++ is to cater the increases of complexity in computer problem solving or programming. Main Menu

END OF TOPIC 1

END OF TOPIC 1