软件工程-编码实现.ppt

  1. 1、本文档共20页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
软件工程-编码实现

编码实现 编码风格 编码语言的选择 编码风格 编码风格 使用标准的控制结构 有限制的使用GOTO语句 实现源程序的文档化 满足运行工程学的输入输出风格 使用标准的控制结构 单入口、单出口标准结构 if c then s; If c then s1 else s2; Case I of a: s1; b: s2; … n: sn; endcase While c do s; for i:=m to n do s; Repeat s until c; 有限制的使用GOTO-1 用GOTO 语句实现提前退出循环; While c1 do begin … if c2 then goto 20; … if c3 then goto 30; … end; 20: … Goto 40; 30: … 40: exit1:=false; exit2:=false; While(c1) and (not exit1) and (not exit2) do Begin … if c2 then exit1:=true; … if c3 then exit2:=true; … End If(exit1) then goto 20; If(exit2) then goto 30; 20:… Goto 40; 30:…. 40: 有限制的使用GOTO-2 GOTO 语句用于出错处理 boolean push(item,index,stack,errflag) { int errflag,index; float item,stack[100]; if(index=100) goto 10; errflag=0; index=index+1; stack[index]=item; return(errflag); 10: errflag=1; return(errflag); } 有限制的使用GOTO-3 使用GOTO语句减少重复程序段。 if p then a;b; else b; endif while q loop a;b; endloop if p then L1: a; … endif b; If q then goto l1; 实现源程序的文档化 有意义的变量名 适当的注释 标准的书写格式 名字 名字-非形式的、简练的、容易记忆的。 一个变量的作用于越大,名字所携带的信息越多。 全局变量-使用具有说明性的名字;并加以注释。 局部变量-用短名字; Npending=0;//current length of input quene 全局变量采用大写开头的变量名。 如:Globle 常量用大写字母拼写。 如:CONSTANTS 变量的类型也应体现: 如:strTo,strFrom 字符串 名字 保持一致性 class UserQueue{ int noOfItemsInQ,frontOfTheQueue, queueCapacity; public: int noOfUserInQueue(){…} } (1)同一个词queue分别用了 Q、Queue、queue (2) 在类型UserQueue访问 queue.queueCapacity多余 可改为: class UserQueue{ int nitems, front, capacity; public: int nusers(){…} } queue.capacity++; n=queue.nusers(); 名字 函数采用动作性的动词,后面可以跟着名词。 now=date.getTime(); putchar(‘/n’); 表达式和语句 用缩行显示程序的结构 for(n=0;n100;field[n++]=‘\0’); *i=‘\0’; return(’\n’); 改为: for(n=0;n100;n++) field[n]=‘\0’; *i=‘\0’; return(’\n’); 表达式和语句 使用表达式的自然形式。 避免含有否定运算的条件表达式。 可以改变关系运算方向,变成肯定的。 如 if(!block_idacblks)||!(block_id=unblocks)) 改为 if((block_id=actblks)||(block_idunblocks)

文档评论(0)

wyjy + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档