Transcription

J. P. Cohoon and J. W. Davidson 1999 McGraw-Hill, Inc.Introduction to Programming andObject-Oriented DesignBasics of machine, software, andprogram design

Ch 1 / Foil 2Computer Organization Every computer is organized roughly into four parts 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

Ch 1 / Foil 3Computer OrganizationMemoryOutputDevicesInputDevicesCPU

Ch 1 / Foil 4CPU “Brains” of the computer Arithmetic calculations are performed using theArithmetic/Logical Unit or ALU Control unit decodes and executes instructionsArithmetic operations are performed using binary number system

Ch 1 / Foil 5CPU Fundamental building block is a switch Switches are made from ultrasmall transistorsExample -- Pentium II

Ch 1 / Foil 6Binary Arithmetic The individual digits of a binary number are referred to as bits Each bit represents a power of twoExamples401011 0 2 1 23 0 22 1 21 1 20 1100010 0 24 0 23 0 22 1 21 0 20 Binaryaddition00010 01011011012 11132Equivalentdecimaladdition

Ch 1 / Foil 7Binary ArithmeticBinarymultiplication0101 001101010101000000000001111Equivalent decimalmultiplication5 315

Ch 1 / Foil 8Two’s Complement Convention for handling signed numbers in binary representation The leading bit is a sign bit– Binary number with leading 0 is positive– Binary number with leading 1 is negativeMagnitude of positive numbers is just the binary representationMagnitude of negative numbers is found by performing the two’scomplement Complement the bits– Replace all the 1's with 0's, and all the 0's with 1's Add one to the complemented numberCarry in most significant bit position is thrown away whenperforming arithmetic

Ch 1 / Foil 9Two's Complement Example Performing two's complement on the decimal 7 to get -7 Using a five-bit representation7 00111 Convert to binary11000 Complement the bits11000 Add 1 to the complement 0000111001 Is -7 in two's complement

Ch 1 / Foil 10Two's Complement Arithmetic Computing 8 - 7 using a two's complement representation withfive-bit numbers8 - 7 8 (-7) 101000 Two's complement of 811001 Two's complement of -7Throw away thehigh-ordercarry as we areusing a five bitrepresentation01000 Add 8 and -7 1100110000100001 Is the five-bit result

Ch 1 / Foil 11Control Unit The fetch/execute cycle isthe steps the CPU takes toexecute an instructionPerforming the actionspecified by an instruction isknown as “executing theinstruction”The program counter (PC)holds the memory address ofthe next instructionFetch the instruction towhich the PC pointsIncrement the PCExecute the fetchedinstruction

Ch 1 / Foil 12Input and Output Devices Accessories that allow computer to perform specific tasks Receiving information for processing Return the results of processing Store informationCommon input and output devices SpeakersMouseScanner PrinterJoystickCD-ROM KeyboardMicrophoneSome devices are capable of both input and output Floppy drive Hard drive Magnetic tape units

Ch 1 / Foil 13Monitor Display deviceAlso known as CRT (cathode ray tube)Operates like a televisionControlled by an output device called a “graphics card”

Ch 1 / Foil 14Monitor and Card Characteristics Refresh rate12801024pixels How fast image ispixelsacrossupdated on the screendownscreenscreenResolution Displayable area– Measured in dots per inch, dotsare often referred to as pixels (short for picture element) Standard resolution is 640 by 480 Some cards support resolution up to 1280 by 1024Number of colors supported

Ch 1 / Foil 15Software Application software Programs designed to perform specific tasks that aretransparent to the userSystem software Programs that support the execution and development ofother programs Two major types– Operating systems– Translation systems

Ch 1 / Foil 16Application Software Application software is the software that has made usingcomputers indispensable and popularCommon application software Word processors Desktop publishing programs Spreadsheets Presentation managers Drawing programsLearning how to develop applicationsoftware is our focus

Ch 1 / Foil 17Operating System Controls and manages the computing resourcesImportant 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 systemsExamples MSDOS , Windows , UNIX

Ch 1 / Foil 18Translation System Set of programs used to develop softwareA key component of a translation system is a translatorTypes of translators Compiler Converts from one language to another Linker Combines resourcesExamples Borland C , Microsoft Visual C , g , Code Warrior – Performs compilation, linking, and other activities.

Ch 1 / Foil 19Software Development Major activities Editing Compiling Linking with precompiled files– Object files– Library modules Loading and executing Viewing the behavior of the program

Ch 1 / Foil 20Software Development CycleSource ProgramCompileLibrary routinesEditLinkOther object filesThinkLoadExecute

Ch 1 / Foil 21IDEs Integrated Development Environments or IDEs Translation systems that support the entire softwaredevelopment cycle– E.g., Borland, MS Visual C , Code WarriorCombine all of the capabilities that a programmer would wanthandy while developing software Editor Compiler Linker Loader Debugger Viewer

Ch 1 / Foil 22Engineering Software Software engineering Area of computer science concerned with building largesoftware systemsChallenge Tremendous advances in hardware have not beenaccompanied by comparable advances in software

Ch 1 / Foil 23Complexity Trade-off System complexity tends to grow as the system becomes moreuser friendlyHighTotal SoftwareComplexityComplexityUser SimplicityLow

Ch 1 / Foil 24Software Engineering Goals Reliability An unreliable life-critical system can be fatalUnderstandability Future development becomes very difficult if software is hardto understandCost Effectiveness Cost to develop and maintain should not exceed profitAdaptability System that is adaptive is easier to alter and expandReusability Improves reliability and maintainability, and reducesdevelopment costs

Ch 1 / Foil 25Software Engineering Principles Abstraction Extract the relevant properties of an object while ignoringinessential detailsEncapsulation Breaking down an object into parts, hiding and protecting itsessential information, and supplying an interface to modifythe information in a controlled and useful mannerModularity Dividing an object into smaller pieces or modules such thatthe object is easier to understand and manipulateHierarchy Ranking or ordering of objects based on some relationshipbetween them

Ch 1 / Foil 26Abstraction Process of extracting only the relevant properties of an objectExtracted properties define a view of the objectExample Car dealer views a car from selling features standpoint– E.g., price, length of warranty, color, optional equipment Mechanic views a car from systems maintenance standpoint– E.g., type of oil, size of the oil filter, type of spark plugsPrice?Oil change?

Ch 1 / Foil 27Encapsulation Breaking down an object into parts, hiding and protecting itsessential information, and supplying an interface to modify theinformation in a controlled and useful mannerBy hiding the information its representation and content can bechanged without affecting otherRadioparts of the systemExample - car radio Interface consists of thePowercontrols and types ofAntennaConnectorconnectors forInputconnecting the radio to the carSpeaker The details of how it works is hiddenConnectors To install and use a radio, we do notneed to know anything about the radio’s electrical system

Ch 1 / Foil 28Modularity Dividing an object into smaller pieces or modules such that themodules hold useful information and the object is easier tounderstand and manipulateMost complex systems are modularExample - Automobile can be decomposed into subsystems Cooling system Ignition system– Radiator– Battery– Thermostat– Starter– Spark plugs– Water pump

Ch 1 / Foil 29Hierarchy Ranking or ordering of objects based on some relationshipbetween themHierarchies help us understand complex systems Example - a company hierarchy helps employeesunderstand the company and their positions within itFor complex systems, a useful way of ordering similarabstractions is from least general to most general Scientists use this technique to identify and classify speciesHierarchical ordering basedon natural relationships iscalled a taxonomy

Ch 1 / Foil 30Northern Timber Wolf TaxonomyKingdom AnimaliaSubkingdom MetaozaPhylum ChordataSubphylum VertabrataSuperclass TetrapodaClass MammaliaSubclass TheriaInfraclass EutheriaCohort FerungulataSuperorder FeraeOrder CarnivoraSuborder FissipedaSuperfamily CanoideaFamily CaninaeSubfamily CaninaeGenus CanisSubspecies Canis lupus occidentalis(Northern Timber Wolf)

Ch 1 / Foil 31OO Design and Programming Object-oriented (OO) design and programming is a methodologythat supports good software engineeringObject-oriented design promotes thinking about software in away that models the way we think and interact with the real worldExample - watching television The remote is a physical objectwith properties– Weight, size, can sendmessages to the television The television is also a physicalobject with various properties

Ch 1 / Foil 32Objects An object is almost anything that can be attributed with thefollowing characteristics Name Properties The ability to act upon receiving a message– Basic message types Directive to perform an action Request to change one of its properties

Ch 1 / Foil 33Object-Oriented Programming Example Sketch the design of a simple computer game called BugHunt– Goal of game is to eliminate the bugs on the screen Features of game– A moving bug is displayed in a window on the screen– The bug changes directions randomly– A bug is eliminated by “swatting” it several times– If a bug is eliminated, a faster one pops up– If an attempted swat misses the bug, the game ends

Ch 1 / Foil 34Object-Oriented Programming First step Determine the objects– Mouse– Window– Bug

Ch 1 / Foil 35Bug Hunt To implement Bug Hunt, abug needs the followingproperties Position in the window A display image or picture Current speed Current direction Strength (the number ofswats it takes to eliminatethe bug)Other possibledirectionsCurrentdirection

Ch 1 / Foil 36Bug Hunt A bug needs to handle thefollowing messages Draw Move Change direction Hit Kill Is-pointed-atYes or NoResponseIs PointedAt?GameControllerMouseClickMouse

Ch 1 / Foil 37Bug engthPosition: 9,2.2Image:Speed: 4Direction: LeftStrength: 4Set DirectionHitKillIs pointed atPosition: 5,3.8Image:Speed: 2Direction: RightStrength: 2The bugclassBug objectswithparticularproperties

Ch 1 / Foil ted HitStrengthKillDirectionIsPointed Atis aSlowBugMessagesMoveMessagesinherited bydescendantsis aFastBugMessagesMove