next up previous
Next: About this document ... Up: $FILE Previous: Unix Commands

Calculator Programming

Go to the CS101 home page.

  1. Download the fib and log programs (follow the lectures link to find these files) and save as local files.
  2. Open the calculator applet (click on the resources link, to find the calculator applet). Run the applet (see handout given on day 1 for tips in case you have problems). Open and run each of the above programs.
  3. Edit the programs to change the input values, and reload and rerun the programs. Check that the correct value is produced for for each input.

    Testing the program with different input values is an important part of programming. Make sure you test with ``special cases'', such as with input value 0, and in the case of the log program, with powers of 10. Try fib with a large number (say 40) and see what happens - use the execute up to line number option to avoid stepping one line at a time.

Now write any one or more of the following programs; do as many as time permits, but it is enough if you do one or two. The programs will not count towards your grade, but you must submit whatever you have done via moodle and you will get feedback. Submit even if the program does not work (note that it doesn't work). If you have more than one program to submit just put them all in one file (one after the other) and submit the file.

You will not have time in the lab to finish all problems, but after the lab you can try writing programs for the other problems on paper. Note that $^{*}$ indicates easy, $^{**}$ is medium and $^{***}$ is hard, and it is enough for this course if you are able to do the easy problems.

  1. $^*$Given a polynomial $f(x,y) = 4x^3 + 9xy + 3y^2$, and values for $x$ and $y$, compute $f(x,y)$.
  2. $^*$Given n, add up all powers of 2 from 1 to $2^n$.
  3. $^*$Given number $n$ find value of $n!$
  4. $^{**}$Given numbers $m$ and $n$, compute $m$ modulo $n$. Note that CAL does not have a modulo (remainder) operator.
  5. $^{**}$Given a number $n$ decide the number of bits required to represent this number in binary. For example, with input = 7, the binary form (111) requires 3 bits.
  6. $^{***}$Given a decimal number between 0 and 63, print out its (unsigned) binary representation. Since CAL does not support binary really, you will print out the corresponding decimal number made up of 1s and 0s, eg given 2, you will display 10, given 63 you will display 11111.

    Make sure to add comments explaining how your program works.

  7. $^{***}$Given a decimal number of up to 5 digits consisting only zeros and ones. Then, assuming it as unsigned binary convert it to equivalent decimal number. For example, suppose the input is 1011 (decimal, as CAL accepts only decimal numbers). Assuming it as binary equivalent, you would have to output the decimal number 11.

    Make sure to add comments explaining how your program works.

$^{*}$Easy $^{**}$Medium $^{***}$Hard


next up previous
Next: About this document ... Up: $FILE Previous: Unix Commands
cs101 Lab 2007-08-06