## CS 1401, Quiz 12

Date: Monday, November 27, 2006
Name (please type legibly, ideally in block letters): ______________________________________________________________________

1. Describe how the invention of logarithms helped computing.

```Solution:

Logarithms made computations easier because they enabled to reduce
multiplication to an easier operation - addition. The use of
logarithms in computing is based on the fact that log(a*b) = log(a)
+ log(b). So, to compute a*b, we can do the following:

1) find log(a) and log(b),

2) add these two logarithms, thus computing s = log(a)+ log(b); and

3) find a number whose logarithm is equal to this sum s.

This number will be exactly a*b.
```
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:
• to trace a method, first write a line of code (to be placed in the method main) that calls this method;
• please notice that in the method, we are not asking you to print anything or read anything from the screen or from a file.

```Solution:

public double credit(int students1, int student2, double credits){
return credits * (students1 + students2);}

in the main program:

double numberOfHours = credit(25, 15, 3.0);

tracing:

-----------------
|  -------------  |
| |    25       | |
|  -------------  |
|    students1    |
|                 |
|  -------------  |
| |    15       | |
|  -------------  |
|    students2    |
|                 |
|  -------------  |
| |    3.0      | |
|  -------------  |
|     credits     |
|-----------------|
|                 |
|                 |
|                 |
-----------------
credit

----------------
|    3.0         |
----------------
numberOfCredits

```
3. 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:
• an argument that students give in favor of copying, and
• an argument why, in this case, copying is harmful.

``` Solution:

for cheat sheet: I will lose my stipend if I get a bad grade; I have
to work and support my family, I have no time to study

against cheat sheet: if you do not learn the material, you will have
trouble understanding next classes

for copying: students are poor, taking money from greedy capitalists
in charge of publishing (who exploit poor students) is not stealing,
it is justice

against copying: publishers do not have more profit than others,
otherwise their stock will be in the news; they need to recover
their investment; the more people copy textbooks, the more they have
to charge others - and the higher the prices of the textbooks become
```