- 1、本文档共800页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据结构与程序设计C描述(Kruse着)高等教育课后答案.
Programming
Principles 1
1.2 THE GAME OF LIFE
Exercises 1.2
Determine by hand calculation what will happen to each of the configurations shown in Figure 1.1 over
the course of five generations. [Suggestion: Set up the Life configuration on a checkerboard. Use one
color of checkers for living cells in the current generation and a second color to mark those that will be
born or die in the next generation.]
Answer
(a)
Figure remains stable.
(b)
(c)
(d)
Figure is stable.
1
2 Chapter 1 _ Programming Principles
(e)
(f)
Figure repeats itself.
(g)
(h)
(i)
Figure repeats itself.
(j)
(k)
(l)
Figure repeats itself.
Section 1.3 _ Programming Style 3
1.3 PROGRAMMING STYLE
Exercises 1.3
E1. What classes would you define in implementing the following projects? What methods would your classes
possess?
(a) A program to store telephone numbers.
Answer The program could use classes called Phone_book and Person. The methods for a Phone_book
object would include look_up_name, add_person, remove_person. The methods for a Person
object would include Look_up_number. Additional methods to initialize and print objects of
both classes would also be useful.
(b) A program to play Monopoly.
Answer The program could use classes called Game_board, Property, Bank, Player, and Dice. In addition
to initialization and printing methods for all classes, the following methods would be useful. The
class Game_board needs methods next_card and operate_jail. The class Property needs methods
change_owner, look_up_owner, rent, build, mortgage, and unmortgage. The class Bank needs
methods pay and collect. The class Player needs methods roll_dice, move_location, buy_property
and pay_rent. The class Dice needs a method roll.
(c) A program to play tic-tac-toe.
Answer The program could use classes called Game_board and Square. The classes need initialization
and printing methods. The class Game_board would also need methods make_move and
is_game_over. The class Square would need methods is_occupied, occupied_by, an
文档评论(0)