高级语言程序设计chapter1

上传人:人*** 文档编号:587213826 上传时间:2024-09-05 格式:PPT 页数:54 大小:1.58MB
返回 下载 相关 举报
高级语言程序设计chapter1_第1页
第1页 / 共54页
高级语言程序设计chapter1_第2页
第2页 / 共54页
高级语言程序设计chapter1_第3页
第3页 / 共54页
高级语言程序设计chapter1_第4页
第4页 / 共54页
高级语言程序设计chapter1_第5页
第5页 / 共54页
点击查看更多>>
资源描述

《高级语言程序设计chapter1》由会员分享,可在线阅读,更多相关《高级语言程序设计chapter1(54页珍藏版)》请在金锄头文库上搜索。

1、A First Book of ANSI CFourth EditionChapter 1Introduction to Computer ProgrammingObjectivesHistory and HardwareProgramming LanguagesAlgorithmsThe Software Development ProcessCase Study: Design and DevelopmentCommon Programming Errors2A First Book of ANSI C, Fourth EditionHistory and HardwareBabbages

2、 analytical engine (1822)Atanasoff-Berry Computer (ABC, 1937)Human operator manipulated external wiringElectrical Numerical Integrator and Computer (ENIAC, 1946)Vacuum tubesMark I (1944)Mechanical relay switchesElectronic Delayed Storage Automatic Computer (EDSAC, 1949)Incorporated a form of memory3

3、A First Book of ANSI C, Fourth EditionHistory and Hardware (continued)4A First Book of ANSI C, Fourth EditionComputer HardwareComputers are constructed from physical components referred to as hardwareHardware facilitates the storage and processing of data under the direction of a stored programCompu

4、ter hardware does not store data using the same symbols that humans do5A First Book of ANSI C, Fourth EditionBits and BytesThe smallest and most basic data item in a computer is a bitOpen or closed switch0 or 1The grouping of 8 bits to form a larger unit is referred to as a byteCan represent any one

5、 of 256 distinct patternsThe collections of patterns consisting of 0s and 1s used to represent letters, single digits, and other single characters are called character codes6A First Book of ANSI C, Fourth EditionComponents7A First Book of ANSI C, Fourth EditionMain Memory UnitStores data and instruc

6、tions as sequence of bytesA program must reside in main memory if it is to operate on the computerCombines 1 or more bytes into a single unit, referred to as a wordConstructed as random access memory, or RAMEvery section of memory can be accessed randomly as quickly as any other sectionVolatile: dat

7、a is lost when power is turned offSize is usually specified in bytes (MB or GB)8A First Book of ANSI C, Fourth EditionCentral Processing Unit (CPU)Control unit: directs and monitors the overall operation of the computerKeeps track of where the next instruction residesIssues the signals needed to bot

8、h read data from and write data to other units in the systemExecutes all instructionsArithmetic and Logic Unit (ALU): performs all of the computations, such as addition, subtraction, comparisons, and so on, that a computer providesCPUs are constructed as a single microchip, which is referred to as a

9、 microprocessor9A First Book of ANSI C, Fourth EditionMicroprocessor10A First Book of ANSI C, Fourth EditionInput/Output UnitThe input/output (I/O) unit provides access to the computer, allowing it to input and output dataIt is the interface to which peripheral devices, such as keyboards, console sc

10、reens, and printers, are attached11A First Book of ANSI C, Fourth EditionSecondary StorageUsed as permanent storage for programs and dataMagnetic tape, magnetic disks, and CD-ROMsDirect access storage device (DASD): allows a computer to read or write any one file or program independent of its positi

11、on on the storage mediumMagnetic hard disk consists of rigid platters that spin together on a common spindleInitially, the most common magnetic disk storage device was the removable floppy disk12A First Book of ANSI C, Fourth EditionMagnetic Hard Disk13A First Book of ANSI C, Fourth EditionProgrammi

12、ng LanguagesComputer program: data and instructions used to operate a computer and produce a specific resultA program or set of programs is called softwareProgramming: writing instructions in a language that the computer can respond to and that other programmers can understandProgramming language: s

13、et of instructions that can be used to construct a program14A First Book of ANSI C, Fourth EditionMachine LanguageExecutable program: program that can operate a computerExecutable programs are written with binary numbers, which is a computers internal language (machine language)An example of a simpl

14、e machine language program containing two instructions is:1100000000000000000100000000001011110000000000000010000000000011Opcode is short for operation code; tells the computer the operation to be performed15A First Book of ANSI C, Fourth EditionAssembly LanguageAssembly language: uses the substitut

15、ion of word-like symbols for the opcodes, and decimal numbers and labels for memory addresses LOAD firstADD secondMUL factorSTORE answer16A First Book of ANSI C, Fourth EditionAssembly Language (continued)17A First Book of ANSI C, Fourth EditionLow- and High-Level LanguagesMachine and assembly langu

16、ages are low-level languages because they both use instructions that are directly tied to one type of computerPrograms written in a computer language are referred to as source programs and source codeWhen each statement in a high-level source program is translated individually and executed immediate

17、ly upon translation, the programming language is called an interpreted languageInterpreter: program that translates each statement in a high-level source program and executes it immediately upon translation18A First Book of ANSI C, Fourth EditionLow- and High-Level Languages (continued)Compiled lang

18、uage: the statements in a high-level source program are translated as a complete unit before any individual statement is executedCompiler: translates a high-level source program as a complete unit before any statement is executedThe output produced by the compiler is called an object program (machin

19、e language version of the source code)Linker: combines additional machine language code with the object program to create a final executable program19A First Book of ANSI C, Fourth EditionLow- and High-Level Languages (continued)20A First Book of ANSI C, Fourth EditionProcedural and Object-Oriented

20、LanguagesProcedural language: instructions are used to create self-contained units, called proceduresProcedure: accepts data as input and transforms it in some manner to produce a specific result as outputAlso called function or methodProcedures conforming to structure guidelines are known as struct

21、ured procedures21A First Book of ANSI C, Fourth EditionProcedural and Object-Oriented Languages (continued)Structured language: high-level procedural language (e.g., C) that enforces structured proceduresObject-oriented languages: languages with object orientation such as C+, Java, Visual Basic, and

22、 C#22A First Book of ANSI C, Fourth EditionProcedural and Object-Oriented Languages (continued)23A First Book of ANSI C, Fourth EditionApplication and System SoftwareApplication software: programs written to perform particular tasks required by usersSystem software: collection of programs that must

23、be readily available to any computer system to enable the computer to operateThe bootstrap loader is internally contained in ROM and is a permanent, automatically executed component of the computers system software24A First Book of ANSI C, Fourth EditionApplication and System Software (continued)Ope

24、rating system: set of system programs used to operate and control a computerMultiuser system: handles multiple users concurrentlyOperating systems that permit each user to run multiple programs are referred to as both multiprogrammed and multitasking systems25A First Book of ANSI C, Fourth EditionTh

25、e Development of CDeveloped in the 1970s at AT&T Bell Laboratories by K. Thompson, D. Ritchie, and B. KernighanHigh-level structured languageCan also access the internal hardware of a computerC permits a programmer to “see into” a computers memory and directly alter data stored in itStandard maintai

26、ned by the American National Standards Institute (ANSI)In the 1980s, Bjarne Stroustrup (working at AT&T) developed C+C with object-oriented capabilities26A First Book of ANSI C, Fourth EditionAlgorithmsAlgorithm: specific steps required to produce a desired resultSet n equal to 100Set a equal to 1Se

27、t b equal to 100Calculate sum = n(a+ b)/2Display the sumWhen English phrases are used to describe an algorithm, the description is called pseudocodeInput the three numbers into the computerCalculate the average by adding the numbers and dividing the sum by threeDisplay the average27A First Book of A

28、NSI C, Fourth EditionAlgorithms (continued)28A First Book of ANSI C, Fourth EditionAlgorithms (continued)When mathematical equations are used to describe an algorithm, the description is called a formulaFlowchart: provides a pictorial representation of an algorithm using specifically defined shapes2

29、9A First Book of ANSI C, Fourth EditionAlgorithms (continued)30A First Book of ANSI C, Fourth EditionAlgorithms (continued)31A First Book of ANSI C, Fourth EditionAlgorithms (continued)Converting an algorithm into a computer program, using a language such as C, is called coding the algorithmThe prog

30、ram instructions resulting from coding an algorithm are called program code, or simply code32A First Book of ANSI C, Fourth EditionAlgorithms (continued)33A First Book of ANSI C, Fourth EditionThe Software Development ProcessEach field of study has a name for the systematic method used to design sol

31、utions to problemsIn science: called the scientific methodIn engineering: called the systems approachThe technique used by professional software developers for understanding the problem that is being solved and for creating an effective and appropriate software solution is called the software develo

32、pment process34A First Book of ANSI C, Fourth EditionThe Software Development Process (continued)35A First Book of ANSI C, Fourth EditionPhase I: Specify the Programs RequirementsBegins with a problem statement or a specific request for a program, which is called a program requirementSuppose you rec

33、eive an e-mail from your supervisor that says: We need a program to provide information about circlesThis is not a clearly defined requirementTo clarify and define the problem statement, your first step would be to contact your supervisor to define exactly what information is to be produced (its out

34、puts) and what data is to be provided (the inputs)36A First Book of ANSI C, Fourth EditionPhase II: Design and DevelopmentStep 1: Analyze the problem. You must understand:The outputs that must be producedThe input data required to create the desired outputsThe formulas relating the inputs to the out

35、putsStep 2: Select an overall solution algorithm37A First Book of ANSI C, Fourth EditionPhase II: Design and Development (continued)38A First Book of ANSI C, Fourth EditionPhase II: Design and Development (continued)For larger programs you will have to refine the initial algorithm and organize it in

36、to smaller algorithms, with specifications for how these smaller algorithms will interface with each otherFirst-level structure diagram for an algorithm is the first attempt at a structure for a solution algorithmTop-down algorithm development starts at the topmost level and proceeds to develop more

37、 and more detailed algorithms as it proceeds to the final set of algorithms39A First Book of ANSI C, Fourth EditionPhase II: Design and Development (continued)40A First Book of ANSI C, Fourth EditionPhase II: Design and Development (continued)41A First Book of ANSI C, Fourth EditionPhase II: Design

38、and Development (continued)Step 3: Write the program (or code the algorithm)Sequence structure defines the order in which instructions are executed by the programSelection structure provides the capability to make a choice between different instructions, depending on the result of some conditionRepe

39、tition structure, also called looping or iteration, provides the ability for the same operation to be repeated based on the value of a conditionInvocation structure involves invoking specific sections of code as they are needed42A First Book of ANSI C, Fourth EditionPhase II: Design and Development

40、(continued)Step 4: Test and correct the programA program error is called a bugTesting attempts to ensure that a program works correctly and produces meaningful resultsIf you find an error, initiate debugging: locating, correcting, and verifying the correctionDevelop a set of test data that determine

41、s whether the program gives correct answersThe tests should examine every possible situation under which a program will be used43A First Book of ANSI C, Fourth EditionPhase III: DocumentationSix documents for every problem solution:1.The requirements statement2.A description of the algorithms that w

42、ere coded3.Comments within the code itself4.A description of modification and changes made over time5.Sample test runs, which include the inputs used for each run and the output obtained from the run6.A users manual, which is a detailed explanation of how to use the program44A First Book of ANSI C,

43、Fourth EditionPhase IV: MaintenanceHow easily a program can be maintained (corrected, modified, or enhanced) is related to the ease with which the program can be read and understood45A First Book of ANSI C, Fourth EditionPhase IV: Maintenance (continued)46A First Book of ANSI C, Fourth EditionBackup

44、Making and keeping backup copies of your work when writing a program is criticalNot part of the formal software development processBackup is unimportant if you dont mind starting all over againMany organizations keep at least one backup on site where it can be easily retrieved, and another backup co

45、py either in a fireproof safe or at a remote location47A First Book of ANSI C, Fourth EditionCase Study: Design and DevelopmentThe circumference, C, of a circle is given by the formula C = 2r, where is the constant 3.1416, and r is the radius of the circle. Using this information, write a C program

46、to calculate the circumference of a circle that has a 2-inch radius.Step 1: Analyze the problemDetermine the desired outputsDetermine the input itemsList the formulas relating the inputs to the outputsPerform a hand calculation48A First Book of ANSI C, Fourth EditionCase Study: Design and Developmen

47、t (continued)Step 2: Select an overall solution algorithmSet the radius value to 2Calculate the circumference, C, using the formula C = 2 rDisplay the calculated value for CStep 3: Write the program (see next slide)Step 4: Test and correct the programThe circumference of the circle is 12.566400Becau

48、se only one calculation is performed by the program, testing Program 1.1 really means verifying that the single output is correct49A First Book of ANSI C, Fourth EditionCase Study: Design and Development (continued)50A First Book of ANSI C, Fourth EditionCommon Programming ErrorsRushing to write and

49、 execute a program without spending sufficient time learning about the problem or designing an appropriate algorithmForgetting to back up a programNot understanding that computers respond only to explicitly defined algorithms51A First Book of ANSI C, Fourth EditionSummaryThe first attempt at creatin

50、g a self-operating computational machine was by Charles Babbage in 1822The physical components used in constructing a computer are called hardwareThe programs used to operate a computer are referred to as softwareProgramming languages come in a variety of forms and typesCompiler and interpreter lang

51、uages are referred to as high-level languages52A First Book of ANSI C, Fourth EditionSummary (continued)Algorithm: step-by-step sequence of instructions that must terminate and describes how to perform an operation to produce a desired outputThe software development procedure consists of the followi

52、ng four phases:Specification of the programs requirementsDesign and developmentDocumentationMaintenance53A First Book of ANSI C, Fourth EditionSummary (continued)Steps of the design and development phase are:Analyze the problemSelect an overall solution algorithmWrite the programTest and correct the programWriting a program consists of translating the solution algorithm into a computer languageFundamental programming control structuresSequence, selection, iteration and invocationYou always need at least one backup of a program54A First Book of ANSI C, Fourth Edition

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 医学/心理学 > 基础医学

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号