Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
MT262 23-9-2006 Week-1 Prepared by: Dr.Bayan Abu Shawar, AOU-Jordan This lecture notes covers units 1, 4, and 5 of Block I. Introduction: MT262 module: Putting computer system to work concerns with computer programming and teaching the skills which enables to write programs to solve problems at the end. Before start teaching you how to program using Borland C++, A brief introduction about computer hardware, software are discussed. What is a computer? A device that accepts input, process data, store data, and produces output. These are the main basic tasks of a computer. Simply, any computer system is composed of computer hardware and software. "The hardware components of a computer system are the electronic and mechanical parts. The software components of a computer system are the intangible parts: the data and the computer programs. "1 1. Computer Hardware The main hardware devices components of a computer are: 1. an input device gathers and translates input into a form that the computer can process, these are devices such as: keyboard, mouse, scanner, microphone, card-reader, and bar reader. 2. Processing data is done in a device called central processing unit (CPU). A processor is ,(the brain of a computer), an electronic device about one inch square covered in plastic, in which a processor manipulates data in many ways by applying a series of actions. 3. Output device, produces results using devices such as: printers, screens, plotters, and loud speaker. 4. Storing data, a computer must store data so that it will be available for processing. There are two places to store data: Maim memory (MM), which holds the programs temporarily during execution. Secondary storage, which holds data and programs permanently such as hard-disk, floppy disks, CD's, 1 http://chortle.ccsu.edu/CS151/Notes/chap01/ch01_3.html 1 1.1Types of memory: To differentiate between memory types, we must first introduce the following concepts: Volatility, is used to distinguish two types: volatile in which all data are erased from memory when the power is switched off or cut off. The other is non-volatile in which the memory keeps the information regardless of electrical power. Accessing time, is the average time it takes to allocate on the storage medium. Data transfer rate: is the amount of data that a storage device can move from a storage medium to computer per second. The storage capacity, is the maximum amount of data that can be stored on a storage medium. 1.1.1 The main memory: The M.M is classified into two types: RAM (Random Access Memory) and ROM (Read Only Memory). The random access means that each byte of data could be retrieved at the same time regardless of its position. Type of M.M RAM Accessing time Random access ROM Random access Read/Write Volatility Read and write volatile memory Writing only once Non-volatile in the factory use to store the operating system software. In RAM, data are stored in machine language which is composed of 0's and 1's (called bits). a group of 8 bits represents a byte, 4 bytes represents word, Kilo Byte (KB) = 1,024 bytes. Mega Byte (MB) = 220 bytes Gega Byte (GB) = MB is the usual unit to measure the storage capacity of RAM. "When people say that a computer has "128 megabytes of RAM" they are talking about how big its main memory is. One megabyte of memory is enough to hold approximately one million characters of a word processing document. (There will be more about bytes and megabytes later on in these notes.) Nothing permanent is kept in main memory. Sometimes data are placed in main memory for just a few seconds; only as long as they are needed. "1 2 Why a computer needs a secondary storage? Because: 1. the M.M is volatile holding data and programs that the processor works with, so it interacts with the processor millions of time per second, 2. the size of M.M is limited, 3. the M.M is expensive, 4. the M.M is not removable from one computer to another. Because of the previous reasons we need a secondary storage (auxiliary storage) which is: 1. holding data permanently (non volatile), it is connected with the main memory 2. cheap, 3. removable, 4. having a bigger size than M.M The disadvantage of the secondary storage in general is the speed, it is slower than the M.M, so transferring data from secondary to M.M is slower that moving the same data from M.M to the processor. 1.1.2 Examples of secondary storage: Magnetic tape: it’s a tape, Using sequential access, in which to allocate data in the tape, the tabe will be read from the beginning till it reaches its target. The accessing is lower than random access, It is a read and write medium. Tape backup, is used for audio recording, Cheap, Portable, Keeping large quantity equivalent to hard-disk, Read ad write medium, Use sequential access Not used for information but to make safety (back up) copies of information. 3 Magnetic disk storage, which has two types: floppy disk, and hard-disk. 1. Floppy disk, is a flexible disk made of plastic film coated with magnetic particles and enclosed in a rigid plastic for protection. Its storage capacity is not large, It use random access to allocate data, It is slower to access than the hard-disk. 2. Hard disk, is a flat, rigid disk made of aluminum or glass and coated with a magnetic Oxide. It uses random access, It is faster than the floppy disk, because the floppy disk starts to rotate only when you request data, the harddisk is continuing in motion. CD-ROM, is cheap Large capacity, It is written only once, and is used to distribute large quantity of information. Other types of CD's are: Write once CD Re-Writable CD's. DVD-ROM, only readable DVD-RAMs, rewritable. What had been mentioned so far is the hardware part of the computer (I/O devices, processor, and memory). Figure 1-1 shows main hardware parts. "The bus is a group of wires on the main circuit board of the computer. It is a pathway for data flowing between components. Most devices are connected to the bus through a controller which coordinates the activities of the device and the bus. "1 As it was mentioned before, a computer system composes of hardware and software. Before moving on in discussing computer software, categories of computers are displayed below. 4 1.2 Categories of computers: Computers could be classified: according to size and powerful according to input data general classification 1.2.1 Categorization according to size and power: 1. Micro-computers: small systems, such as PC 2. Mini-Computers: intermediate in size, can carry out the processing tasks for several people working at terminals that are connected to mini-computers. 3. Main-frames: large systems, and expensive, usually used in business and governments to provide centralized storage, processing and management for large amount of data, serves more users than minicomputer. 4. Super-computer: are the fastest and the most expensive, originally designed for computer intensive systems such as molecular weapons. 1.2.1 Categorization according to input data: 1. Digital computers: accepts input from users such as numbers, characters, like our PC's. 2. Analogue computers: accepts input data from the outside environment such as temperature and pressure. 3. Hybrid computers: combine both of the digital and analogue systems. 1.2.3 General categorization: 1. Embedded systems 2. Non-embedded system, like our PC's, lab-top,.. An Embedded system, in this model, the computer takes the form of a small system buried within domestic appliances, machine tools, measuring instruments and road vehicles. Embedded systems have two types of input and output: 1. I/O coming from (or going to) users, such as pressing buttons to make a washing machine work. 2. I/O coming from (going to) component of appliance, such as taking input from water temperature, and water sensors. 5 2. Computer software Computer software (SW) is a general terminology; represents a program or a set of programs with data that cooperate to achieve a task. The SW makes a computer useful. SW is kept on some hardware device such as the hard disk. A computer program is a set of detailed, step by step instructions that tells a computer how to solve a problem or carry out a task. Computer software could be classified into: 1. System Software 2. Application software 2.1 System Software: It helps the computer to carry out its basic operation tasks. Examples of system software are: 1. Programming languages 2. Compilers 3. Interpreters 4. Operating systems 2.1.1 Programming languages A program language is composed of a set of symbols, rules, syntax and semantics to do operations and solve problems in computers, such as Cobol, Fortran, Pascal, Java,.. Level of programming languages: a) Machine language, which is a low level language, in biary code (0's and 1's) that computer could execute directly. b) Assembly language, where each instruction is represented in a lowlevel language corresponding to a single instruction for the processor. ( ADD X). A programmer typically used assembly language to write compilers and operating systems. c) High-level languages, slows programmers to use instructions that are more like human language such as C++, Java, Small Talk, Pascal,.. d) Application generators, these are database languages such as Oracle, Access. These languages allow user to create tables, store data, making reports and generate queries on these tables. 6 2.1.2 Compilers & Interpreters A compiler, is a program that translates the program written in high-level language into low-level instructions then executes it as a whole. An Interpreter, do the same job as a compiler, but it translates each instruction then execute it. 2.1.3 Operating System An Operating System (OS): is essentially the master controller for all of the activities that take place within a computer. It sets the standards for all application SW that a computer runs. "The most important systems program is the operating system. The operating system is always present when the computer is running. It coordinates the operation of all the hardware and software components of the computer system. The operating system is responsible for starting application programs running and finding the resources that they need. When an application program is running, the operating system manages the details of the hardware for it. For example, when you type characters on the keyboard, the operating system determines which application program they are intended for and does the work of getting them there. Modern operating systems usually come with a user interface that enables users to easily interact with application programs (and with the operating system itself) by using windows, buttons, menus, icons, the mouse, and the keyboard. Examples of operating systems are Unix, Windows 98, Windows NT, Linux. "1 7 How the OS works when you start a program: "When a computer is started up, the hardware will automatically load the operating system and start it running. This process is called booting. The reason for this odd term is that the operating system is itself involved in getting itself running---a process that is like someone "pulling themselves up by their bootstraps." Once the operating system is running, it is used to start up any other program. Here is a (simplified) list of what happens when the user (you) starts up an application. Assume that the operating system (OS) is already running. 1. The user asks to run an application. This could be done by clicking on an icon, making a menu choice, or other means. 2. The OS determines the name of the application. 3. The OS finds the section of the hard disk where the application program and its data are stored. 4. The OS finds an unused section of main memory that is large enough for the application. 5. The OS makes a copy of the application and its data in that section of main memory. The software on the hard disk is unchanged; a copy of it has been made in main memory 6. The OS sets up resources for the application. 7. Finally, the OS starts the application running. As the application runs, the OS is there in the background managing resources, doing input and output for the application, and keeping everything else running. "1 2.2 Application Software These are programs which users choose to work with such as word processing & Excel. 8 3. Writing a program In this module, you will learn how to write a program, and this implies the following stages: 1. Understand and analyse the problem, 2. write an algorithm to solve the problem, an algorithm is a method of solution described in a way can be carried out by a computer, it could be represented by : pseudo-code which is a mixture of English and a favorite programming language. Flowchart which is a graphical representation of the way computer should work to solve the problem. Examples are shown in the next page. 3. Write a program by converting the algorithm into an appropriate programming language (in this module Borland C), 4. compile the program to detect and fix syntax errors, 5. Test the program, by executing it with different data, to detect and fix any semantic errors and to be sure that it executes in all cases. 3.1 Programming models: Two well known styles of programming are: 1. The Procedural model, it includes a set of procedures and functions that is run sequentially, and ask a user to enter inputs. 2. Even-Driven model, is an action (event) happened such as key press or mouse click, to which a program might respond. In this model, a user control the execution, nothing will happened if a user do not do an event or an action. In both models, a programmer could write a re-usable code, which could be reused by other programs. In terms of a re-usable code, a programmer should be a ware of two parts: Specification, what a piece of code does. Implementation, how a piece of code achieve its purpose. The specification part is the one needed in terms of re-usable code, without any need to know how exactly it works. In C++, the implementation part is saved as .cpp file, and the specification is saved as a header file (.h), i.e, #|include <stdio.h>. 9 Examples of Pseudo-code and Flowchart: The pseudo-code of finding the area of a rectangle is as follows: Read the height of a triangle Read the width of a triangle Compute area as height times width 10