CS 1401, Final Exam

Date: Tuesday, December 6, 2005
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.

Tomorrow, December 7, is the International Civil Aviation Day.

1. Describe at least two events from the history of computing, and how these events affected the field of computing.

2. The total weight of a plane is equal to the weight of a plane itself plus the overall weight of the passengers -- computed as the average passenger weight times the number of passengers. Write a method that takes, as input, the weight of the plane itself, the number of passengers, and the average weight of the passengers, and returns the total weight of the plane. Trace this method on the example of a small plane that weighs 200 kg and has 2 passengers of average weight 70 kg. Hints: For extra credit: design a GUI for reading the weight of the plane itself and of the number of passengers; design an algorithm and/or write a code.

3. (related to Problem 2) Define a class Airplane in which each object has three private fields: weightOfPlane, averageWeight, and numberOfPassengers. Your code for defining the class should contain:

4. Dr. Kreinovich was originally planning to fly to a conference in Houston to present his joint paper with Dr. Longpre, but it turns out that he cannot go, so Dr. Longpre will fly instead. It is therefore necessary to change a ticket. Write a piece of code that, given a string ticket that contains the last name Kreinovich exactly once, replaces this name with Longpre.

5. (related to Problem 4). Write a method that swaps the values of two globally defined string variables flies and stays. Trace your method on the example when originally the contents of the string variable flies is "Kreinovich", and the contents of the string variable stays is "Longpre".

6. It is recommended that a passenger who is not checking in luggage arrives at the airport: a passenger who want to check in luggage must arrive at the airport 30 minutes earlier than that. Write a piece of code that, based on the values of Boolean variables domestic and checkingIn, computes how many hours earlier than the flight time the passenger has to arrive at the airport. Write two versions of this code: What are the relative advantages and disadvantages of using if and ?: operators? For extra credit: what are the relative advantages and disadvantages of using switch?

7. The passenger list for a flight is contained in a file: Write a piece of code that asks the user for the file name, and then places the passenger names from the corresponding file into an array names, so that: 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 of passenger weights, and returns the average weight of the passengers. Assume that there are no empty spots in the array. Assuming that a weight can be from 1 kg to 150 kg, and the number of passengers can be from 1 to 10, what are the reasonable test cases for this method? Give specific examples of the corresponding test arrays.

9. Use the algorithms that we learned in class to translate 12 and 7 into binary, add these numbers in binary, and translate the sum 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 12.0 and 7.0, what will be the result?

10. Is it ethical to copy your lab assignments from someone else or from the web and present it as your own? Is it ethical, instead of buying a copyrighted textbook, to download it, for free, from a webpage where it is illegally posted? For each of these two cases, present: