Question

Extra 11 - Pay to the Order Of.. (Due 5/29) A check writer.program. Write a program that displays a simulated check. The prog

write it in a c++ language

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>
#include <cctype>
#include <iomanip>
using namespace std;

string convertToTwoDigitToWords(int, string);
string numberToWords(unsigned long long int);

const string EMPTY = "";
const string digits[] = {
        EMPTY, "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten ", "Eleven ", "Twelve ",
        "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen "
};

const string tens[] = {
        EMPTY, EMPTY, "Twenty-", "Thirty-", "Forty-", "Fifty-", "Sixty-", "Seventy-", "Eighty-", "Ninety-"
};

string convertToTwoDigitToWords(int num, string suffix)
{
    if(num == 0)
        return EMPTY;
    if(num > 19)
    {
        return tens[num / 10] + digits[num % 10] + suffix;
    }
    else
        return digits[num] + suffix;
}

string numberToWords(unsigned long long int num)
{
    string words = "";

    words = convertToTwoDigitToWords((num % 100), "");

    if(num > 100 && num % 100)
    {
        words = words;
    }

    words = convertToTwoDigitToWords(((num / 100) % 10), "Hundred ") + words;

    words = convertToTwoDigitToWords(((num / 1000) % 100), "Thousand ") + words;

    words = convertToTwoDigitToWords(((num / 100000) % 100), "Lac, ") + words;

    words = convertToTwoDigitToWords(((num / 10000000) % 100), "Million, ") + words;

    words = convertToTwoDigitToWords(((num / 1000000000) % 100), "Billion, ") + words;

    return words;
}

int main()
{
    string date, name;
    string amount;

    int dollar, cents;

    cout << "Enter date: ";
    cin >> date;
    cin.ignore();
    cout << "Enter payee's name: ";
    getline(cin, name);
    cout << "Enter the amount: $";
    cin >> amount;

    int posOfDot = amount.find(".");
    dollar = stoi(amount.substr(0, amount.find_first_of(".")));
    cents = stoi(amount.substr(posOfDot + 1));

    string dollarInWords = numberToWords(dollar);
    string centsInWords = numberToWords(cents);

    double amt = stod(amount);
    cout << setprecision(2) << fixed;

    // printing the cheque
    cout << endl << "*****************************************************************************" << endl;
    cout << "                                             Date: " << date << endl << endl << endl;
    cout << "Pay to the order of: " << name << "                       $" << amt << endl << endl;
    cout << dollarInWords << "dollars and " << centsInWords << "cents" << endl;
    cout << endl << "*****************************************************************************" << endl;
    return 0;
}

************************************************************************ SCREENSHOT ***************************************************

531790 Enter date: Enter payees name: d Tzmp -Enter the amount: $ 2567.97 Date: 05/31/2016 Pay to the order of: Donald Trump

Add a comment
Know the answer?
Add Answer to:
write it in a c++ language Extra 11 - Pay to the Order Of.. (Due 5/29) A check writer.program. Write a program that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this is for c++ please and thank you! 19. Check Writer Write a program that displays...

    this is for c++ please and thank you! 19. Check Writer Write a program that displays a simulated paycheck. The program should ask the user to enter the date, the payee's name, and the amount of the check (up to $10,000). It should then display a simulated check with the dollar amount spelled out, as shown here: Date: 11/24/2014 Pay to the Order of: John Phillips $1920.85 One thousand nine hundred twenty and 85 cents Be sure to format the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT