Fall 2012 Final Exam, TR 12-1:20 pm class section, December 11, 2012

*Background:* On this day, in 1972, exactly forty years ago,
astronauts from Apollo-17 mission landed on the moon. This was the
last lunar landing.

1. Apollo-17 spaceship used primitive computers, in which only integer arithmetic operations were hardware supported. To test a computer, astronauts:

- asked the computer to calculate the value of a simple arithmetic expression,
- calculated the value of this expression by hand, and
- compared the results.

2. Each Apollo mission considered several possible landing sites. For each site, scientists estimated how interesting this site will be, while engineers estimated how difficult it will be to land in this site. The Mission Control then selected a site for which the difference between the interest score and the difficulty score is the largest. Write a method that, given two numbers, returns their difference.

3-5. Let us first consider the case when there are three possible landing sites.

- The first site
has scores
*interest1*and*complexity1*. - The second site
has scores
*interest2*and*complexity2*. - The third site
has scores
*interest3*and*complexity3*.

- Write a piece of code that uses these values and if-then statements to compute the number (1, 2, or 3) of the best site -- i.e., of the site which has the largest value of the difference.
- One possible way to describe the conditions of the
corresponding if-then statements is to use and-operation &&. Draw
the truth table that describes the values of A && B for all four
possible combinations of truth values of A and B.
*For extra credit:*draw similar tables for "or" and "not". - Describe combinations of values that you can use to test
your code. Explain why you selected these values; what is the general
principle of testing a code that contains if-then statements?
*For extra credit:*describe other rules of testing; explain the difference between black-box and white-box testing.

6. We may have more than three possible landing sites. In this case, it is reasonable to store the scores of different sites in two arrays:

- the
*i*-th element*interest[i]*of the array*interest*is the interest score of the*i*-th site; - the
*i*-th element*complexity[i]*of the array*complexity*is the complexity score of the*i*-th site.

- site 0 with interest score 5 and complexity score 3, and
- site 1 with interest score 4 and complexity score 1.

7. To compute the speed of the spaceship, the program divided the distance

8-9. As the Apollo-13 flight has shown, spaceflights are risky. To help astronauts, Mission Control prepared a manual describing what to do if each components of the spaceship is malfunctioning. The instructions are placed in an array

- Write a method for linear search, and
trace, step-by-step, how your method will search for the index of
*parachute*in the array consisting of three components*engine*,*parachute*, and*radio*. - Trace, on the example of an extended array
consisting of six components
*engine*,*food*,*light*,*parachute*,*radio*, and*toilet*, how the following binary search method will look for*parachute*.

public static int binarySearch(String[] nam, String comp){ boolean found = false; int lower = 0; int upper = a.length - 1; int mid = 0; while(!found && lower <= upper){ mid = (lower + upper) / 2; if(nam[mid].equals(comp)){ found = true; } else if (nam[mid].compareTo(comp) < 0}{ lower = mid + 1; } else{ upper = mid - 1; } } if(found){ return mid; else{ return -1; } }Here,

10. Design a class

11. Let us design a dialog program to help astronauts report possible spaceflight problems. This program should:

- ask an astronaut whether there are still some problems to report, by asking him or her to type Yes or No;
- if there are more problems to report, the program should ask for the description of the next problem and record it.

- the description of the first problem should be stored in the element
*problems[0]*; - the description of the second problem should be stored in the element
*problems[1]*; - etc.

12. Describe the contribution of Ada Lovelace to computing.

13. Instead of buying software (like Windows) or music, some students copy this software or music from their friends.

- Provide two arguments
why this practice is not ethical; explain how such copying affects
the authors of this software (music).
*For extra credit:*provide additional arguments. - Provide two arguments that students
use to explain their copying.
*For extra credit:*provide additional arguments.