Programming Principles(程序原理)

class Life;

"initialize()" to initialize a Life configuration;【初始化Life配置】

"print()" to output a Life configuration;【输出Life配置】

"update()" to change a Life object,in order to store the configuration at the next generation;【修改Life对象,使它存贮下一代配置】

"user_says_yes()" to ask the user whether or not to go on the next generation;【询问用户是否继续进行下一代】

"instruction()" to print instructions for using the program. 【打印使用此程序的指令】

Precept:

NAMES:           Always name your classes ,variables and functions with the greatest care,and explain them thoroughly.

名称的使用应谨慎,在命名时可选择与所编辑程序相关名称,方便记忆且不容易弄混,而且命名时尽量少用容易混淆的字母和数字,例如:“1”&“l”,“o”&“0”。

DOCUMENTATION & FORMAT:           Keep your documentation concise but descriptive.

文档不仅是对于其他人的一种解释,在大型软件编程时,文档同样是对自己的一种记忆储备,因此,文档需要简练且明确。

设计程序员身份,还有此程序目的说明,函数所修改和使用的数据,对程序外部文档的引用,都应写在序言处,方便其他人阅读,或是自己记忆。

STUBS:

1.To compile the main program correctly ,there must be something in the place of each function that is used, and hence we must put in short ,dummy functions,called stubs.

DEFINITION OF THE CLASS LIFE:

2.Each Life object needs to include a rectangular array, which we shall call grid ,to store a Life configuration. We use an integer entry of 1 in the array grid to denote a living cell,and 0 to denote a dead cell.

  Hence ,the class Life should include a member function neighbor_count that does this task.

COUNTING NEIGHBORS:

3.The function that counts neighbors of the cell with coordinates row, col requires that we look in the eight adjoining cells.

SENTINEL:

4.Another term often used instead of hedge is sentinel:A sentinel is an extra entry put into a data structure so that boundary conditions need not be treated as a special case.

UPDATING THE GRID:

5.We first use the data stored in the configuration to calculate entries of a rectangular array called new_grid that records the updated configuration.We then copy new_grid,entry by entry,back to the grid member of our Life object.

INPUT & OUTPUT:

6.It now remains only to write the Life methods initialize() and print(), with the functions user_says_yes() and instructions() that do the input and output for our program.

[1].Instructions()

  A  simple exercise in use of the put to operator<<and the standard output stream called cout.

[2].Initialization

  The Life method initialize() must accomplish is to set up an initial configuration.

DIVERS【驱动器】

调试和测试单个函数的一种方法是写一个较短的辅助程序来为此函数提供必要的输入、调用此函数并评价函数执行的结果,这样的辅助函数称为函数的驱动器。

PROGRAM TRACING【程序跟踪】

PRINCIPLES OF PROGRAM TSETING【程序测试原理】

程序测试用于说明bug的存在。



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值