The University of Queensland Homepage
School of ITEE ITEE Main Website

 COMP2304 Assignment 1

Overview

This assignment must be submitted electronically during week four of semester, by 5pm Friday 19 August, 2005.

You must write a C++ program that translates numbers spelt out in their English written form to integer, eg.

Input Output
ONE THOUSAND ONE HUNDRED AND FORTY-TWO 1142

Specifications

  1. Your program must be a C++ Win32 Console project that compiles under MSVC.NET 2003 on the laboratory machines (which will be the testing environment). For this assignment, your source code should be completely contained in a single C++ file (a .cpp file); adding this file to an empty Win32 Console project should be sufficient for the project to compile and run your submission without additional project configuration.

  2. For each line of input from cin you must write one line of output to cout, unless the line of input is empty. If the line of input is empty, your program must exit without error. Similarly, if the end of the input stream is reached, your program should exit without error.

  3. Additionally, before reading any input from cin your program should write to cout the following text, where 00000000 would be replaced by your student number in your own program:

    STUDENT ID 00000000
  4. Each valid line of input shall be entirely in upper case, and will be a number spelt out in its entirety. For each valid line of input your program must write the integer form of this number on a line by itself to cout. The number described will be a while number no less than 0 (ZERO) and no larger than the maximum value of a 32-bit unsigned integer (4294967295 or "FOUR BILLION TWO HUNDRED AND NINETY-FOUR MILLION NINE HUNDRED AND SIXTY-SEVEN THOUSAND TWO HUNDRED AND NINETY-FIVE").

  5. Your program should keep interpreting lines of input until it reads an empty line, or the end of the input stream, and when it reaches either of these cases it should exit. Otherwise, you should print out one line of output for each line of input.

  6. Valid input may contain hyphens at appropriate places (such as "NINETY-NINE" or "TWENTY-ONE") but the input will contain no other punctuation. Expect no commas in the input and produce none in the output. Your program may but need not be tolerant of extra whitespace.

  7. The word "AND" will appear in valid input in cases such as "ONE HUNDRED AND FIVE", and "TEN MILLION ONE HUNDRED AND FIVE THOUSAND AND SEVENTY".

  8. A line of input that cannot be interpretted according to these requirements must still produce one line of output, ideally of no more than about twenty (20) characters, but this output need not be meaningful. Your program should never crash as a result of trying to produce output for a line of input as this would prevent it from attempting to interpret further lines of input.

  9. Some example inputs that must produce valid numbers are as follows

    InputOutput
    ONE HUNDRED AND FOUR 104
    ELEVEN 11
    NINE THOUSAND AND FIFTEEN 9015
    THREE HUNDRED MILLION AND ONE 300000001
    FIFTEEN MILLION ONE HUNDRED AND ELEVEN THOUSAND 15111000

A series of programs to assist you is bundled here. No source code will be available for these executables during this assignment. This archive contains:

A1_Demo.exe

A compiled solution to Assignment 1 that meets all of the specifications.

A1_Gen.exe

A program to generate sample lines of input to test your solution with. It will repeatedly accept numeric input and spell the number out to the console, until it reaches non-numeric input or the end of the input stream.

A1_List.exe

A program to make lists of input for A1_Gen.exe. Use from the command line as

A1_List.exe 1-10 2-4 7

to list the numbers 1 through to 10, 2 through to 4 and a 7.

BOM.txt

A bill of materials for the contents of the Assignment_1_binaries.zip archive.

Assessment

The assignment will be awarded a mark out of 20:

  • (1 mark) Your program must print the first STUDENT ID XXXXXXXX line with your student ID at the beginning of execution.
  • (1 mark) Your program should print out one line of output per line of input read, in addition to the STUDENT ID line, and exit upon reading an end of file or empty line.
  • (3 marks) Your program correctly interprets the numbers 0-19 inclusive.
  • (4 marks) Your program correctly interprets the numbers 20-99 inclusive.
  • (3 marks) Your program correctly interprets the numbers 100-999 inclusive.
  • (2 marks) Your program correctly interprets the numbers 1000-1121 inclusive.
  • (3 marks) Your program correctly interprets one thousand random numbers from 1121 to the upper limit 4294967295 inclusive.
  • (3 marks) Your program correctly interprets one hundred "tricky" numbers, that might probe a poorly written program.

To receive marks for a section interpretting numbers, all numbers in that section, must be correctly interpretted. For example, being unable to parse ZERO would cost all of the marks in the 0-19 section.

The source code of your submission must not contain #include "stdafx.h".

The source code of your submission must be contained in a single .cpp file.

It is recommended that you test your assignment well before submitting. A preliminary demonstration of the automatic assessment program exists on the web site to assess all sections but the "tricky numbers" section. Please post any queries regarding this to the newsgroup. Be certain to read the Notes.html file included in the archive.

This assignment must be submitted electronically during week four of semester, by 5pm Friday 19 August, 2005. You may submit your assignment at the ITEE electronic submission page.


Amendments

  1. [2005.08.02.2307] Corrected sample input from 15111000000 to 15111000.

  2. [2005.08.02.2322] Added specification notes concerning compilation.

  3. [2005.08.03.1312] Updated demo and testbed binaries to correctly reject ONE THOUSAND AND ZERO and overly large inputs.

  4. [2005.08.15.1532] Added expanded assessment section and demo automated assessor binaries.

  5. [2005.08.15.1717] Small update to the Notes.html in the Assessor_binaries.zip bundle.

  6. [2005.08.16.1115] Assessor.exe no longer denies all later marks for invalid STUDENT ID lines, so long as your first line looks like it was an attempt at printing a student ID.

  7. [2005.08.16.1500] Assessor.exe no longer crashes when you don't pass it a student number.

  8. [2005.08.16.1621] Assessor.exe really no longer crashes when you don't pass it a student number. And this time I built and uploaded the right project.

  9. [2005.08.18.1522] Assessor.exe no longer gives you marks when you don't deserve it (for aborting output early).

  10. [2005.08.18.1638] The demo and testbed binaries no longer accept silly numbers, such as ONE THOUSAND TWO THOUSAND.

  11. [2005.08.19.1153] The previous fix to the demo and testbed binaries broke some inputs; this has been fixed.