Due: 12:00 Noon Thu Oct 17
You are to create files, as directed below, and then submit them electronically on host lectura.cs.arizona.edu using the command
Please follow the directions below carefully: submissions that don't follow directions will be penalized heavily.
Note: As before, your programs should compile with no errors or warnings when compiled with gcc -Wall. Moreover, each program should exit with a status of 0 if execution proceeds normally, and a status of -1 if any sort of error occurs.
In addition, from now on your programs will be expected to follow the coding guidelines for this class.
012345the expected output is
twelve thousand three hundred and forty five
Write a program, in a file number.c, that behaves as follows. The program sits in a loop repeatedly reading in strings of digits from stdin, until end-of-file is encountered. For each string that is read in the program prints out the value of that string in words. The details of this are as follows:
Input:Each string that is read in may be assumed to be a sequence of decimal digits that is at most 99 characters long, i.e., represents a non-negative integer with value between 0 and 10100-1.Output:Note that these numbers may not fit into a variable of type int: a 32-bit value cannot accommodate values larger than about 109.
The output generated by your program should consist of a sequence of words, giving the value of a number read in and satisfying the following requirements:Additional Files:
- The value of a number should be printed using lower-case letters only, and should all be on one line. Each pair of adjacent words should be separated by a single space. There should be no additional punctuation, e.g., in the form of commas or periods, either within or at the end of the word sequence.
- The value of a number should be given in terms of values of 3-digit groups (except possibly for the highest group, which may have fewer than 3 digits), followed by a name corresponding to the position of that number (thousand, million, billion, etc.). We will use American names for this assignment. (The 3-digit grouping means, for example, that the number 4213 should be described as four thousand two hundred and thirteen, and not fortytwo hundred and thirteen.)
- The description of a 3-digit group XYZ should have the structure ``X hundred and Yty Z'' (but see the minimality requirement below). For example, the number 324 should be described as three hundred and twenty four.
- The values of 3-digit groups should be given in left-to-right order, i.e., in descending order of their positional value. Thus, the number 123 should be described as one hundred and twenty three, and not twenty three and one hundred or twenty and one hundred and three. The number 123456 should be described as one hundred and twenty three thousand four hundred and fifty six, and not four hundred and fifty six and one hundred and twenty three thousand.
- The description of a number should be minimal, i.e., should not contain anything unnecessary. In particular, this implies that:
- Leading zeros should be ignored. For example, the number 00011 should be described as eleven, and not zero thousand zero hundred and eleven.
- Zero fields within a number should be ignored. For example, the number 1000100 should be described as one million one hundred and not one million zero hundred thousand one hundred.
The directory /home/cs352/FALL02/hw5_stuff contains the following files to assist you in this assignment:
- NUMBERS
- This is a text file that contains the (American) names for numbers of the form 103n, one per line, starting from n = 1 (103 = thousand) to n = 33 (1099 = duotrigintillion). You can read this file in using the myIOlib library from Assignment 4. Information about how to communicate information about include files and libraries to a C compiler is available here.
- number
- This is an executable file for lectura that implements the behavior expected of your program.