Chapter 1 Computer and Programming By Zerihun Alemayehu
What is computer? A device capable of performing computations and making logical decisions at speeds millions (even billions) of times faster than human beings can Computers process data under the control of sets of instructions called computer programs
CRT Display The Box CD-ROM Drive Keyboard Floppy Disk Drive Mouse
Input Devices
Output Devices
Memory unit RAM - Random Access Memory The main 'working' memory used by the computer. When the operating system loads from disk when you first switch on the computer, it is copied into RAM.
Arithmetic and logic unit (ALU) This unit is responsible for performing calculations + - x It contains the decision mechanisms that allow the computer, for example, to compare two items from the memory unit to determine whether they are equal.
Central processing unit (CPU) Coordinates and supervises the operation of the other sections
Secondary storage unit ROM Read Only Memory A special type of memory chip that holds software that can be read but not written to.
Printer Mouse Keyboard Modem Ports bus Disk controller Graphics card Monitor CPU Sound card Speakers RAM Network card Computer
Computer Memory All computers work on a binary numbering system, i.e. they process data in one's or zero's. This 1 or 0 level of storage is called a bit. Byte = 8 bits Kilobyte (KB) = 1024 bytes Megabyte (MB) = 1024 KB Gigabyte (GB) = 1024 MB
Binary number system 1 s place 10 s place 100 s place 1 s place 2 s place 4 s place (Base 10) 129 129= 1 x 10 0 + 2 x 10 1 + 9 x 10 2 101 (Base 2) 101= 1 x 2 0 + 0 x 2 1 + 1 x 2 2 n bits 2 n possible values 8 bits (1 byte) 256 values (-128 to 127) 16 bits (2 bytes) 65, 536 values 32 bits (4 bytes) 4, 294, 967, 296 values
Inside Computer
Computer Languages Machine languages (0s and 1s) Assemblers Assembly languages Compilers High level languages (FORTRAN, Basic, C, C++, Java, etc.)
History of FORTRAN FORTRAN (FORmula TRANslation): IMB 1950s FORTRAN II FORTRAN IV FORTRAN 66 FORTRAN 77 FORTRAN 90 FORTRAN 95 FORTRAN 2003
Programming An engineering problem solving methodology using computers consists of Problem Statement Input/Output Description Hand Example Algorithm Development Testing A solution to a problem is called an algorithm; it describes the sequence of steps to be performed for the problem to be solved.
Algorithm Problem 1: start your car Algorithm: 1. Insert the key. 2. Make sure the transmission is in Park (or Neutral). 3. Depress the gas pedal. 4. Turn the key to the start position. 5. If the engine starts within six seconds, release the key to the ignition position. 6. If the engine doesn't start in six seconds, release the key, wait ten seconds, and repeat steps 3 through 6, but not more than five times. 7. If the car doesn't start, call the garage.
The Four Phases Phase 1: Creating a Program Phases 2: Compiling Phase 3: Linking Phase 4: Execution Editing source code (.F90,.F95,.F) FORTRAN program machine language executable image Object code
Required Tools Hardware - Computer - Compiler - Paper & pencil Software - Knowledge - Creativity - Motivation
From problem to program 1. Specify the problem clearly 2. Analyse the problem and break it down into its fundamental elements 3. Code the program according to the plan developed at step 2 4. Test the program exhaustively, and repeat steps 2 and 3 as necessary until the program works correctly in all situations
Example 1. Problem Write a program that will ask the user the radius of a circle and which will calculate the area of the circle and then displays the area of the circle.
2. Steps to the solution Solution 1) Read the radius, r 2) Calculate the area of the circle using = πr 2 /4 3) Display the area of the circle
Solution 3. Write the program PROGRAM circle IMPLICIT NONE REAL :: r, area, pi = 3.414! Ask the user for the data PRINT*, please give the radius READ*, r area = pi * (r **2)/4!Display the result PRINT*, The area of the circle =, area END PROGRAM Circle!Calculate the area
Sources Compiler www.silverfrost.com/32/ftn95/ftn95_personal_edition.aspx Course notes aaucivil.wordpress.com/fortran