Programming Logic and Design Fourth Edition, Introductory[編程邏輯設(shè)計(jì)第四版介紹](-47)_第1頁
Programming Logic and Design Fourth Edition, Introductory[編程邏輯設(shè)計(jì)第四版介紹](-47)_第2頁
Programming Logic and Design Fourth Edition, Introductory[編程邏輯設(shè)計(jì)第四版介紹](-47)_第3頁
Programming Logic and Design Fourth Edition, Introductory[編程邏輯設(shè)計(jì)第四版介紹](-47)_第4頁
Programming Logic and Design Fourth Edition, Introductory[編程邏輯設(shè)計(jì)第四版介紹](-47)_第5頁
已閱讀5頁,還剩42頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、Programming Logic and Design Fourth Edition, IntroductoryChapter 4Designing and Writing a Complete Program1ObjectivesPlan the mainline logic for a complete programDescribe typical housekeeping tasksDescribe tasks typically performed in the main loop of a programDescribe tasks performed in the end-of

2、-job moduleUnderstand the need for good program design2Objectives (continued)Appreciated the advantages of storing program components in separate filesSelect superior variable and module namesDesign clear module statementsUnderstand the need for maintaining good programming habits3Understanding the

3、Mainline Logical Flow Through a ProgramUnderstand what the goals areAsk the user to clarify if necessary4Understanding the Mainline Logical Flow Through a Program (continued)Ensure you have all the data required to produce the desired output5Understanding the Mainline Logical Flow Through a Program

4、(continued)Understand the big picture first6Understanding the Mainline Logical Flow Through a Program (continued)Procedural program: one procedure follows another from beginning to endMainline logic has three distinct parts:Housekeeping: steps to get readyMain loop: instructions executed for every i

5、nput recordEnd-of-job: steps taken at end of programBreak the logic down into at least three modules7Understanding the Mainline Logical Flow Through a Program (continued)8Understanding the Mainline Logical Flow Through a Program (continued)Modularization of the program:Keeps the job manageableAllows

6、 multiple programmers to work simultaneouslyKeeps the program structured9Housekeeping TasksHousekeeping tasks: include all steps that occur at the beginning of the programDeclare variablesOpen filesPerform one-time-only tasks such as printing headingsRead the first input record 10Declaring Variables

7、Assign identifiers to memory locationsSpecify the name and data typeUse meaningful names and follow standardsPrefixes may be used to group related variablesDeclare a variable for each field in a data file11Declaring Variables (continued)12Declaring Variables (continued)Group name: Name for a group o

8、f associated variablesCan handle the entire group with a single instruction13Declaring Variables (continued)Initializing (or defining) the variable: providing an initial valueSome languages provide default initial valuesOther languages leave variables with an unknown or garbage valueVariables repres

9、enting data fields in files do not need to be initialized14Declaring Variables (continued)Can use variables for report headingsEmbed any required spaces Heading can be printed using these variables15Declaring Variables (continued)Every language provides methods for:Advancing the paper to top of page

10、Printing single, double, or triple spaced linesUse annotation symbol to show variables16Opening FilesSpecify file name and path (location)Issue a file open commandIf no input file is opened, input may be accepted from the standard input device (e.g., keyboard)You must open both input and output file

11、s to be used, including printer output deviceIf no output file is opened, standard output device (e.g., monitor) may be used17A One-Time-Only Task - Printing HeadingsPrinting headings for reports usually is done at beginning of the program18Reading the First Input RecordReading the first input recor

12、d is the last housekeeping taskInteractive application: Interacts with users via keyboard or mouse inputProgram pauses when the read command is executed until the user enters dataDelimiter: a character designated as a separator between data valuesPrompt: an output statement that asks the user to ent

13、er specific data19Reading the First Input Record (continued)Interactive input:20Reading the First Input Record (continued)Input from a data file:Input from a data file using a group name:21Checking for the End of the FileFirst task after housekeepingFor an interactive program, EOF may be determined

14、when:User enters a predetermined sentinel valueUser selects a screen option using a mouseFor input from a file, the input device recognizes EOFIf no data in the file, EOF occurs on the first readIf there is data, each record is processed before the next read occurs22Checking for End of File (continu

15、ed)23Checking for End of File (continued)24Checking for End of File (continued)25Checking for End of File (continued)Handling the report headings in a separate module:26Writing the Main LoopEach data record passes through the main loop onceInventory program main loop steps:Calculate the profit for a

16、n itemPrint the items information on the reportRead the next inventory record27Writing the Main Loop (continued)Must declare additional variables for calculation results28Writing the Main Loop (continued)29Writing the Main Loop (continued)Detail lines are printed one line at a time:Calculations can

17、be done within the print statement:Work variable (or work field): a variable used to temporarily hold a calculation30Performing End-of-Job TasksEnd-of-job tasks may include:Printing summaries or grand totalsPrinting “End of Report” messageClosing any open filesFooter line (or footer): end-of-job mes

18、sage line31Performing End-of-Job Tasks (continued)32Performing End-of-Job Tasks (continued)33Performing End-of-Job Tasks (continued)34Understanding the Need for Good Program DesignGood design is:Critical for very large programsNeeded to guarantee that components work together properlyWell-designed p

19、rogram modules should work:As stand-alone modules As part of larger systems35Storing Program Components in Separate FilesLarge programs may contain hundreds of variables and thousands of lines of codeManage lengthy programs by breaking into modulesMany languages allow program components to be stored

20、 in separate filesStoring components separately simplifies reuseAccessing modules from separate files is done with a statement like include, import, or copy36Storing Program Components in Separate Files (continued)37Storing Program Components in Separate Files (continued)Advantages of storing compon

21、ents separately:Simplifies reuseCan be provided in compiled form only, to hide detailsImplementation hiding: hiding details of how a program or module works38Selecting Variable and Module Names Using meaningful names:Improves code readabilityIs a form of self-documenting the programUse pronounceable

22、 namesCommonly used abbreviations are ok (e.g., SSN)Avoid digits in a name to avoid confusing:Zeros and OsOnes and lowercase Ls39Designing Clear Module StatementsFollow these rules:Select good identifier namesAvoid confusing line breaksUse temporary variables to clarify long statementsUse constants

23、where appropriate40Avoiding Confusing Line BreaksFree-form coding allows programmer to decide where to break lines of code41Using Temporary Variables to Clarify Long StatementsUse temporary variables to store intermediate results42Using Constants Where AppropriateNamed constant: a constant whose val

24、ue never changes during executionAdvantagesImproves code readabilityIf the value changes later, there is only one place in the code to make the changeUsually written with all uppercase lettersATHLETIC_FEETUITION_PER_CREDIT_HOUR43Using Constants Where Appropriate (continued)44Maintaining Good Programming HabitsProgram will be better written if you plan before you

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論