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. 【打印使用此程序的指令】
NAMES:
Always name your classes ,variables and functions with the greatest care,and explain them thoroughly.
为了使程序完善的运行,并且能够确切的知道每个类和变量代表什么以及每个函数做什么,在命名的时候就更应该慎重,以明确的、简洁的识别他们的意义。
DOCUMENTATION & FORMAT:
Keep your documentation concise but descriptive.
为了使其他人能够理解这一编程,并且自己在编写大型程序时,容易产生记忆混杂,对于一些细节不太清晰。
一个具有描述性并且简洁明了的文档,可以让更多人加深与对此程序的理解,并且便于自己对程序的记忆与讲解。
1.Stubs:
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.
2.Definition of the class Life:
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.
3.Counting Neighbors:
The function that counts neighbors of the cell with coordinates row, col requires that we look in the eight adjoining cells.
4.Sentinel:
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.
5.Updating the grid:
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.
6.Input & output:
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.
Instructions()
A simple exercise in use of the put to operator<<and the standard output stream called cout.
Initialization
The Life method initialize() must accomplish is to set up an initial configuration.
7.Divers
辅助函数,用来测试调用
8.程序跟踪
发现潜在的缺陷的最有效方法。
9.Principles of program testing
程序测试原理
用来说明bug的存在而无法证明bug的不存在。