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

Design a class called Numbers that can be used to translate whole dollar amounts

ID: 649849 • Letter: D

Question

Design a class called Numbers that can be used to translate whole dollar amounts in the range 0 through 9999 into an English description of the number. For example, the number 713 would be translated into the string seven hundred thirteen, and 8203 would be translated into eight thousand two hundred three. The class should have a single integer member variable int number; and public member functions: const static string lessThan20[ ]; const static string tens[ ]; const static string hundred; const static string thousand; The class should have a constructor that accepts a nonnegative integer and uses it to initialize the Numbers object. It should have a member function print() that prints the English description of the Numbers object. void print(); Numbers(int x){ number = x; } Static string members will specify how to translate key dollar amounts into the desired format (Static member variables must be defined outside of the class). For example, you might use static strings such as const string Numbers::lessThan20[ ]= {"zero", "one", ..., "eighteen", "nineteen" }; const string Numbers::tens[ ] = { "zero", "ten", "twenty",

Explanation / Answer

Answer

please rate - thanks

#include <iostream>
using namespace std;
class Numbers
{public:
int number;
Numbers(int);
void print( );
void printword(string);
void getthree( long div,string upto20[],string tens[],string group);
};
int main()
{int n;

cout<<"enter a number: ";
cin>>n;
while(n<0||n>9999)
   {cout<<"Please enter positive numbers which are no more than 4 digits in length ";
    cout<<"enter a number: ";
    cin>>n;
    }
   Numbers num(n);
   num.print();
cout<<endl;
system("pause");
return 0;
}
Numbers::Numbers(int n)
{number=n;
}
void Numbers::printword(string w)
{long i;
    cout<<w;
cout<<" ";
}
void Numbers:: print()
{long n,t;
string upto20[20]={"zero","one","two","three","four","five","six","seven",
                   "eight","nine","tenth","eleven","twelve","thirteen",
                     "fourteen","fifteenth","sixteen","seventeen",
                     "eighteen","nineteen"};

string tens[10]={"zero","ten","twenty","thirty","forty","fifty","sixty",
                 "seventy", "eighty", "ninety"};
getthree(100000,upto20,tens,"thousand ");
n=number/100;
if(n>0)
     {printword(upto20[n]);
   cout<<"hundred ";
   }
number%=100;
if(number>=20)
    {n=number/10;          
        if(n>0)
           printword(tens[n]);      

     }
else if(number>=10)
    { printword(upto20[number]);
     return;
     }
number%=10;
if(number>0)
     printword(upto20[number]);


}
void Numbers::getthree(long div,string upto20[],string tens[],string group)
{long n;
n=number/div;
    if(n>0)
      {printword(upto20[n]);
      cout<<"hundred ";
      }
number%=div;
n=number/(div/10);
    if(n>0)
      printword(tens[n]);
number%=(div/10);
n=number/(div/100);
    if(n>0)
      {printword(upto20[n]);
      cout<<group;
      }
number%=(div/100);
}

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