Question
The program makes use of strings, arrays, and classes. Problem specifications are as shown below with my changes marked in blue. 12. Check Writer Write
The program makes use of strings, arrays, and classes. Problem specifications are as shown below with my changes marked in blue. 12. Check Writer Write a program that displays a simulated paycheck. Create a class named TextVersionOfNumber. The UML for the class is as follows: TextVersionOfNumber Class E Fields amount:double Methods string getTextVersionOfNumber setAmount(double) : void It holds a private variable named amount which has a mutator method. It contains a function named getTextVersionOfNumber that returns the text version of the number as a string. It does not print out anything! In int main Create an instance of the TextVersionOfNumber variable. Use the mutator function to provide it with numbers and display the string returned by the getTextVersionOfNumber function. Sample output is as follows The program should ask the user to enter the date, the payees name, and the amount of the check. It should then display a simulated check with the dollar amount spelled out, as shown here: Date: 12/24/2016 Pay to the Order of: John Phillips $1920.85 One thousand nine hundred twenty and 85 cents 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 no fractional part. Use either C-strings or string class objects in this program. The getTextVersionOfNumber function converts the class private variable amount's content into a text value. This function contains the arrays shown below: string one_19[] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}; string twenty_90[] = {"","","twenty","thirty","forty", "fifty", "sixty", "seventy", "eighty", "ninety"}; The value store in amount is split up into numeric values that hold the individual digits in the amount field. These are used as subscripts across the above arrays. Refer to the Programming Standards document and follow the rules stated there in order to complete the program. I will not accept a program with 20-30 "if" statements instead of array processing! Decisions structures will need to be used to implement this logic; however using 20-30 "if" statements is not acceptable! This assignment should be implemented in 3 files, which are: TextVersionOfNumber.h TextVersionOfNumber.cpp your_initials_assignment8_tester.cpp Do not print in the TextVersionOfNumber class's convertNumberToText function. Return a string that is printed out in int main() maya_tolappa_assignment6_tester.cpp Here is the file I used to test the assignment class. Download it from BlackBoard or click this link. Rename it your_initials_assignment6_tester.cpp and use it. It does not contain statements to obtain user input. Instead, values from an array are used to simulate user input. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 // Maya Tolappa. 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 #include #include 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, 12.45, 19, 19.02, 19.45, 20, 20.65, 34, 56.78, 100.21, 109.05, 119.78, 450, 678.90, 1000, 1011, 1011.11,1009.45, 1056, 1234.15, 1567.98,9999, 9999.99}; cout << setprecision(2) << fixed; for(auto an_amount : testAmounts) { checkAmount.setAmount(an_amount); cout << setw(60) << right; cout << "Date: " << date << endl; cout << "Pay to the order of: " << payee << "\t\t\t"; cout << "$" << an_amount << endl; cout << checkAmount.getTextVersionOfNumber() << endl; cout << "-------------------------------------------- "; } return 0; } Instead of asking the user to enter name and date, I assigned values to the variables. In the loop in lines 25-36, the elements in the double array defined in 17-21 provide the number that needs to be converted into text. Rounding up a double value to an int and converting it to a string Using ostringstream to convert double/float to a string after rounding I used ostringstream to format cents into a string and avoid 1-cent-off errors! It is used as shown below. This is not complete code, but gives you an idea of how to convert a double/float into a string with rounding up instead of truncation occurring.: x5NBYnMdwHj0imGIlCEv493QPXVPC9JrtkvU99PM Using to-string to convert double/float to a string after rounding The value to be rounded, cents, is multiplied by 100. After that, 0.5 is added to it and then truncated. The to_string function can be used to convert an int to a string value. image?w=624&h=315&rev=1&ac=1 Using cmath include to convert double/float to a string after rounding xkZxEBXYd-ejWg83H_Sr1JhdKeIWiXsxRit8zYw6 The round function from cmath rounds up a number to the closest int. Output from my version of the assignment Date: 03/05/2016 Date: 03/05/2016 Date: 03/05/2016 Pay to the order of: Maya Tolappa $0.00 zero dollars and 0 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $0.01 zero dollars and 1 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $0.25 zero dollars and 25 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $12.12 twelve dollars and 12 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $12.45 twelve dollars and 45 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $19.00 nineteen dollars and 0 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $19.02 nineteen dollars and 2 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $19.45 nineteen dollars and 45 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $20.00 twenty dollars and 0 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $20.65 twenty dollars and 65 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $34.00 thirty four dollars and 0 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $56.78 fifty six dollars and 78 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $100.21 one hundred dollars and 21 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $109.05 one hundred nine dollars and 5 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $119.78 one hundred nineteen dollars and 78 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $450.00 four hundred fifty dollars and 0 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $678.90 six hundred seventy eight dollars and 90 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $1000.00 one thousand dollars and 0 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $1011.00 one thousand eleven dollars and 0 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $1011.11 one thousand eleven dollars and 11 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $1009.45 one thousand nine dollars and 45 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $1056.00 one thousand fifty six dollars and 0 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $1234.15 one thousand two hundred thirty four dollars and 15 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $1567.98 one thousand five hundred sixty seven dollars and 98 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $9999.00 nine thousand nine hundred ninety nine dollars and 0 cents --------------------------------------------------------------------- Date: 03/05/2016 Pay to the order of: Maya Tolappa $9999.99 nine thousand nine hundred ninety nine dollars and 99 cents --------------------------------------------------------------------- Press any key to continue . . . Show transcribed image text
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started