CS 1401, Final Exam

Date: Tuesday, May 9, 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.

Today, May 9, is the International Teacher Day.

1. Describe how the invention of variables and the invention of logarithms helped in computing. For extra credit: Describe one more event from the history of computing, and how this event affected the field of computing.

2. A teacher teaches two sections of the same class. Write a method that takes, as input, the number of students in each of these sections and the number of credit hours in the class, and returns the total number of credit hours generated by this class. Trace this method on the example when there are 25 students in the first section, 15 in the second section, and the class is worth 3.0 credit hours; your method should return 3.0 * (25 + 15) = 120.0 credit hours. Hints: For extra credit: describe a GUI design for reading the number of students and the number of credit hours; design an algorithm and/or write a code.

3. (related to Problem 2) Define a class Teacher in which each object has three private fields: numberOfStudentsInFirstSection, numberOfStudentsInSecondSection, and numberOfCreditHours. Your code for defining the class should contain:

4. Dr. Romero was originally planning to prepare the final exam, but the plans changed, and Dr. Kreinovich designed it instead. It is therefore necessary to change the wording of the final exam. Write a piece of code that, given a string finalExam that contains the last name Romero exactly once, replaces this name with Kreinovich.

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

6. Students from the earlier (9 am) class section take the final today, on May 9; students from the later (10:30 am) class section take their final on May 11. Let us describe an earlier section by a letter E, and a later section by a letter L, and let us assume that this letter is stored in the variable section. Write a piece of code that, based on the value of this variable, computes the date for the final exam (9 or 11). Do not forget to include an error message if the letter is neither E nor L. 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 class list for a class is contained in a file: Write a piece of code that asks the user for the file name, and then places the student names from the corresponding file into an array names, and the corresponding letters in to the array section, so that: The total number of students should be placed into a variable students. 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 section and the number students described in Problem 7, and returns the total number of students in the earlier section. Assuming that the number of students in a class section can be from 0 to 50, 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 9 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 multiply 5.0 and 9.0, what will be the result?

10. Is it ethical to use a cheat sheet on the exam? 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: