Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Question: Given Tester file: // Chapter 12-- Assignment 14: Check Writer //

ID: 3695745 • Letter: C

Question

C++ Question:

Given Tester file:

// 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 << "--------------------------------------------------------------------- ";
   }
   cin.get();
   return 0;
}

Given h file:

#include<iostream>
#include<string>
#include <iomanip>
using namespace std;
class TextVersionOfNumber
{
private:
   double amount;

public:
   string getTextVersionOfNumber();
   void setAmount(double);
};

I need to return the numbers as a string using array processing with decision structures.

This is what I have so far...

#include "TextVersionOfNumber.h"
string TextVersionOfNumber::getTextVersionOfNumber()
{
  
   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" };

  

}
void TextVersionOfNumber::setAmount(double _amount)
{
   amount = _amount;

}

Help please!

Explanation / Answer


string TextVersionOfNumber::getTextVersionOfNumber()
{
  
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" };
  
double amt1 = (int)amount;
double amt2 = (amount - amt1)*100;
  
string s1 = "";
  
if(amt1<=19){
s1 = one_19[(int)amt1];
}else{
int tens = amt1/10;
int - (tens*10);
s1 = twenty_90[tens] + one_19[ones];
}
  
string s2 = "";
  
if(amt2<=19){
s2 = one_19[(int)amt1];
}else{
int tens = amt1/10;
int - (tens*10);
s2 = twenty_90[tens] + one_19[ones];
}
  
string s = s1+"."+s2;
return s;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote