CS 1401, Final Exam

Date: Thursday, May 11, 2006
Name (please type legibly, ideally in block letters): ______________________________________________________________________
Each problem is worth (approximately) the same number of points. Extra credit for a problem will be given only if the problem itself is solved correctly. If you use extra sheets of paper, place your name on each sheet.

On this day, May 11, 1997, a chess-playing computer Deep Blue defeated Garry Kasparov, the world chess champion.

1. Describe the contribution of computing pioneers Charles Babbage and Ada Lovelace to the field of computing. For extra credit: Describe one more event from the history of computing, and how this event affected the field of computing.

2. In a chess championship, a win brings 1 point, a tie brings 0.5 points, and a loss brings 0 points. Write a method that takes, as input, the numbers of wins, ties, and losses, and returns the total number of points earned by the player. Trace this method on the example when a player had 4 wins, 3 ties, and 5 losses; your method should return 4 * 1 + 3 * 0.5 + 5 * 0 = 5.5 points. Hints: For extra credit: describe a GUI design for reading the number of wins, ties, and losses; design an algorithm and/or write a code.

3. (related to Problem 2) Define a class Player in which each object has three private fields: numberOfWins, numberOfTies, and numberOfLosses. Your code for defining the class should contain:

4. After the defeat, Deep Blue became the world's chess champion. It was therefore necessary to change the wording of the chess federation webpage. Write a piece of code that, given a string chessChampion that contains the last name Kasparov exactly once, replaces this name with Deep Blue.

5. (related to Problem 4). Write a method that swaps the values of two globally defined string variables champion and secondPlace. Trace your method on the example when originally the contents of the string variable champion is "Kasparov", and the contents of the string variable secondPlace is "Deep Blue". As a result of the swap, the first string variable will now have the value "Deep Blue", and the second will have the value "Kasparov".

6. In one of chess tournaments, it is possible to gain up to 6 points. If you gain 6 points, you are the champion. If you earn 4 or 5 points, you automatically become a chess master. If you earn 2 or 3 points, your status does not change. If you earn 0 or 1 points, you are disqualified from future tournaments of this level. Assume that the number of points is stored in an integer variable points. Write a piece of code that, based on the value of this variable, produces the corresponding message. Do not forget to include an error message if the value is above 6 or below 0. Write two versions of this code: What are the relative advantages and disadvantages of using if and switch For extra credit: what are the relative advantages and disadvantages of using ?: operators?

7. The list of chess players who participated in a tournament is contained in a file: Write a piece of code that asks the user for the file name, and then places the players' names from the corresponding file into an array names, and the corresponding number of points into the array points, so that: The total number of players should be placed into a variable players. Use try-catch to catch the situation when there is no file with this name, and produce the corresponding error message.

8. Write a method that takes, as the input, the array points and the number players described in Problem 7, and returns the average number of points earned by players. Assuming that the number of players in a tournament can be from 1 to 8, what are the reasonable test cases for this method? Give specific examples of the corresponding test data.

9. Use the algorithms that we learned in class to translate 5 and 11 into binary, add and multiply these numbers in binary, and translate the results back into decimal (to check the correctness of the result). Suppose that a computer has only one decimal significant digit, and it uses round-off; if you ask this computer to add 5.0 and 11.0, what will be the result?

10. People who hack into computers claim that they are doing a useful job for the community by discovering the defects of the existing computer security systems. Is it ethical? Explain your answer. Give two other examples of unethical computer-related behavior (more for extra credit); for each example, explain how people justify their behavior and why it is harmful to these people and/or to others.