1. 首页
  2. 文档大全

数据结构与程序设计C描述Kruse着高等教育出版社课后答案

上传者:键*** 2022-07-10 19:57:57上传 DOCX文件 833KB
数据结构与程序设计C描述Kruse着高等教育出版社课后答案_第1页 数据结构与程序设计C描述Kruse着高等教育出版社课后答案_第2页 数据结构与程序设计C描述Kruse着高等教育出版社课后答案_第3页

《数据结构与程序设计C描述Kruse着高等教育出版社课后答案》由会员分享,可在线阅读,更多相关《数据结构与程序设计C描述Kruse着高等教育出版社课后答案(800页珍藏版)》请在文档大全上搜索。

1、ProgrammingPrinciples 11.2 THE GAME OF LIFEExercises 1.2Determine by hand calculation what will happen to each of the configurations shown in Figure 1.1 overthe course of five generations. Suggestion: Set up the Life configuration on a checkerboard. Use onecolor of checkers for living cells in the c

2、urrent generation and a second color to mark those that will beborn or die in the next generation.Answer(a)Figure remains stable.(b)(c)(d)Figure is stable.12 Chapter 1 _ Programming Principles(e)(f)Figure repeats itself.(g)(h)(i)Figure repeats itself.(j)(k)(l)Figure repeats itself.Section 1.3 _ Prog

3、ramming Style 31.3 PROGRAMMING STYLEExercises 1.3E1. What classes would you define in implementing the following projects? What methods would your classespossess?(a) A program to store telephone numbers.Answer The program could use classes called Phone_book and Person. The methods for a Phone_bookob

4、ject would include look_up_name, add_person, remove_person. The methods for a Personobject would include Look_up_number. Additional methods to initialize and print objects ofboth classes would also be useful.(b) A program to play Monopoly.Answer The program could use classes called Game_board, Prope

5、rty, Bank, Player, and Dice. In additionto initialization and printing methods for all classes, the following methods would be useful. Theclass Game_board needs methods next_card and operate_jail. The class Property needs methodschange_owner, look_up_owner, rent, build, mortgage, and unmortgage. The

6、 class Bank needsmethods pay and collect. The class Player needs methods roll_dice, move_location, buy_propertyand 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 initializationand prin

7、ting methods. The class Game_board would also need methods make_move andis_game_over. The class Square would need methods is_occupied, occupied_by, and occupy.(d) A program to model the build up of queues of cars waiting at a busy intersection with a traffic light.Answer The program could use classe

8、s Car, Traffic_light, and Queue. The classes would all need initializationand printing methods. The class Traffic_light would need additional methods change_statusand status. The class Queue would need additional methods add_car and remove_car.E2. Rewrite the following class definition, which is sup

9、posed to model a deck of playing cards, so that itconforms to our principles of style.class a / a deck of cardsint X; thing Y152; /* X is the location of the top card in the deck. Y1 lists the cards. */ public:a( );void Shuffle( ); / Shuffle randomly arranges the cards.thing d( ); / deals the top ca

10、rd off the deck;Answerclass Card_deck Card deck52;int top_card;public:Card_deck( );void Shuffle( );Card deal( );4 Chapter 1 _ Programming PrinciplesE3. Given the declarationsint ann, i, j;where n is a constant, determine what the following statement does, and rewrite the statement to accomplishthe s

11、ame effect in a less tricky way.for (i = 0; i < n; i.)for (j = 0; j < n; j.)aij = (i . 1)/(j . 1) * (j . 1)/(i . 1);Answer This statement initializes the array a with all 0s except for 1s down the main diagonal. A lesstricky way to accomplish this initialization is:for (i = 0; i < n; i.)for


文档来源:https://www.renrendoc.com/paper/212695742.html

文档标签:

下载地址