6
HW4 Explanation

HW4 Explanation. Problem 1 You should write maxv() function (Exercise 11 on page 297). Testcase: – Testcase 1: Input : 1 2 3 4 5 -1 Output : maximum value

Embed Size (px)

Citation preview

Page 1: HW4 Explanation. Problem 1 You should write maxv() function (Exercise 11 on page 297). Testcase: – Testcase 1: Input : 1 2 3 4 5 -1 Output : maximum value

HW4 Explanation

Page 2: HW4 Explanation. Problem 1 You should write maxv() function (Exercise 11 on page 297). Testcase: – Testcase 1: Input : 1 2 3 4 5 -1 Output : maximum value

Problem 1

• You should write maxv() function (Exercise 11 on page 297).

• Testcase:– Testcase 1:• Input : 1 2 3 4 5 -1• Output : maximum value was v[4] = 5

– Testcase 2:• Input : 5 1 3 4 2 -1• Output : maximum value was v[0] = 5

Page 3: HW4 Explanation. Problem 1 You should write maxv() function (Exercise 11 on page 297). Testcase: – Testcase 1: Input : 1 2 3 4 5 -1 Output : maximum value

Problem 2

• Test case– Input

1351451451-451-1-1

You can create your own test case using the form in http://www.1728.org/vectors.htm.

Output901.414201.4142

Page 4: HW4 Explanation. Problem 1 You should write maxv() function (Exercise 11 on page 297). Testcase: – Testcase 1: Input : 1 2 3 4 5 -1 Output : maximum value

Problem 3

• Input– 1 2 3 4 5 6 7 8 9

• Output– The matrix is

1 2 34 5 67 8 9Transpose of matrix is1 4 72 5 83 6 9Determinant of matrix is0

Page 5: HW4 Explanation. Problem 1 You should write maxv() function (Exercise 11 on page 297). Testcase: – Testcase 1: Input : 1 2 3 4 5 -1 Output : maximum value

Problem 4

• The first player to get to 50 points wins.• Human player enters R or H to signal whether

to Roll or to Hold. The computer player will always hold after 4 rolls unless its turn ends early due to a 1.

• After each roll, print the current sequence of scores and the current sum. If the player rolls a 1, the program prints "1 rolled, turn is over" and then the current score for both players.

Page 6: HW4 Explanation. Problem 1 You should write maxv() function (Exercise 11 on page 297). Testcase: – Testcase 1: Input : 1 2 3 4 5 -1 Output : maximum value

Problem 4Player Dice output ScoreComputer 2 C=2, P=0Computer 1 C=0, P=0Player , R 4 C=0, P=4Player , R 5 C=0, P=9Player , R 6 C=0, P=15Player , R 3 C=0, P=18Player , H - C=0, P=18Computer 3 C=3, P=18Computer 4 C=7, P=18Computer 2 C=9, P=18Computer 2 C=11, P=18Player, R 2 C=11, P=20Player, R 1 C=11, P=18