Question: C++ Design a class Numbers that can be used to translate whole dollar amounts in the range 0 through 9999 into an English description of
C++
Design a class 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 a static array of string objects that specify how to translate key dollar amounts into the desired format. For example, you might use static strings such as
string lessThan20[] = {"zero", "one", ..., "eighteen", "nineteen"}; string bet20To100[] = {"", "", "twenty", "thirty",...,"eighty","ninety"}; string hundred = "hundred"; string thousand = "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. Demonstrate the class by writing a main program that asks the user to enter a number in the proper range and then prints out its English description.
The error message should read Error! Number is outside valid range. DO NOT USE A LOOP A successful message should read English description: nine thousand nine hundred ninety nine
#ifndef NUMBERS_H
#define NUMBERS_H
#include
#include
using namespace std;
class Numbers
{
int number;
public:
static string lessThan20[ ];
static string bet20To100[ ];
static string hundred;
static string thousand;
Numbers(int);
void print();
};
#endif
-------------------------
#include
#include
#include "Numbers.h"
using namespace std;
int main()
{
int Num;
// Ask the user to enter a number in the range 0 through 9999;
cout << "This program displays the English description of a number. "
<< "Enter a number in the range 0 through 9999: ";
cin >> Num;
Numbers Obj(Num);
Obj.print();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
