Branching

Lab Assignment

The assignment contains two parts.
  1. Mini Sort Study Debugging in Eclipse. Create a project titled Lab2_MiniSort. Cut and paste this example program into your project. The program attempts to sort three integer numbers in the increasing order. However, it is incomplete. For example, it does not work for this input 3 2 1 . Debug the program. Demonstrate to the lab instructor tracing of the program.

    Hint: to correct the program you need to add another swapping of values between variables one and two.

    Submit the corrected program to the subversion repository.

  2. Number Spell Create a project Lab2_NumberSpell. Write a program that inputs a two-digit natural number (from 10 to 99) and outputs this number spelled out in English. That is, for 23 it outputs twenty three. You are not allowed to use the concepts, such as looping or functions that we have not studied. Writing a program that treats all 90 cases separately (that is, has 90 separate output statements) will result in a bad grade.

    Hint: input the numbers as two variables of type char, then create output using several switch and if statements. Specifically, you will need to differentiate (with an if) a number that is less than 20. For such numbers you will need a switch statement to print the whole value. For the numbers larger than 20, you will need one switch to print the word for the first digit, and another -- for the word of the second digit.

    That is, the outline of your program could be as follows:

    if(first character is equal to '1')
       switch that recognizes the second character (second digit) and prints the whole number "ten", "eleven", or ...
    else
       switch that recognizes the first digit and prints "twenty" or "thirty", or .   ..
       then
       switch that recognizes the second digit and prints "one" or "two", or ...
    

    Make sure you program adheres to proper programming style. Submit your project to the subversion repository.

Do not forget to verify your submission on the web.