CPTR 124 Fundamentals of Programming


The purpose of this lab is to use if/else statements to allow programs to optionally execute various statements depending on user input.


  1. Forming a Team

    You are encouraged to choose a partner from this class as a teammate. You two will work together on this assignment.

    You are not required to work with someone else; you may work alone if you prefer.

  2. Familiarize yourself with the assignment

    Read over the complete lab before you begin creating your project and C++ source file.

  3. Housekeeping

    You will need to create a separate Visual Studio project for this program.

  4. What to do

    Write a program that accepts a single integer from the user. In response, the program should print a single line consisting of the English text representation of that number.

    Some specifics:

    • The program should be able to handle any integer the user provides. For integers in range –100...100, the program should print the English word that represents the number.

    • If the user enters a value less than –100, the program should print "too small." If the user enters a value greater than 100, the program should print "too big."

    • Your program can print 203 possible messages, but you may not use 203 if statements as shown in the following code fragment:

      //  Code like this is NOT acceptable!
                .
                .
                .
      if (n == 34)
          cout << "thirty-four" << endl;
      else if (n == 35)
          cout << "thirty-five" << endl;
      else if (n == 36) {
          cout << "thirty-six" << endl;
                .
                .
                .
      

      You must use if statements for your conditional checks, but you are limited to 50 or fewer if statements within your code. This means you need to look for common properties that can reduce the number of required if statements. Any value between 71 and 79 would have the prefix "seventy-", for example. A subsequent if statement then would determine the ones digit to follow (via the modulus of 10) and print it separately.

    • Treat the values 10-19 as special cases since their names are irregular. For example, 23 is "twenty-three," but 13 is not "ten-three."

    • There many ways to solve the problem. One approach uses the following logic flow:

      Number to text
     flowchart

    Do not include capital letters in your text result, and do not include any extraneous spaces. Example acceptable results are "negative thirty-five" for -35, and "four" for 4. Here is the definitive list of proper number spellings that we will use for this lab:

    -101 : too small
    -100 : negative one hundred
     -99 : negative ninety-nine
     -98 : negative ninety-eight
     -97 : negative ninety-seven
     -96 : negative ninety-six
     -95 : negative ninety-five
     -94 : negative ninety-four
     -93 : negative ninety-three
     -92 : negative ninety-two
     -91 : negative ninety-one
     -90 : negative ninety
     -89 : negative eighty-nine
     -88 : negative eighty-eight
     -87 : negative eighty-seven
     -86 : negative eighty-six
     -85 : negative eighty-five
     -84 : negative eighty-four
     -83 : negative eighty-three
     -82 : negative eighty-two
     -81 : negative eighty-one
     -80 : negative eighty
     -79 : negative seventy-nine
     -78 : negative seventy-eight
     -77 : negative seventy-seven
     -76 : negative seventy-six
     -75 : negative seventy-five
     -74 : negative seventy-four
     -73 : negative seventy-three
     -72 : negative seventy-two
     -71 : negative seventy-one
     -70 : negative seventy
     -69 : negative sixty-nine
     -68 : negative sixty-eight
     -67 : negative sixty-seven
     -66 : negative sixty-six
     -65 : negative sixty-five
     -64 : negative sixty-four
     -63 : negative sixty-three
     -62 : negative sixty-two
     -61 : negative sixty-one
     -60 : negative sixty
     -59 : negative fifty-nine
     -58 : negative fifty-eight
     -57 : negative fifty-seven
     -56 : negative fifty-six
     -55 : negative fifty-five
     -54 : negative fifty-four
     -53 : negative fifty-three
     -52 : negative fifty-two
     -51 : negative fifty-one
     -50 : negative fifty
     -49 : negative forty-nine
     -48 : negative forty-eight
     -47 : negative forty-seven
     -46 : negative forty-six
     -45 : negative forty-five
     -44 : negative forty-four
     -43 : negative forty-three
     -42 : negative forty-two
     -41 : negative forty-one
     -40 : negative forty
     -39 : negative thirty-nine
     -38 : negative thirty-eight
     -37 : negative thirty-seven
     -36 : negative thirty-six
     -35 : negative thirty-five
     -34 : negative thirty-four
     -33 : negative thirty-three
     -32 : negative thirty-two
     -31 : negative thirty-one
     -30 : negative thirty
     -29 : negative twenty-nine
     -28 : negative twenty-eight
     -27 : negative twenty-seven
     -26 : negative twenty-six
     -25 : negative twenty-five
     -24 : negative twenty-four
     -23 : negative twenty-three
     -22 : negative twenty-two
     -21 : negative twenty-one
     -20 : negative twenty
     -19 : negative nineteen
     -18 : negative eighteen
     -17 : negative seventeen
     -16 : negative sixteen
     -15 : negative fifteen
     -14 : negative fourteen
     -13 : negative thirteen
     -12 : negative twelve
     -11 : negative eleven
     -10 : negative ten
      -9 : negative nine
      -8 : negative eight
      -7 : negative seven
      -6 : negative six
      -5 : negative five
      -4 : negative four
      -3 : negative three
      -2 : negative two
      -1 : negative one
       0 : zero
       1 : one
       2 : two
       3 : three
       4 : four
       5 : five
       6 : six
       7 : seven
       8 : eight
       9 : nine
      10 : ten
      11 : eleven
      12 : twelve
      13 : thirteen
      14 : fourteen
      15 : fifteen
      16 : sixteen
      17 : seventeen
      18 : eighteen
      19 : nineteen
      20 : twenty
      21 : twenty-one
      22 : twenty-two
      23 : twenty-three
      24 : twenty-four
      25 : twenty-five
      26 : twenty-six
      27 : twenty-seven
      28 : twenty-eight
      29 : twenty-nine
      30 : thirty
      31 : thirty-one
      32 : thirty-two
      33 : thirty-three
      34 : thirty-four
      35 : thirty-five
      36 : thirty-six
      37 : thirty-seven
      38 : thirty-eight
      39 : thirty-nine
      40 : forty
      41 : forty-one
      42 : forty-two
      43 : forty-three
      44 : forty-four
      45 : forty-five
      46 : forty-six
      47 : forty-seven
      48 : forty-eight
      49 : forty-nine
      50 : fifty
      51 : fifty-one
      52 : fifty-two
      53 : fifty-three
      54 : fifty-four
      55 : fifty-five
      56 : fifty-six
      57 : fifty-seven
      58 : fifty-eight
      59 : fifty-nine
      60 : sixty
      61 : sixty-one
      62 : sixty-two
      63 : sixty-three
      64 : sixty-four
      65 : sixty-five
      66 : sixty-six
      67 : sixty-seven
      68 : sixty-eight
      69 : sixty-nine
      70 : seventy
      71 : seventy-one
      72 : seventy-two
      73 : seventy-three
      74 : seventy-four
      75 : seventy-five
      76 : seventy-six
      77 : seventy-seven
      78 : seventy-eight
      79 : seventy-nine
      80 : eighty
      81 : eighty-one
      82 : eighty-two
      83 : eighty-three
      84 : eighty-four
      85 : eighty-five
      86 : eighty-six
      87 : eighty-seven
      88 : eighty-eight
      89 : eighty-nine
      90 : ninety
      91 : ninety-one
      92 : ninety-two
      93 : ninety-three
      94 : ninety-four
      95 : ninety-five
      96 : ninety-six
      97 : ninety-seven
      98 : ninety-eight
      99 : ninety-nine
     100 : one hundred
     101 : too big
         

    Notice that no capital letters appear anywhere. Be sure the required spaces and dashes are in their proper places.

  5. Check out

    I will review your lab with you before you leave. Be prepared to answer questions about any parts of your programs. After you have been checked out, please submit your C++ source code (the .cpp files) to eclass.e.southern.edu.

  6. Log out

    Don't forget to log out on your lab workstation and take your USB drive before you leave the lab.