C语言数据结构设计1._第1页
C语言数据结构设计1._第2页
C语言数据结构设计1._第3页
C语言数据结构设计1._第4页
C语言数据结构设计1._第5页
免费预览已结束,剩余6页可下载查看

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Cha pter 1 P ROGRAMMING P RINC IP LES1.1 ntroductio n:P roblems with large p rograms2. The Game of Life (ac ontinuing exa mple3. P rogrammi ng style(aNames(bDocume ntati on and format(cRe ?n eme nt and modularity4. Codi ng, test ing, and further re?n eme nt(aStubs(binput and Output(cDrivers(dP rogra

2、m Testi ng5. Refere ncesP roblems of Large P rograms1. The p atchwork app roach2. Problem sp eci?cati on3. P rogram orga ni zati on4. Data orga ni zati on and data structures5. Algorithm selecti on and an alysis6. Debuggi ng7. Testi ng8. MaintenanceRules for the Game of Life1. The n eighbors of a gi

3、ve n cell are the eight cells that touch it vertically, horiz on tally, or diag on ally. Every cell is either livi ng or dead.2. A liv ing cell stays alive in the n ext gen erati on if it has either 2or 3liv ing n eighbors; it dies if it has 0,1,4, or more liv ing n eighbors.3. A dead cell becomes a

4、live in the n ext gen erati on if it has ex-actly three n eighbori ng cells, no more or fewer, that are al-ready alive. All other dead cells remain dead in the n ext gen-erati on.4. All births and deaths take pl ace at exactly the same time, so that a dying cell can help to give birth to ano ther, b

5、ut cannot p reve nt the death of others by reduc ing overcrowd ing, nor can cells being born either p reserve or kill cells liv ing in the p revious gen erati on.IdlJ(i(kD1 * - lL1U J D«:-1 T,(IAlgorithm for the Life GameIn itialize an array called map to contain the in itial con? gurati on of

6、liv ing cells.Rep eat the follow ing ste ps for as long as desired:For each cell in the array do the followi ng:Count the nu mber of liv ing n eighbors of the cell.If the count is 0,1,4, 5, 6, 7, or 8, the n set the corres ponding cell in ano ther array called n ewma p to be dead; if the count is 3,

7、 the n set the corres ponding cell to be alive;and if the count is 2, the n set the corres ponding cell to be the same as the cell in array map (sin cethe status of a cell with count 2does not cha nge.Copy the array n ewma p into the array map .Print the array map for the user.Guideli nes for Choos

8、ing Names1. Give sp ecial care to the choice of n ames for functions, con-sta nts, and all global variables and types used in differe nt p arts of the p rogram.2. Keep the n ames simple for variables used only brie?y and locally.3. Use com mon p re?xes or suf?xes to associate n ames of the same gen

9、eral category.4. Avoid deliberate miss pell ings and mea nin gless suf?xes to obta in differe nt n ames.5. Avoid choos ing cute n ames whose meaning has little or no th-i ng to do with the p roblem.6. Avoid Choos ing n ames that are close to each other in sp elli ng or otherwise easy tocon fuse.7. B

10、e careful in the use of the letter“I ” (smallell,“ O ” (capital oh andP rogrammi ng Prece ptAlways n ame your variables and fun cti onswith the greatest care, and exp lai n them thoroughly.Docume ntati on Guideli nes1. PI ace a pro logue at the beg inning of each fun cti on with(aidenti?cation (prog

11、rammer' s name, date, version.(bStateme nt of the purp ose of the function and method used.(cCha nges the fun cti on makes and what data it uses.(dRefere nee to further docume ntati on for the p rogram. 2. Whe n each variable, con sta nt, or type is declared, explain what it is and how it is use

12、d.3. In troduce each sig ni ?ca nt part of the p rogram with a statene nt of purp ose.4. I ndicate thee nd of each sig ni ?ca nt sect ion.5. Avoid comme nts that p arrot what the code does or that are meanin gless jarg on.6. Exp lai n any stateme nt that employs a trick or whose mea ning is un clear

13、. Better still, avoid such stateme nts.7. The code itself should explain how the p rogram works. The docume ntati on should explain why it works and what it does. 8. Be sure to modify the docume ntati on along with the p rogram.P rogrammi ng Prece ptKeep your docume ntatio n con cise but descri ptiv

14、e.P rogrammi ng Prece ptThe readi ng time for p rograms is much more tha n the writi ng time. Make read ing easy to do.Re?n eme nt and Modularity Top-dow n desig n and re?n eme nt:P rogrammi ng Prece ptDon t lose sight of the forest for its trees. Divisi on of work among fun cti ons:P rogrammi ng Pr

15、ece ptEach function should do only one task, but do it well. P rogram ming P rece ptEach fun ctio n should hide someth ing. P rogrammi ng Prece ptIn clude p recise precon diti ons and p ostc on diti ons with every fun cti on that you write.Categories of Data Used inFunctionsInputp arametersOut putp

16、arametersIn outp arametersLocalvariablesGlobal variablesP rogrammi ng Prece ptKee p your conn ecti ons sim pie. Avoid global variables whe never po ssible.P rogrammi ng Prece ptNever cause side effects if you can avoid it.If you must use global variables, docume nt them thoroughly. P rogrammi ng Pre

17、ce ptKeep your input and out put as sep arate functions.so they can be cha nged easilyand can be custom-tailored to your computing system.-JMAX ROWMAXROW + 1.MAXCOL乙 MAXCOL + 12 .2r ii/iijjN': -r r 勺 j nlL'irk cy i.Debugg ing and Test ing Methods for debuggi ng: 1. Structured walkthrough 2.S

18、nap shots 3. Scaffoldi ng 4. Static an alyzer P rogrammi ng P rece pt The quality of test data is more imp orta nt tha n its qua ntity. P rogrammi ng P rece pt P rogram test ing can be used to show the p rese nee of bugs, but n ever their abse nee. Methods for p rogram testi ng: 1. The black-box met

19、hod: (a Easy values (b Typi cal, realistic values (c Extreme values (d Illegal values 2. The glass-box method: Trace all the p aths through the p rogram. 3. The tick ing- box method: Don ' t do anythingjst hpe for the best! Debugging and Testing Transp.11, Sect. 1.4, Codi ng, Testi ng, and Furth

20、er Ren eme nt 239 1997 Pren tice-Hall, I nc. UpperSaddle River, N.J. 07458 Data Structures and P rogram Desig n In C, 2nd. ed.Executi on P aths switch a case 1: x = 3; break; case 2: if (b = 0 x = 2; else x = 3; x =4; break; case 3: while (c > 0 p rocess (c; break; a = 1 a = 2 b = 0 b != 0 a = 3

21、x = 2; x = 4; while (c > 0 p rocess (c; a = 1 a = 2 b = 0 a = 2 b != 0 a = 3 x = 3; x = 2; x =4; while (c > 0 process (c; P ath 1 P ath 2 Path 3 Path 4 Executio n P aths Transp. 12, Sect.1.4, Codi ng. Test ing, and Further Ren eme nt 240 1997 Pren tice-Hall, I nc. Upper SaddleRiver, N.J. 07458

22、 Data Structures and P rogram Desig n In C, 2nd. ed.R Pentomino Cheshire Cat Virus Tumbler Barber P ole Harvester The Glider GunLife con gurati ons Transp. 13, Sect. 1.4, Codi ng, Test ing, and Further Ren eme nt 241 1997Pren tice-Hall, I nc., Upper Saddle River, N.J. 07458 Data Structures and P rog

23、ram Desig nIn C, 2nd. ed.Poin ters and Pitfalls 1. Un dersta nd your p roblem before you decide how to solve it.2. Un dersta nd the algorithmic method before you start to p rogram. 3. Divide the p roblem into p ieces and thi nk of each part sep arately. 4. Keep your fun cti ons short and simp le. 5.In clude careful docume ntati on with each fun cti on. 6. Write dow n p recise precon diti ons

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论