Presentation is loading. Please wait.

Presentation is loading. Please wait.

What is a Computer?  A computer is a device capable of performing computations and making logical decisions. It is a device for solving problems.  Some.

Similar presentations


Presentation on theme: "What is a Computer?  A computer is a device capable of performing computations and making logical decisions. It is a device for solving problems.  Some."— Presentation transcript:

1 What is a Computer?  A computer is a device capable of performing computations and making logical decisions. It is a device for solving problems.  Some of its advantages Fast Accurate Reliable  Computers process data under the control of sets of instructions called computer programs.  Programming is nothing more than telling a computer how to solve a specific problem. We can’t do this unless we know how to solve the problem.  Hardware: various devices comprising a computer  Software: programs that run a computer

2 Hardware Units  Hardware units in every computer: 1.Input unit  obtains information from input devices (keyboard, mouse) 2.Output unit  outputs information (to screen, to printer, to control other devices) 3.Central processing unit (CPU)  supervises and coordinates the other sections of the computer  Arithmetic and logic unit (ALU) performs arithmetic calculations and logic decisions 4.Memory unit  main memory: rapid access, low capacity, stores input information  Secondary storage unit: cheap, long-term, high- capacity storage, stores inactive programs

3 Computer Organization  CPU - central processing unit Where decisions are made, computations are performed, and input/output requests are delegated  Memory Stores information being processed by the CPU  Input devices Allows people to supply information to computers  Output devices Allows people to receive information from computers

4 Computer Organization

5 CPU  Brains of the computer Arithmetic calculations are performed using the Arithmetic/Logical Unit or ALU Control unit decodes and executes instructions  Arithmetic operations are performed using binary number system

6 Control Unit  The fetch/execute cycle is the steps the CPU takes to execute an instruction  Performing the action specified by an instruction is known as executing the instruction  The program counter (PC) holds the memory address of the next instruction

7 Input and Output Devices  Accessories that allow computer to perform specific tasks Receive information for processing Return the results of processing Store information  Common input and output devices SpeakersMouse Scanner PrinterJoystickCD-ROM KeyboardMicrophoneDVD  Some devices are capable of both input and output Floppy driveHard driveMagnetic tape units

8 Monitor  Display device that operates like a television Also known as CRT (cathode ray tube)  Controlled by an output device called a graphics card  Displayable area Measured in dots per inch, dots are often referred to as pixels (short for picture element) Standard resolution is 640 by 480 Many cards support resolution of 1280 by 1024 or better Number of colors supported varies from 16 to billions

9 RAM (memory) I/O Devices Central Processing Unit (CPU) Secondary Storage Registers Computer Architecture of a Computer

10 I/O Devices  Communications with the outside world.  Input devices: keyboard mouse joystick  Output devices: screen printer computer speakers RAM (memory) I/O Devices Central Processing Unit (CPU) Secondary Storage Registers Computer

11 RAM (memory) I/O Devices Central Processing Unit (CPU) Secondary Storage Registers Computer Central Processing Unit (CPU)  Execute the instructions of a program. Arithmetic operations comparison operations  Uses one or more registers as scratch space for storing numbers between instructions.  A typical CPU today can execute millions of arithmetic operations in a second.

12 Main Memory  Sometimes called random access memory (RAM).  Stores the numbers (data) that a program uses when it runs on the computer.  Also stores the instructions of the program that is running on the computer.  Divided into fixed size units of memory called words. each word stores one number RAM (memory) I/O Devices Central Processing Unit (CPU) Secondary Storage Registers Computer Data Program Instructions

13 Secondary Storage  Permanent storage used to save data and programs when they are not running on the computer.  Data and programs are organized into varying size units called files. each file has a unique name  Files are organized into directories that can contain subdirectories.  Think of secondary storage as a large electronic file cabinet containing folders with files in them. RAM (memory) I/O Devices Central Processing Unit (CPU) Secondary Storage Registers Computer

14  Application software Programs designed to perform specific tasks that are transparent to the user  System software Programs that support the execution and development of other programs Two major types  Operating systems  Translation systems Software

15 Application Software  Application software is the software that has made using computers indispensable and popular  Common application software Word processors Desktop publishing programs Spreadsheets Presentation managers Drawing programs  Learning how to develop application software is our focus

16  Examples Windows ®, UNIX ®, Mac OS X ®  Controls and manages the computing resources  Important services that an operating system provides File system  Directories, folders, files Commands that allow for manipulation of the file system  Sort, delete, copy Ability to perform input and output on a variety of devices Management of the running systems Operating System

17 Translation System  Set of programs used to develop software  A key component of a translation system is a translator  Some types of translators Compiler  Converts from one language to another Linker  Combines resources  Examples Microsoft Visual C++ ®, CBuilder ®, g++, Code Warrior ®  Performs compilation, linking, and other activities.

18 Software Development Activities  Editing  Compiling  Linking with precompiled files Object files Library modules  Loading and executing  Viewing the behavior of the program

19 Software Development Cycle

20 What is a program?  A computer is a general purpose machine, but is useless without a program  A program is a set of instructions that tells the computer what to do  The program turns the general purpose machine into a special purpose machine  Any piece of software is a program  Programming is nothing more than telling a computer how to solve a specific problem. We can’t do this unless we know how to solve the problem ourselves.

21 Software  Programming languages Three types of programming languages 1.Machine languages –strings of numbers giving machine specific instructions –Example: +1300042774 2.Assembly languages –English-like abbreviations representing elementary computer operations –Example: LOAD BASEPAY ADD OVERPAY STORE GROSSPAY 3. High-level languages similar to everyday English and use mathematical notations (translated via compilers) Example: GrossPay = basePay + overTimePay

22 Number Systems  You are familiar with the base 10 number system in which each digit of a number is multiplied by a power of 10. for example: 4325 = 4x10 3 + 3x10 2 + 2x10 1 + 5x10 0 for example: 103.23 = 1x10 2 + 0x10 1 + 3x10 0 + 2x10 -1 + 3x10 -2  Other number systems with a base different from 10 work in a similar fashion. base 8 number system: 521.4 8 = 5x8 2 + 2x8 1 + 1x8 0 + 4x8 -1 (337.5) base 2 number system: 101.1 2 = 1x2 2 + 0x2 1 + 1x2 0 + 1x2 -1 (5.5)  Two number systems are widely used in computers Binary: base 2 with digits 0 and 1 Hexadecimal: base 16 with digits 0, 1, 2, …, 9, A, B, C, D, E, F  12A4F 16 = 1x16 4 + 2x16 3 + 10x16 2 + 4x16 1 + 15x16 0 (76367)

23 Computer Number Systems  Binary number system a computer is composed of many electronic circuits at any particular time, each circuit has a current flowing through it or it doesn’t  hence the circuit is in one of two states (On| Off)  one state represents the digit 0 and the other represents 1  this is exactly what we need for base 2 (binary) numbers nearly all computers use the binary number system for numbers  Hexadecimal number system binary numbers require many digits to represent large numbers 4 consecutive binary digits represent the numbers from 0 to 15 this is exactly what we need for base 16 (hexadecimal) numbers using 4 consecutive binary digits to represent one hexadecimal digit provides a shortcut way to represent numbers as stored on a computer

24 Computer Number System Examples 10110101110001011001110011110110 binary number 11 5 12 5 9 12 15 6 B 5 C 5 9 C F 6 equivalent base 10 value for each group of 4 consecutive binary digits (bits) corresponding hexadecimal (base 16) digit B5C59CF6 equivalent hexadecimal number

25 Computer Main Memory  The main memory of a computer consists of many electronic circuits, each representing a single binary digit called a bit.  A group of eight consecutive bits forms a byte of memory.  A group of four consecutive bytes forms a word of memory. each word of memory represents one number a word of memory consists of 32 bits  Each byte of memory has a unique address starting from address 0. hence each word has an address that is a multiple of 4... 0 1 0 0 1 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 0 0 0 0 0 1... One Word of Main Memory 2350 16 2351 16 2352 16 2353 16

26 Representing Programs  In a computer instructions are written out ahead of time in the form of a program that is stored in the main memory of the computer along with the data (numbers) that the program needs.  The CPU of every computer has a simple machine language that it understands. instructions in this language are very simple the instructions are encoded as strings of bits each instruction takes one word of memory  The CPU executes the instructions in a program one by one performing whatever computation is specified by the program.

27 Machine Language Example Memory Address Instruction Comment --------- ------------- ----------------------------------------------- …….. 0001280120F340 Load number in word 0F340 into Register 2 00012C0420F348 Add number in word 0F348 to Register 2 0001301220F340 Store value in Register 2 in word 0F340 00013424200128 If Register 2 is positive jump to instruction 128... operation coderegistermemory address Operation Codes:01 = load 04 = add 12 = store 24 = compare to 0

28 Putting the Pieces Together  A machine language program is created and stored in secondary storage.  The program is loaded into memory to run under control of the CPU (and the operating system).  The CPU fetches instructions from memory one by one and executes them.  Execution of instructions may require reading / writing numbers in CPU registers and in memory  The CPU controls I/O devices which move data between memory and the outside world. RAM (memory) I/O Devices Central Processing Unit (CPU) Secondary Storage Registers Computer

29 Algorithms  An algorithm is a sequence of steps for solving a problem. It must be: complete unambiguous in terms that can be understood  Algorithms are coded in some programming language to form a program.  So the steps in using a computer are: understand the problem to be solved figure out how to solve it yourself develop an algorithm to solve the problem write a program to tell the computer how to solve the problem

30 Building Blocks Of An Algorithm  A computer is capable of doing only a few things and algorithms must be defined in terms of these “few things”  A computer can: add two numbers subtract two numbers multiply two numbers divide two numbers compare two numbers to determine which is bigger based on a comparison, jump to a different part of a program save a number in a word of memory or a register fetch a number from a word of memory or a register read data from an input device write data to an output device read and write data to secondary storage interpret numbers as characters (e.g., letters of the alphabet)

31 Compute the Sum and Product of Three Numbers  Assumptions compute the sum first and display it compute the product next and display it  Algorithm save the three numbers in three words of memory compute the sum of the three numbers display the computed sum compute the product of the three numbers display the computed product  We may need to refine this algorithm to add more details. put it in terms of the basic building block

32 Problem Solving  What are the inputs? domain & range? special cases?  What are the outputs? domain & range? special cases?  How are outputs related to inputs?  Other questions What is the general case of the problem? Have I solved this problem or a similar problem before? Has someone solved this problem or a similar problem before?

33 Example  Problem: Solve quadratic equations A*x 2 +B*x + C = 0.0  Analysis general case 2 real or imaginary roots special cases a, b and/or c = 0.0  Applicable algorithm -B + √(B 2 -4AC) or -B - √(B2-4AC) 2*A

34 Quadratic Equation Case Analysis  A*x 2 +B*x + C = 0.0 B = 0 C = 0 B ≠ 0 C = 0 B = 0 C ≠ 0 B ≠ 0 C ≠ 0 A = 0∞ roots one real root Bx = 0 one real root C = 0 one real root B*x + C = 0 A ≠ 0 Two real roots Ax 2 = 0 Two real roots Ax 2 +Bx = 0 Two roots Ax 2 + C = 0 Two roots Ax 2 +Bx+C = 0

35 Design by Stepwise Refinement  Start with the whole problem  Subdivide problem into several separate subparts e.g. input, compute, output  Decide how to represent data and carry it between subparts  Subdivide each subpart into simpler subsubparts  Continue subdividing until sub*parts are small  Combine sub*parts to make complete program

36 Refined Algorithm to Compute Sum and Product  Algorithm -- second attempt save the three numbers in three words of memory  get a number from an input device and save the number in memory word 1  get a number from an input device and save the number in memory word 2  get a number from an input device and save the number in memory word 3 compute the sum of the three numbers  fetch the number from memory word 1 into register 1  add the number in memory word 2 to the number in register 1, putting the sum in register 1  add the number in memory word 3 to the number in register 1, putting the sum in register 1

37 Refined Algorithm (continued)  Algorithm -- second attempt (continued) display the computed sum  write the number in register 1 to an output device compute the product of the three numbers  fetch the number in memory word 1 into register 1  multiply the number in memory word 2 by the number in register 1, putting the result in register 1  multiply the number in memory word 3 by the number in register 1, putting the result in register 1 display the computed product  write the number in register 1 to an output device  This iterative process is the easiest way to develop an algorithm. each iteration provides more detail called “stepwise refinement”

38 Largest Number in a List  Assumptions the list will have 5 numbers in it in random order  Algorithm -- first attempt save the five numbers from the list in five words of memory determine the largest of the five numbers display the number selected as the largest  We must refine this algorithm to put it in terms of the basic building blocks.  Notice that it will be necessary to save the number determined to be the largest number between steps 2 and 3.

39 Largest Number in a List (continued)  Algorithm -- second attempt save the five numbers from the list in five words of memory  read a number from an input device and save the number in memory word 1  do these same step using memory word 2  do these same step using memory word 3  do these same step using memory word 4  do these same step using memory word 5 determine the largest of the five numbers  fetch the number is memory word 1 into register 1  compare the number in memory word 2 with the number in register 1, putting the larger in register 1  compare the number in memory word 3 with the number in register 1, putting the larger in register 1

40 Largest Number in a List (continued)  Algorithm -- second attempt (continued) determine the largest of the five numbers (continued)  compare the number in memory word 4 with the number in register 1, putting the larger in register 1  compare the number in memory word 5 with the number in register 1, putting the larger in register 1 display the number selected as the largest  write the number in register 1 to an output device  These steps are close enough to the basic building blocks for algorithms that we will do no more refinement.

41 Homework Problem  From Kilometers to Miles  Write an Algorithm to convert a distance in kilometers to a distance in miles.  What is the input? What its type?  What is the expected output?

42 The Programming Process  Use an editor to create a program file (source file). contains the text of the program  Use a compiler to convert the source file into a machine code file (object file). convert from “English” to binary with machine operations  Use a linker to convert the object file into an executable file. include other machine code that the program requires  Run the executable file.  Iterate from any point as needed. Editor Program.cpp Compiler Program.obj Libraries Linker Program.exe Run the Program Done success errors

43 IDEs  Integrated Development Environments or IDEs Supports the entire software development cycle  E.g., MS Visual C++, Borland, Code Warrior  Provides all the capabilities for developing software Editor Compiler Linker Loader Debugger Viewer


Download ppt "What is a Computer?  A computer is a device capable of performing computations and making logical decisions. It is a device for solving problems.  Some."

Similar presentations


Ads by Google