高级语言程序设计 chapter1.ppt

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

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

1、A First Book of ANSI CFourth Edition,Chapter 1 Introduction to Computer Programming,A First Book of ANSI C, Fourth Edition,2,Objectives,History and Hardware Programming Languages Algorithms The Software Development Process Case Study: Design and Development Common Programming Errors,A First Book of

2、ANSI C, Fourth Edition,3,History and Hardware,Babbages analytical engine (1822) Atanasoff-Berry Computer (ABC, 1937) Human operator manipulated external wiring Electrical Numerical Integrator and Computer (ENIAC, 1946) Vacuum tubes Mark I (1944) Mechanical relay switches Electronic Delayed Storage A

3、utomatic Computer (EDSAC, 1949) Incorporated a form of memory,A First Book of ANSI C, Fourth Edition,4,History and Hardware (continued),A First Book of ANSI C, Fourth Edition,5,Computer Hardware,Computers are constructed from physical components referred to as hardware Hardware facilitates the stora

4、ge and processing of data under the direction of a stored program Computer hardware does not store data using the same symbols that humans do,A First Book of ANSI C, Fourth Edition,6,Bits and Bytes,The smallest and most basic data item in a computer is a bit Open or closed switch 0 or 1 The grouping

5、 of 8 bits to form a larger unit is referred to as a byte Can represent any one of 256 distinct patterns The collections of patterns consisting of 0s and 1s used to represent letters, single digits, and other single characters are called character codes,A First Book of ANSI C, Fourth Edition,7,Compo

6、nents,A First Book of ANSI C, Fourth Edition,8,Main Memory Unit,Stores data and instructions as sequence of bytes A program must reside in main memory if it is to operate on the computer Combines 1 or more bytes into a single unit, referred to as a word Constructed as random access memory, or RAM Ev

7、ery section of memory can be accessed randomly as quickly as any other section Volatile: data is lost when power is turned off Size is usually specified in bytes (MB or GB),A First Book of ANSI C, Fourth Edition,9,Central Processing Unit (CPU),Control unit: directs and monitors the overall operation

8、 of the computer Keeps track of where the next instruction resides Issues the signals needed to both read data from and write data to other units in the system Executes all instructions Arithmetic and Logic Unit (ALU): performs all of the computations, such as addition, subtraction, comparisons, and

9、 so on, that a computer provides CPUs are constructed as a single microchip, which is referred to as a microprocessor,A First Book of ANSI C, Fourth Edition,10,Microprocessor,A First Book of ANSI C, Fourth Edition,11,Input/Output Unit,The input/output (I/O) unit provides access to the computer, allo

10、wing it to input and output data It is the interface to which peripheral devices, such as keyboards, console screens, and printers, are attached,A First Book of ANSI C, Fourth Edition,12,Secondary Storage,Used as permanent storage for programs and data Magnetic tape, magnetic disks, and CD-ROMs Dire

11、ct access storage device (DASD): allows a computer to read or write any one file or program independent of its position on the storage medium Magnetic hard disk consists of rigid platters that spin together on a common spindle Initially, the most common magnetic disk storage device was the removable

12、 floppy disk,A First Book of ANSI C, Fourth Edition,13,Magnetic Hard Disk,A First Book of ANSI C, Fourth Edition,14,Programming Languages,Computer program: data and instructions used to operate a computer and produce a specific result A program or set of programs is called software Programming: writ

13、ing instructions in a language that the computer can respond to and that other programmers can understand Programming language: set of instructions that can be used to construct a program,A First Book of ANSI C, Fourth Edition,15,Machine Language,Executable program: program that can operate a comput

14、er Executable programs are written with binary numbers, which is a computers internal language (machine language) An example of a simple machine language program containing two instructions is: 11000000000000000001000000000010 11110000000000000010000000000011 Opcode is short for operation code; tell

15、s the computer the operation to be performed,A First Book of ANSI C, Fourth Edition,16,Assembly Language,Assembly language: uses the substitution of word-like symbols for the opcodes, and decimal numbers and labels for memory addresses LOAD first ADD second MUL factor STORE answer,A First Book of AN

16、SI C, Fourth Edition,17,Assembly Language (continued),A First Book of ANSI C, Fourth Edition,18,Low- and High-Level Languages,Machine and assembly languages are low-level languages because they both use instructions that are directly tied to one type of computer Programs written in a computer langua

17、ge are referred to as source programs and source code When each statement in a high-level source program is translated individually and executed immediately upon translation, the programming language is called an interpreted language Interpreter: program that translates each statement in a high-leve

18、l source program and executes it immediately upon translation,A First Book of ANSI C, Fourth Edition,19,Low- and High-Level Languages (continued),Compiled language: the statements in a high-level source program are translated as a complete unit before any individual statement is executed Compiler: t

19、ranslates a high-level source program as a complete unit before any statement is executed The output produced by the compiler is called an object program (machine language version of the source code) Linker: combines additional machine language code with the object program to create a final executab

20、le program,A First Book of ANSI C, Fourth Edition,20,Low- and High-Level Languages (continued),A First Book of ANSI C, Fourth Edition,21,Procedural and Object-Oriented Languages,Procedural language: instructions are used to create self-contained units, called procedures Procedure: accepts data as in

21、put and transforms it in some manner to produce a specific result as output Also called function or method Procedures conforming to structure guidelines are known as structured procedures,A First Book of ANSI C, Fourth Edition,22,Procedural and Object-Oriented Languages (continued),Structured langua

22、ge: high-level procedural language (e.g., C) that enforces structured procedures Object-oriented languages: languages with object orientation such as C+, Java, Visual Basic, and C#,A First Book of ANSI C, Fourth Edition,23,Procedural and Object-Oriented Languages (continued),A First Book of ANSI C,

23、Fourth Edition,24,Application and System Software,Application software: programs written to perform particular tasks required by users System software: collection of programs that must be readily available to any computer system to enable the computer to operate The bootstrap loader is internally co

24、ntained in ROM and is a permanent, automatically executed component of the computers system software,A First Book of ANSI C, Fourth Edition,25,Application and System Software (continued),Operating system: set of system programs used to operate and control a computer Multiuser system: handles multipl

25、e users concurrently Operating systems that permit each user to run multiple programs are referred to as both multiprogrammed and multitasking systems,A First Book of ANSI C, Fourth Edition,26,The Development of C,Developed in the 1970s at AT&T Bell Laboratories by K. Thompson, D. Ritchie, and B. Ke

26、rnighan High-level structured language Can also access the internal hardware of a computer C permits a programmer to “see into” a computers memory and directly alter data stored in it Standard maintained by the American National Standards Institute (ANSI) In the 1980s, Bjarne Stroustrup (working at

27、AT&T) developed C+ C with object-oriented capabilities,A First Book of ANSI C, Fourth Edition,27,Algorithms,Algorithm: specific steps required to produce a desired result Set n equal to 100 Set a equal to 1 Set b equal to 100 Calculate sum = n(a+ b)/2 Display the sum When English phrases are used to

28、 describe an algorithm, the description is called pseudocode Input the three numbers into the computer Calculate the average by adding the numbers and dividing the sum by three Display the average,A First Book of ANSI C, Fourth Edition,28,Algorithms (continued),A First Book of ANSI C, Fourth Edition

29、,29,Algorithms (continued),When mathematical equations are used to describe an algorithm, the description is called a formula Flowchart: provides a pictorial representation of an algorithm using specifically defined shapes,A First Book of ANSI C, Fourth Edition,30,Algorithms (continued),A First Book

30、 of ANSI C, Fourth Edition,31,Algorithms (continued),A First Book of ANSI C, Fourth Edition,32,Algorithms (continued),Converting an algorithm into a computer program, using a language such as C, is called coding the algorithm The program instructions resulting from coding an algorithm are called pro

31、gram code, or simply code,A First Book of ANSI C, Fourth Edition,33,Algorithms (continued),A First Book of ANSI C, Fourth Edition,34,The Software Development Process,Each field of study has a name for the systematic method used to design solutions to problems In science: called the scientific method

32、 In engineering: called the systems approach The 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 development process,A First Book of ANSI C, Fourth Edition,35,

33、The Software Development Process (continued),A First Book of ANSI C, Fourth Edition,36,Phase I: Specify the Programs Requirements,Begins with a problem statement or a specific request for a program, which is called a program requirement Suppose you receive an e-mail from your supervisor that says: W

34、e need a program to provide information about circles This is not a clearly defined requirement To 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 outputs) and what data is to be provided (the inp

35、uts),A First Book of ANSI C, Fourth Edition,37,Phase II: Design and Development,Step 1: Analyze the problem. You must understand: The outputs that must be produced The input data required to create the desired outputs The formulas relating the inputs to the outputs Step 2: Select an overall solution

36、 algorithm,A First Book of ANSI C, Fourth Edition,38,Phase II: Design and Development (continued),A First Book of ANSI C, Fourth Edition,39,Phase II: Design and Development (continued),For larger programs you will have to refine the initial algorithm and organize it into smaller algorithms, with spe

37、cifications for how these smaller algorithms will interface with each other First-level structure diagram for an algorithm is the first attempt at a structure for a solution algorithm Top-down algorithm development starts at the topmost level and proceeds to develop more and more detailed algorithms

38、 as it proceeds to the final set of algorithms,A First Book of ANSI C, Fourth Edition,40,Phase II: Design and Development (continued),A First Book of ANSI C, Fourth Edition,41,Phase II: Design and Development (continued),A First Book of ANSI C, Fourth Edition,42,Phase II: Design and Development (con

39、tinued),Step 3: Write the program (or code the algorithm) Sequence structure defines the order in which instructions are executed by the program Selection structure provides the capability to make a choice between different instructions, depending on the result of some condition Repetition structure

40、, also called looping or iteration, provides the ability for the same operation to be repeated based on the value of a condition Invocation structure involves invoking specific sections of code as they are needed,A First Book of ANSI C, Fourth Edition,43,Phase II: Design and Development (continued),

41、Step 4: Test and correct the program A program error is called a bug Testing attempts to ensure that a program works correctly and produces meaningful results If you find an error, initiate debugging: locating, correcting, and verifying the correction Develop a set of test data that determines wheth

42、er the program gives correct answers The tests should examine every possible situation under which a program will be used,A First Book of ANSI C, Fourth Edition,44,Phase III: Documentation,Six documents for every problem solution: The requirements statement A description of the algorithms that were

43、coded Comments within the code itself A description of modification and changes made over time Sample test runs, which include the inputs used for each run and the output obtained from the run A users manual, which is a detailed explanation of how to use the program,A First Book of ANSI C, Fourth Ed

44、ition,45,Phase IV: Maintenance,How easily a program can be maintained (corrected, modified, or enhanced) is related to the ease with which the program can be read and understood,A First Book of ANSI C, Fourth Edition,46,Phase IV: Maintenance (continued),A First Book of ANSI C, Fourth Edition,47,Back

45、up,Making and keeping backup copies of your work when writing a program is critical Not part of the formal software development process Backup is unimportant if you dont mind starting all over again Many organizations keep at least one backup on site where it can be easily retrieved, and another bac

46、kup copy either in a fireproof safe or at a remote location,A First Book of ANSI C, Fourth Edition,48,Case Study: Design and Development,The 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

47、C program to calculate the circumference of a circle that has a 2-inch radius. Step 1: Analyze the problem Determine the desired outputs Determine the input items List the formulas relating the inputs to the outputs Perform a hand calculation,A First Book of ANSI C, Fourth Edition,49,Case Study: Des

48、ign and Development (continued),Step 2: Select an overall solution algorithm Set the radius value to 2 Calculate the circumference, C, using the formula C = 2 r Display the calculated value for C Step 3: Write the program (see next slide) Step 4: Test and correct the program The circumference of the

49、 circle is 12.566400 Because only one calculation is performed by the program, testing Program 1.1 really means verifying that the single output is correct,A First Book of ANSI C, Fourth Edition,50,Case Study: Design and Development (continued),A First Book of ANSI C, Fourth Edition,51,Common Programming Errors,Rushing to write and execute a program without spending sufficient time learning about the problem or designing an appropriate algorithm Forgetting to back up a program Not understanding that computers respond only to explicitly defined algorithms,A First Book of ANSI C, Fourth Editio

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1