CS 1401, Quiz #1

Date: Thursday, January 20, 2005
Name: ______________________________________________________________________
Last 4 digits of UTEP ID #:(it is OK if you do not remember it): ______________________________________________________________________

1. Explain why the invention of variables was a good idea. (Hint: how were formulas described before that?) When were they invented? By whom?


Answer: 

Variables were invented by Francois Viete (a.k.a. Francisco Vieta) in
1520. Variables enable to make descriptions of algorithms much shorter 
and easier to understand, e.g., "to compute the area of the rectangle,
multiply its first side by its second side" is much more difficult to
write and to understand than A=s1*s2.

2. Describe, step by step, an algorithm that, given three real numbers a, b, and c, returns the values x for which a*x+b=c.

Answer:

Let us first move b to the other side of the equation, we get
a*x=c-b. This leads to the following algorithm:

* First check whether a = 0. 

* If a =/= 0, then compute and return the value x = (c-b)/a

* If a = 0, then check whether b = c.
  
  * If b = c, then every real number x is a solution

  * If b =/= c, then the original equation has no solutions. 

3. Explain which of the following five expressions are correct names for Java variables, and if not, why:


viete
  
  It is a correct name, because it is a sequence of characters and/or
  digits starting with a character

1520

  Incorrect: starts with a digit, should start with a letter

francois_viete

  Correct: underscore is allowed

francois-viete
 
  Incorrect: - is not allowed; the only two symbols that are not
  letters or digits that are allowed in a Java name are underscore and $

francois viete 

  Incorrect: blank space is not allowed

4. In Java, strings are described by double quotes. For example, the text Java is described as follows:
"Java"
Describe, in Java, the two strings that contain the following two texts:

Francois Viete 

  "Francois Viete"

At a conference SCAN'04, Viete said: "I invented variables."  

  "At a conference SCAN'04, Viete said: \"I invented variables.\""