Question: C++ and its one question split into 5 parts And the skeleton program is #include Wordnum.h #include #include #include using namespace std; string join (string*


C++ and its one question split into 5 parts
And the skeleton program is
#include "Wordnum.h" #include
using namespace std; string join (string* first, string* last, char separator) { ostringstream output; if (first 0) *first++ = token; } return first; } ostream& operator > (istream& is, Wordnum& n) { string text; if (is >> text) { n.value_ = Wordnum::read_number(text); } return is; } string units[] = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; string Wordnum::write_number (int n) { return units[n % 10]; } int Wordnum::read_number (string n) { for (int i = 0; i For this assignment, numbers should be written as English words separated by underscore characters, with the default wording following the US conventions (because they are simpler to program). Thus 1001 is written "one thousand one" and 123000009 is "one_ hundred twenty three_million_ nine". If British format is in effect (from level 6), tens and units are separated by a hyphen and preceded by the word "and". For example in British format 123 would be written one hundred and twenty-three Because of the way numbers are written as words in English, you'll probably find it easiest if you break a number up into groups of 3 digits, called triads, and deal with each triad separately. For example, 12345678 is best though of as 12 million 345 thousand 678. Because the code for converting a triad to and from words is the same for each triad number like this: group, you can convert a multi work out how many millions (m) , thousands (t) and units (u) write triad for m followed by "million" write triad for t followed by "thousand" write triad for u and to input a num ber you would reverse the process: try to read a triad followed by "million" and set m to the result try to read a triad followed by "thousand" and set t to the result try to read a triad and set u to the result the number is m* 1000000 + t 1000+ u To input or output a triad, the simplest strategy is to use arrays of strings for the various words, with the array indexes carefully arranged to correspond to the numeric values of the words. Then you can convert a number to words by indexing the arrays with the appropriate value, and you can convert words to a number by looping though the arrays looking for a match. Of course, you'll need to deal with the case where the hundreds, tens, or units digits in the triad are zero. Rather than trying to read input and write output directly, you'll probably find it easier to convert numbers to and from an array of strings, with each element in the array representing one word. Then the extract and insert operators can simply read and write the string arrays. For example, the insert operator would output each word separated by an underscore, and the input operator would tokenise the input using the underscore as a delimiter, storing the tokens into successive array elements. For this assignment, numbers should be written as English words separated by underscore characters, with the default wording following the US conventions (because they are simpler to program). Thus 1001 is written "one thousand one" and 123000009 is "one_ hundred twenty three_million_ nine". If British format is in effect (from level 6), tens and units are separated by a hyphen and preceded by the word "and". For example in British format 123 would be written one hundred and twenty-three Because of the way numbers are written as words in English, you'll probably find it easiest if you break a number up into groups of 3 digits, called triads, and deal with each triad separately. For example, 12345678 is best though of as 12 million 345 thousand 678. Because the code for converting a triad to and from words is the same for each triad number like this: group, you can convert a multi work out how many millions (m) , thousands (t) and units (u) write triad for m followed by "million" write triad for t followed by "thousand" write triad for u and to input a num ber you would reverse the process: try to read a triad followed by "million" and set m to the result try to read a triad followed by "thousand" and set t to the result try to read a triad and set u to the result the number is m* 1000000 + t 1000+ u To input or output a triad, the simplest strategy is to use arrays of strings for the various words, with the array indexes carefully arranged to correspond to the numeric values of the words. Then you can convert a number to words by indexing the arrays with the appropriate value, and you can convert words to a number by looping though the arrays looking for a match. Of course, you'll need to deal with the case where the hundreds, tens, or units digits in the triad are zero. Rather than trying to read input and write output directly, you'll probably find it easier to convert numbers to and from an array of strings, with each element in the array representing one word. Then the extract and insert operators can simply read and write the string arrays. For example, the insert operator would output each word separated by an underscore, and the input operator would tokenise the input using the underscore as a delimiter, storing the tokens into successive array elements
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
