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

(Visual Studio 2008) write a c++ program that has a class called Numbers that ca

ID: 3625301 • Letter: #

Question

(Visual Studio 2008) write a c++ program that has a class called Numbers that can be used to translate whole dollar amounts in the range of 0 through 9999 into English description of the number. For example, the number 713 would be translated  into string seven hundred thirteen, and 8203 would be translated into eight thousand two hundred three. The class should have a single integer member variable number and a collection of string members that specify how to translate key dollar amounts into the desired format.For example

string lessThan20[] = {"zero", "one", ..., "eighteen", "nineteen"};

string hundred = "hundred";

string thousand = "thousand";

 The class should have a constructor that accepts a nonnegative integer and uses it to intialize the Numbers object. Demonstrate the class by writing a main program that asks to enter a number in the proper range and then prints its English description. 

Explanation / Answer

#include <iostream>

#include <string>

#include<math.h>

using namespace std;

class Numbers

{

private:

int numbers;

public:

Numbers(int x)

{

numbers = x;

}

void Display();

};

void Numbers::Display()

{

string abovetwenty[20]={"zero","one","two","three","four","five","six","seven", "eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen", "eighteen","nineteen"};

string lessThan20[10]={"zero","ten","twenty","thirty","forty","fifty","sixty", "seventy", "eighty", "ninety"};

numbers=abs(numbers);

int s=numbers/1000;

if(s>0)

cout<<" "<<abovetwenty[s]<<" thousand ";

numbers%=1000;

s=numbers/100;

if(s>0)

cout<<abovetwenty[s]<<" hundred ";

numbers%=100;

if(numbers>=20)

{

s=numbers/10;

if(s>0)

cout<<lessThan20[s]<<" ";

}

else if(numbers>=10)

{

cout<< abovetwenty[numbers]<<" ";

return;

}

numbers%=10;

if(numbers>0)

cout<<abovetwenty[numbers];

cout<<" ";

}

int main()

{

int num;

cout<<"Enter number: ";

cin>>num;

while(num!=0)

{

Numbers number(num);

number.Display();

cout<<" Enter number:";

cin>>num;

}

system("pause");

return 0;

}