Branching

Lab Assignment

The assignment contains two parts.
  1. Order. Study tracing a program. Create a project Lab2_Order. Modify the mini sort of the previous lab to sort the numbers in both decreasing and increasing order depending on user input.

    You are not allowed to use the concepts, such as looping or functions, that we have not studied.

    Hint: the easiest way to code program is to incorporate || (logical-or) operation in the expression of the branching statements.

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

    if the order is increasing AND x is greater than y OR the order is decreasing AND x is less than y then
      swap x and y
    
    if the order is increasing AND y is greater than z OR the order is decreasing AND y is less than z then
      swap y and z
    
    if the order is increasing AND x is greater than y OR the oreder is decreasign AND x is less than y then
      swap x and y again
    
  2. Spell Days. Create a project Lab2_Japril. Japril is a calendar month with 35 days. Write a program that inputs the number of days in Japril, two-digit natural number (from 1 to 35), and outputs this number spelled out in English. That is, for 23 it outputs twenty three. For 6, it should output six.

    You may assume that the user never inputs a number less than 1 or greater than 35.

    You are not allowed to use the concepts, such as looping or functions, that we have not studied. Writing a program that treats all 35 cases separately (that is, has 35 separate output statements) will result in a bad grade.

    Hint: Use integer division to extract singles and tens out of the input number of days. See this program for an example. Then use switch and if statements. Specifically, you will need to differentiate (with an if) the number days that is less than 20. For such numbers you will need a switch statement to print the whole value. For the number of days larger than 20, you will need one switch to print the word for the first digit, and another -- the word for the second digit.

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

    if(number of tens is equal to 1)
       switch that differentiates singles and prints  "ten", "eleven", or ...
    else
       switch or if that differentiates tens and prints "twenty" or "thirty"
           note that this switch should ignore the case (print nothing) if 
           the number of tens is zero
       after that
       switch that differentiates singles and prints "one" or "two", or ...
           note that this switch should also ignore the case of zero 
    
    The number manipulation is very similar to this switch example we studied in class.

Milestone: implement part 1 (Order) of the assignment.

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.