12. Check Writer Please read this entire question as this differs from the book
ID: 3697910 • Letter: 1
Question
12. Check Writer
Please read this entire question as this differs from the book
I DO NOT NEED THE TESTER FILE. THIS IS THE THIRD TIME I'VE HAD TO ASK THIS QUESTION.
Write a program that displays a simulated paycheck. The program should ask the user to enter th date, the payee's name, and the amount of the check. It should then display a simulated check with the dollar amount spelled out. You may assume the amount is no greater than $10000. Be sure to format the numeric value of the check in fixed=point notation with two decimal places of precision. Be sure the decimal place always displays, even when the number is zero or has fractional part.l Use either C-strings or string class objects in this program.
In order to complete this assignment, create a class called TextVersionOfNumber
Be sure to not use a lot of "if" statements; use array processing.
(Here is the tester for the program)
// 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;
#include "TextVersionOfNumber.h"
// Assume a maximum amount of $10,000
int main()
{
string date = "03/05/2016", payee = "Maya Tolappa";
TextVersionOfNumber checkAmount;
double testAmounts [] = {0, .01, .25, 12, 12.45, 19, 19.02,
19.45, 20, 20.45,
34, 56.78, 100, 109, 119.78,
450, 678.90, 1000, 1009.45, 1056,
1234, 1567.98,9999, 9999.99};
for(int i=0; i < sizeof(testAmounts)/sizeof(double); i++)
{
double an_amount = testAmounts[i];
checkAmount.setAmount(an_amount);
cout << setprecision(2) << fixed;
cout << setw(60) << right;
cout << "Date: " << date << endl;
cout << "Pay to the order of: " << payee << " ";
cout << "$" << an_amount << endl;
cout << checkAmount.getTextVersionOfNumber() << endl;
cout << "--------------------------------------------------------------------- ";
}
return 0;
}
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include "TextVersionOfNumber.h"
using namespace std;
string TextVersionOfNumber::convertNumberToText()
{
string array1[] = {"", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve",
"thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
"eighteen", "nineteen"};
string array2[] = {"","","twenty","thirty","forty",
"fifty", "sixty", "seventy", "eighty", "ninety"};
double amount;
int thousand = amount / 1000;
int hundred = amount % 1000 / 100;
int ten = amount % 100 / 10;
int % 10;
int deci = amount - static_cast<int>(amount) * 100;
//takes out the decimal and multiplies by 100
final_string = th_string[thousand] + hu_string[hundred] + te_string[ten] + o_string[one] + to_string(deci) + "cents";
if (thousand >= 1)
amount_string = array1[thousand] + " thousand " + array1[b] + " hundred "
}
void TextVersionOfNumber::setAmount(double DollarAmount)
{
DollarAmount = amount;
}
Hope this program is what you are asking for!!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.