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

write a c++ program which converts dollar amounts from numeric form, such as pro

ID: 3684465 • Letter: W

Question

write a c++ program which converts dollar amounts from numeric form, such as proper for writing a check. I'd prefer an explanation rather than an answer if possible thanks. write a c++ program which converts dollar amounts from numeric form, such as proper for writing a check. I'd prefer an explanation rather than an answer if possible thanks. write a c++ program which converts dollar amounts from numeric form, such as proper for writing a check. I'd prefer an explanation rather than an answer if possible thanks.

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;

class Amount {
private:
int amount;
static string one[];
static string ty[];
static string teen[];
static string hundred[];
static string thousand[];

public:
Amount();
Amount(int num){setNum(num);};
void setNum(int num){amount = num;};
void print();
};

string Amount::one[] = {"one ", "two ", "three ", "four ", "five ", "six ","seven ", "eight ", "nine "} ;

string Amount:teen[] = {"ten ","eleven ", "twelve " ,"thirteen ","fourteen ","fifteen ","sixteen ", "seventeen ","eighteen ","nineteen "};

string Amount::ty[] = {"twenty ","thirty ","forty ","fifty ","sixty ","seventy ","eighty ","ninety "};

string Amount::hundred[] = {"one hundred ","two hundred ","three hundred ","four hundred ","five hundred ", "six hundred ","seven hundred ","eight hundred ","nine hundred "};

string Amount::thousand[] = {"one thousand ","two thousand ","three thousand ","four thousand ","five thousand ", "six thousand ","seven thousand ","eight thousand ","nine thousand "};

void Amount::print() {
if (amount < 0)
{amount = -amount;}

if (amount == 0)
{cout << "zero ";}

if (amount >= 1000) {
cout << thousand[amount/1000];
amount %= 1000;
}

if (amount >= 100) {
cout << hundred[amount/100];
amount%= 100;
}

if (amount>= 20) {
cout << ty[(amount/10)-1];
amount %= 10;
}

if (amount >= 10 && amount <= 19)
{cout << teen[(amount%10)+1];}

if (amount > 0)
{cout << one[amount];}

cout << "dollars";
}

int main() {
cout<<” enter the amount in numeric dollars”;

int amount;

cin >> amount;

while (amount >= 0) {
Amount p(amount);
p.print();
cout << " please enter another amount: ";
cin >> amount;
}
return 0;
}