// Chapter 12-- Assignment 14: Check Writer
// This program can convert a dollar and cents amount given in
// numerical form to a word description of the amount.
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
using namespace std;
class text
{
const int SIZE;
private:
double amount;
string amount_string;
public:
string convertNumberToText();
void setAmount(double);
};
// Assume a maximum amount of $10,000
This is as far as i got and do not know where to start. I need to put this into 3 separate files: an .h file and 2 cpp files as the main is a cpp tester file. If anyone can help me asap i would really be appreciated!!
Thanks Aleonard for the tip. I am working with visual basic 2012 to code my programs. I figured out how to separate them into the 3 programs. I just don't know what to put in under the public classes to make my conversions.
Is there a difference between a stringstream compared to a ostreamstring? My prof. recommends us using the ostreamstring but didn't teach us the concept.
I'm not sure about the details but basically, an ostringstream is a stringstream specialized for output stuff, while an istringstream is a stringstream for input stuff.
I'm sure it's not important at this level. It would be a good question for your teacher to ask him the real difference between istringstream, ostringstream and stringstream. One more time, the answer is in the doc :)
//And then my test file which consist of the main function. //Tester.cpp:
// Chapter 12-- Assignment 14: Check Writer
// This program can convert a dollar and cents amount given in
// numerical form to a word description of the amount.
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <sstream>
using namespace std;
#include "TextVersionOfNumber.h"
// Assume a maximum amount of $10,000
Hi, you wrote:
Im looking for output:
One hundred and twenty three and 45 cents.
And I must say, this is not what I understood at first ! This is a bit less straightforward...
Forget about stringstream then ... sorry for that. what you should do is the following:
extract the decimal and integer parts of your number. For decimal, you multiply by 100 and then %100 should give you the cents.
(123.45 * 100) % 100 = 45 (if I'm not wrong)
To get the integer part, simply do a type cast to int:
(int)123.45 = 123;
So for the cents part, you're done. For the integer part, you must create a table of strings for "one", "two", "three", ... "nine", "ten", "elevene", nineteen". Another one for "tweenty", "thirty", "fourty", ... "ninety".
Then you extract the units usin modulo 10 operation:
123 % 10 = 3, and you call unitArray[3] = "three"
Then you extract the next digit:
(123/10) % 10 = 2, and you call decadeArray[2] = "tweenty"
Last number:
(123/100)%10 = 1 and you call unitArray[1] = "one" + "hundred"
Do you see what I mean ? You'll have to make a lot of checks if statements...
i'm doing the same program, the part i don't get is how to put the decision together.
should i use a for look to search through the array and pick what subscript is should choose to match the number