chap01 - Chapter 1 Chapter An Overview of Computers and An...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 1 Chapter An Overview of Computers and An Programming Languages Programming Chapter Objectives Chapter Learn about different types of computers Explore the hardware and software Explore components of a computer system components Learn about the language of a computer Learn about the evolution of programming Learn languages languages Examine high-level programming languages Chapter Objectives Chapter Discover what a compiler is and what it does Examine how a Java program is processed Learn what an algorithm is and explore Learn problem-solving techniques problem-solving Become aware of structured and objectoriented programming design methodologies Introduction Introduction Computers have greatly effected our daily Computers lives – helping us complete many tasks lives Computer programs (software) are designed Computer specifically for each task specifically Software is created with programming Software languages languages Java is an example of a programming language An Overview of the History of Computers Computers 1950s: Very large devices available to a select 1950s: few 1960s: Large corporations owned computers 1970s: Computers get smaller and cheaper 1990s: Computers get cheaper and faster and 1990s: are found in most homes are Elements of a Computer System Elements A computer has 2 components Hardware Software Hardware Components of a Computer Computer Central Processing Unit (CPU) Main Memory Hardware Components of a Computer Computer Main Memory Main Ordered sequence of cells (memory cells) Directly connected to CPU All programs must be brought into main All memory before execution memory When power is turned off, everything in main When memory is lost memory Main Memory with 100 Storage Cells Cells Secondary Storage Secondary Provides permanent storage for information Examples of secondary storage: Hard Disks Floppy Disks ZIP Disks CD-ROMs Tapes Input Devices Input Definition: devices that feed data and Definition: computer programs into computers computer Examples: Keyboard Mouse Secondary Storage Output Devices Output Definition: devices that the computer uses to Definition: display results display Examples: Printer Monitor Secondary Storage Software Software Software consists of programs written to Software perform specific tasks perform Two types of programs System Programs Application Programs System Programs System System programs control the computer control The operating system is first to load when you The turn on a computer turn Operating System (OS) Operating OS monitors overall activity of the computer OS and provides services and Example services: memory management input/output activities storage management Application Programs Application Written using programming languages Perform a specific task Run by the OS Example programs: Word Processors Spreadsheets Games Language of a Computer Language Machine language: the most basic language of Machine a computer computer A sequence of 0s and 1s sequence Every computer directly understands its own Every machine language machine A bit is a binary digit, 0 or 1 A byte is a sequence of eight bits Evolution of Programming Languages Languages Early computers programmed in machine Early language language Assembly languages were developed to make Assembly programmer’s job easier programmer’s In assembly language, an instruction is an In easy-to-remember form called a mnemonic easy-to-remember Assembler: translates assembly language Assembler: instructions into machine language instructions Instructions in Assembly and Machine Language Machine Evolution of Programming Languages Languages High-level languages make programming easier easier Closer to spoken languages Examples: Basic Basic FORTRAN COBOL C/C++ Java Evolution of Programming Languages Languages To run a Java program: 1. Java instructions need to be translated into an Java intermediate language called bytecode intermediate 2. Then the bytecode is interpreted into a particular Then machine language Evolution of Programming Languages Languages Compiler: A program that translates a program Compiler: written in a high-level language into the equivalent machine language. (In the case of Java, this machine language is the bytecode.) Java, Java Virtual Machine (JVM) - hypothetical computer developed to make Java programs machine independent machine Processing a Java Program Processing Two types of Java programs: applications and applets Source program: Written in a high-level language Source Written Linker: Combines bytecode with other programs provided by the SDK and creates executable code the Loader: transfers executable code into main memory Interpreter: reads and translates each bytecode instruction into machine language and then executes it into Processing a Java Program Processing Problem-Solving Process Problem-Solving 1. State the Problem State 2. Analyze the problem: outline solution requirements 2. and design an algorithm and 3. Design an algorithm to solve the problem 4. Implement the algorithm in a programming language (Java) and verify that the algorithm works language 5. Maintain the program: use and modify if the problem domain changes problem Problem-Analysis-CodingProblem-Analysis-CodingExecution Cycle Algorithm: A step-by-step problem-solving Algorithm: process in which a solution is arrived at in a finite amount of time finite Algorithms Algorithms Definition of an Algorithm? What makes a good algorithm? Example © Janice Regan 2003 Janice Definition Definition An algorithm is Any set of instructions that specifies a series Any of steps to correctly solve the problem of There may be many different algorithms There to solve a given problem to Some algorithms may be more efficient Some than others than Algorithms and Programs Algorithms An algorithm is a finite set of instructions that An explains the required solution step-by-step explains A computer can be instructed to implement many computer algorithms with a finite number of steps or instructions instructions A program is a set of computer instructions that program implements an algorithm implements © Janice Regan 2003 Janice Why Should I Write Algorithms? Why A computer program solves a scientific computer programming problem with a computer programming a simulation problem, a data analysis simulation application, a control system, etc. application, To write a computer program you need to To know the series of steps your are implementing to solve your problem, You need to know your algorithm! need © Janice Regan 2003 Janice Important Important The sequence or order of the steps is usually of The critical importance in writing a correct algorithm critical You must be exact when specifying an algorithm that You is to be translated into a computer program is What is the difference between A*B+C and (A*B) +C? Be careful, the computer will do exactly what +C? you ask, even it is not what you really want it to do!! you © Janice Regan 2003 Janice Problem Solving Methodology and Algorithms Algorithms Problem Specification: State the problem clearly Analysis: Input, Output, How to go from input to Analysis: output Design: Develop a step by step method Test Plan: How do you test to determine your Test algorithm works algorithm Implementation or coding Testing Refinement Problem Specification I Problem Any problem solving process consists Any of Input Algorithm Output Determine what information is Determine available as input to your algorithm available Determine what information is desired Determine as output from your algorithm as © Janice Regan 2003 Janice Specification and Analysis Specification What needs to be done to the input to What determine the output? determine Determine a series of steps that will transform Determine the input data into the output results the Then enumerate all the special cases that the Then must be handled must If necessary modify or redesign your series of If steps to handle all special cases steps © Janice Regan 2003 Janice Verifying Algorithms Verifying You written your algorithm, is it ready to be You translated into a program? translated Verify that it gives the desired results. Verify that all special cases are handled Verify that the algorithm ends after the outputs are Verify determined determined You have a series of items to verify, you also have You made a good start on determining what tests need to be included in your test plan. to © Janice Regan 2003 Janice Summary: Writing Algorithms? Summary: You will succeed in writing algorithms if you First think about the problem, its input data and First required results (output) required Next determine a series of steps that will transform the Next input data into the output results input Then enumerate all the special cases that the must be Then handled handled If necessary modify or redesign your series of steps so If that all special cases are handled that Verify your algorithm © Janice Regan 2003 Janice Example: Problem Specification Example: You are spending the weekend with a group of You friends. Your contribution to making breakfast is making the coffee. The friend in charge of grocery shopping has told you the coffee is in the freezer. coffee Example: Analysis and Design Example: You see a coffee maker on the kitchen counter You with a box of coffee filters. with You might decide to subdivide the problem of You making the coffee into the following steps making Example: Algorithm Example: 1. 2. 3. 4. 5. 6. Take the coffee out of the freezer Put the coffee in a filter Put the filter in the coffee maker Put water in the coffee maker Turn on the coffee maker Put the rest of the coffee back in the freezer Example: refinement I Example: You look for the coffee in the freezer and You you find whole coffee beans. You know that you need ground coffee beans to make coffee. make Refinement of step 2 a) b) c) d) d) Find the coffee grinder Put the coffee beans into the grinder Grind the coffee beans Grind Put the ground coffee in the filter Example: refinement II Example: You need to decide when the coffee is You properly ground Refinement of step 2c a) Grind the coffee beans i. Stop grinding i. ii. Check to see if the coffee beans are properly Check ground ground iii. Continue grinding if they are not iv. Repeat until the coffee is properly ground Example: refinement III Example: What if you use the last of the coffee What and have none left to put back in the freezer? freezer? Refinement of step 6 1. If there are any coffee beans left put If them back in the freezer them Example: refined algorithm I Example: 1. Take the coffee out of the freezer 2. Put coffee in a filter a) b) c) c) d) Find the coffee grinder Put the coffee beans into the grinder Put Grind the coffee beans i. Stop grinding ii. Check to see if the coffee beans are properly Check ground ground iii. Continue grinding if they are not iv. Repeat until the coffee is properly ground Put the ground coffee in the filter Example: refined algorithm II Example: 1. 2. 3. 4. Put the filter in the coffee maker Put water in the coffee machine Turn on the coffee machine If there are any coffee beans left put the If rest of the coffee back in the freezer rest Choices Choices There may be several algorithms to solve a There given problem given Which algorithm is the best? How do we chose? Properties of Good Algorithms Properties Efficiency Simplicity Precision Effectiveness Generality Levels of Abstraction Correctness Finiteness Maintainability Class discussion Class Algorithm for solving a quadratic equation Problem-Analysis-CodingProblem-Analysis-CodingExecution Cycle Programming Methodologies Programming Two basic approaches to programming design: Structured design Structured Object-oriented design Structured Design Structured 1. A problem is divided into smaller problem subproblems subproblems 2. Each subproblem is solved 3. The solutions of all subproblems are then The combined to solve the problem combined Object-Oriented Design (OOD) Object-Oriented In OOD, a program is a collection of In interacting objects interacting An object consists of data and operations Steps in OOD: 1. 2. 3. Identify objects Form the basis of the solution Determine how these objects interact Chapter Summary Chapter A computer system is made up of hardware and computer software components software Computers understand machine language; it is easiest Computers for programmers to write in high-level languages for A compiler translates high-level language into compiler machine language machine High-level language steps to execute a program: edit, High-level compile, link, load, and execute compile, Chapter Summary Chapter Algorithm: step-by-step problem-solving Algorithm: process in which a solution is arrived at in a finite amount of time finite Three steps to problem solving: analyze the Three problem and design an algorithm, implement the algorithm in a programming language, and maintain the program maintain Two basic approaches to programming design: Two structured and object-oriented structured ...
View Full Document

This note was uploaded on 01/16/2010 for the course CMPT 101 taught by Professor Various during the Spring '03 term at Simon Fraser.

Ask a homework question - tutors are online